How to code Claude Code in 200 lines of code
TL;DR Highlight
Three tools and a loop make a working file-editing coding agent in about 200 lines of Python
Who Should Read
An LLM API developer who wants to understand how coding agents work internally by building a minimal one
Core Mechanics
- The core is a tool-calling loop
- The LLM requests a tool call and your program runs it locally.
- The result goes back to the LLM, repeating until no tool is requested.
- The LLM never touches your filesystem directly.
- Three tools are enough
- The tools are read_file, list_files and edit_file.
- The author says Claude Code has more, such as grep, bash and websearch.
- Editing uses one old_str/new_str convention
- An empty old_str creates a new file.
- Otherwise the first match of old_str is replaced with new_str.
- If it is not found, it returns "old_str not found".
- Tool descriptions are generated from docstrings
- inspect extracts each function's signature and docstring into the system prompt.
- The LLM uses these to choose tools, so write docstrings in detail.
- Tool calls are plain text lines
- The prompt tells the LLM to reply with exactly one line: 'tool: TOOL_NAME({JSON})'.
- The parser finds lines starting with 'tool:' and extracts name and JSON args.
- Production tools differ mainly in extras
- The author lists error handling and fallbacks, streaming, and smarter context management.
- Running commands, codebase search and approval for destructive operations are also listed.
- The author claims the core loop is the same.
Community Reactions
- Comment: agents need TODOs against early stopping
- One commenter says the article's agent stops before the task is done.
- Claude Code reportedly re-injects open TODOs into every prompt to prevent this.
- They report TODOs performed best in HolmesGPT benchmark experiments.
- Comment: disabling TODO tools hurt results
- A commenter running Claude Code on CTFs found that disabling the TodoList tool and planning dropped results by 1-2 grades.
- Comment: production scale adds much complexity
- A commenter running an in-house agent loop at over a billion tokens a month says many small issues compound.
- Examples: user messages arriving mid-loop, approvals and guardrails, and storing tool outputs.
- Comment: one Bash tool is enough
- A commenter argues a single Bash tool can read, write and search.
- They say specialized tools are only an optimization, and the gh CLI avoids a context-heavy GitHub MCP.
- Comment: prior art and RL-trained tools
- Commenters point out Thorsten Ball's April 2025 'How to Build an Agent' came first and wasn't credited.
- Another says models are RL-trained on specific tools, so custom tools may be at a disadvantage.
How to Apply
- Run a minimal agent yourself
- Paste the prompt below into Claude Code to generate a three-tool agent today.
- Ask it to create hello.py and add a function, then inspect the tool-call logs.
- Rewrite tool docstrings as LLM manuals
- Add one line per argument and the return value to your agent's tool descriptions.
- Check whether wrong tool choices decrease.
- Inject TODOs to prevent early stopping
- Have the LLM create a TODO list at the start of a task.
- Re-attach remaining items to every turn's prompt and make it verify completion.
- Add an approval step before tool execution
- Require a y/n confirmation before destructive tools like edit_file run.
- This is a minimal version of the approval workflow the article lists for production.
Try It
# Paste into Claude Code (the article's method turned into a prompt)
Build a Python coding agent in a single agent.py, under 200 lines, with this spec.
- Use the anthropic SDK, read ANTHROPIC_API_KEY from the environment (.env), model {{model name}}
- Three tools: read_file(filename), list_files(path), edit_file(path, old_str, new_str)
- edit_file: if old_str is empty, create/overwrite the file; otherwise replace the first match; return "old_str not found" if missing
- Each function returns a dict and resolves relative paths to absolute paths
- Generate tool descriptions with inspect from each function's docstring and signature and insert them into the system prompt
- System prompt: to use a tool, reply with exactly one line in the form 'tool: TOOL_NAME({"arg":"value"})'
- Parser: extract name and JSON args from lines starting with 'tool:'
- Loop: outer loop takes user input; inner loop calls the LLM and, while tools are requested, runs them and appends 'tool_result(...)' as a user message
When done, test it with '{{first test request}}'.Terminology
Related Papers
Frostbite: A new CPU architecture discovered, designed and verified by AI
AI agents designed a CPU from scratch, claiming 4.59x perf/W over a traditional core
Restricting AI agents in mobile operating systems platforms from capturing data
Signal now blocks OS-level AI agents from reading its screen on iOS 27 and Android
Actions Speak Louder than Words: Stateful Privacy Sniffing of LLM Agents via Behavioral Covert Channels in Web Interactions
Agents' link choices alone let attackers rebuild user queries at F1 0.89; SOR cuts it to 0.39.
Tracking and Limiting Unsupported Claim Propagation in Multi-Agent LLM Systems: A Provenance-Aware Framework
Passing claims with source, evidence and history kept equivalence at 5 agent stages at 96% versus 31%.
LLM assisted reverse engineering
Pointing an agent at binaries with skills and MD notes made years-long hacks feasible
Metrics-in-the-Loop: Complexity Feedback Reshapes Agent-Written Code
Injecting per-turn complexity reports into coding agents cut code erosion without changing correctness
Why is Gemini 4 Carbon taking so long?
Carbon took nearly an hour on bug fixes that Astra and Opus finished in minutes, mostly from extra unrequested work.
Weight-Space Programming builds neural networks like a 1990s researcher
LLM hand-wrote MNIST weights to 91.3%, using 1990s-style techniques
Related Resources
- https://www.mihaileric.com/The-Emperor-Has-No-Clothes/
- https://ampcode.com/how-to-build-an-agent
- https://fly.io/blog/everyone-write-an-agent/
- https://github.com/SWE-agent/mini-swe-agent
- https://github.com/badlogic/lemmy/tree/main/apps/claude-trace
- https://martinfowler.com/articles/build-own-coding-agent.html
- https://github.com/samsaffron/term-llm
- https://blog.scottlogic.com/2023/05/04/langchain-mini.html
- https://github.com/vinhnx/vtcode
- https://agentskills.io/home