Build your own coding agent from scratch.
A progressive tutorial that demystifies AI coding agents like Claude Code, Cursor Agent, and Codex CLI.
4 versions, ~1000 lines total, each adding one concept:
| Version | Lines | What it adds | Core insight |
|---|---|---|---|
| v0 | ~50 | 1 bash tool | Bash is all you need |
| v1 | ~200 | 4 core tools | Model as Agent |
| v2 | ~300 | Todo tracking | Explicit planning |
| v3 | ~450 | Subagents | Divide and conquer |
pip install anthropic
# Edit any file to set your API key, then:
python v0_bash_agent.py # Minimal
python v1_basic_agent.py # Core agent loop
python v2_todo_agent.py # + Todo planning
python v3_subagent.py # + SubagentsEvery coding agent is just this loop:
while True:
response = model(messages, tools)
if response.stop_reason != "tool_use":
return response.text
results = execute(response.tool_calls)
messages.append(results)That's it. The model calls tools until done. Everything else is refinement.
mini-claude-code/
├── v0_bash_agent.py # ~50 lines: 1 tool, recursive subagents
├── v0_bash_agent_mini.py # ~16 lines: extreme compression
├── v1_basic_agent.py # ~200 lines: 4 tools, core loop
├── v2_todo_agent.py # ~300 lines: + TodoManager
├── v3_subagent.py # ~450 lines: + Task tool, agent registry
└── docs/ # Detailed explanations (EN + ZH)
One tool. Recursive self-calls for subagents. Proves the core is tiny.
4 tools (bash, read, write, edit). The complete agent in one function.
Todo tool makes plans explicit. Constraints enable complex tasks.
Task tool spawns isolated child agents. Context stays clean.
Technical tutorials (docs/):
| English | 中文 |
|---|---|
| v0: Bash is All You Need | v0: Bash 就是一切 |
| v1: Model as Agent | v1: 模型即代理 |
| v2: Structured Planning | v2: 结构化规划 |
| v3: Subagent Mechanism | v3: 子代理机制 |
Original articles (articles/) - Chinese only, social media style:
This is for learning. For production use:
Kode - Full-featured open source Claude Code
The model is 80%. Code is 20%.
Claude Code works not because of clever engineering, but because the model is trained to be an agent. Our job is to give it tools and stay out of the way.
MIT
Model as Agent. That's the whole secret.