1- # Learn Claude Code -- Build an AI Agent From Scratch
1+ # Learn Claude Code -- A nano Claude Code-like agent, built from 0 to 1
22
33[ English] ( ./README.md ) | [ 中文] ( ./README-zh.md ) | [ 日本語] ( ./README-ja.md )
44
1717 loop back -----------------> messages[]
1818
1919
20- That's it . Every AI coding agent is this loop.
21- Everything else is refinement .
20+ That's the minimal loop . Every AI coding agent needs this loop.
21+ Production agents add policy, permissions, and lifecycle layers .
2222```
2323
24- ** 11 progressive sessions, from a simple loop to full autonomous teams .**
24+ ** 12 progressive sessions, from a simple loop to isolated autonomous execution .**
2525** Each session adds one mechanism. Each mechanism has one motto.**
2626
2727> ** s01**   ; * "Bash is all you need"* &mdash ; one tool + one loop = an agent
2828>
29- > ** s02**   ; * "The loop didn't change"* &mdash ; adding tools means adding handlers, not logic
29+ > ** s02**   ; * "The loop didn't change"* &mdash ; adding tools means adding handlers, not rewriting the loop
3030>
3131> ** s03**   ; * "Plan before you act"* &mdash ; visible plans improve task completion
3232>
4545> ** s10**   ; * "Same request_id, two protocols"* &mdash ; one FSM pattern powers shutdown + plan approval
4646>
4747> ** s11**   ; * "Poll, claim, work, repeat"* &mdash ; no coordinator needed, agents self-organize
48+ >
49+ > ** s12**   ; * "Isolate by directory, coordinate by task ID"* &mdash ; task board + optional worktree lanes
4850
4951---
5052
@@ -77,6 +79,19 @@ def agent_loop(messages):
7779
7880Every session layers one mechanism on top of this loop -- without changing the loop itself.
7981
82+ ## Scope (Important)
83+
84+ This repository is a 0->1 learning project for building a nano Claude Code-like agent.
85+ It intentionally simplifies or omits several production mechanisms:
86+
87+ - Full event/hook buses (for example PreToolUse, SessionStart/End, ConfigChange).
88+ s12 includes only a minimal append-only lifecycle event stream for teaching.
89+ - Rule-based permission governance and trust workflows
90+ - Session lifecycle controls (resume/fork) and advanced worktree lifecycle controls
91+ - Full MCP runtime details (transport/OAuth/resource subscribe/polling)
92+
93+ Treat the team JSONL mailbox protocol in this repo as a teaching implementation, not a claim about any specific production internals.
94+
8095## Quick Start
8196
8297``` sh
@@ -87,6 +102,7 @@ cp .env.example .env # Edit .env with your ANTHROPIC_API_KEY
87102
88103python agents/s01_agent_loop.py # Start here
89104python agents/s11_autonomous_agents.py # Full autonomous team
105+ python agents/s12_worktree_task_isolation.py # Task-aware worktree isolation
90106```
91107
92108### Web Platform
@@ -124,6 +140,9 @@ s08 Background Tasks [6] s10 Team Protocols [12]
124140 |
125141 s11 Autonomous Agents [14]
126142 idle cycle + auto-claim
143+ |
144+ s12 Worktree Isolation [16]
145+ task coordination + optional isolated execution lanes
127146
128147 [N] = number of tools
129148```
@@ -133,7 +152,7 @@ s08 Background Tasks [6] s10 Team Protocols [12]
133152```
134153learn-claude-code/
135154|
136- |-- agents/ # Python reference implementations (s01-s11 + full)
155+ |-- agents/ # Python reference implementations (s01-s12 + full)
137156|-- docs/{en,zh,ja}/ # Mental-model-first documentation (3 languages)
138157|-- web/ # Interactive learning platform (Next.js)
139158|-- skills/ # Skill files for s05
@@ -158,6 +177,7 @@ Available in [English](./docs/en/) | [中文](./docs/zh/) | [日本語](./docs/j
158177| [ s09] ( ./docs/en/s09-agent-teams.md ) | Agent Teams | * Append to send, drain to read* |
159178| [ s10] ( ./docs/en/s10-team-protocols.md ) | Team Protocols | * Same request_id, two protocols* |
160179| [ s11] ( ./docs/en/s11-autonomous-agents.md ) | Autonomous Agents | * Poll, claim, work, repeat* |
180+ | [ s12] ( ./docs/en/s12-worktree-task-isolation.md ) | Worktree + Task Isolation | * Isolate by directory, coordinate by task ID* |
161181
162182## License
163183
0 commit comments