Learn · A 12-lesson source-code reading

Learn Claude Code

Not a tutorial — a teardown. From the one-line agent loop to worktree isolation. 12 lessons × 3 interactive widgets, each readable on its own.

12 lessons 36 widgets Based on shareAI-lab/learn-claude-code
S01
Agent Loop
Without loops, there is no agent
Agent loopstop_reasonmessages historytool_result return
S02
Tool Use
The cycle hasn’t changed, it’s just that there are more tools
Tool dispatch mapJSON schemasafe_path anti-escapetool extension
S03
Todo Write
Let the agent manage its own progress
TodoManagerin_progress singleton limitnag reminder injectionstructured state
S04
Subagent
Handle big problems to a newly opened agent
Subagent distributioncontext isolationCHILD_TOOLS CroppingSummary return
S05
Skill Loading
Domain knowledge loaded on demand
Two-tier skill architectureYAML frontmatterload_skill tooltoken economy
S06
Context Compact
The context is full, learn to cut
Micro compactAuto compactManual compact tooltranscript persistence
S07
Task System
State is written to disk, surviving compression
Task CRUDblockedBy dependency graphJSON file persistenceTopology search is executable
S08
Background Tasks
Let the agent run by itself without blocking the agent.
Threaded bg tasknotification queuedrain before LLM callRecharge results
S09
Agent Teams
Multiple agents communicate through file mailboxes
durable teammateJSONL mailbox5 message typesTeam config.json
S10
Team Protocols
Handshake protocol between two agents
shutdown protocolplan_approval agreementrequest_id associationFSM: pending→approved/rejected
S11
Autonomous Agents
Agent who finds work by himself
WORK / IDLE two stagestask board pollingauto_claimidentity re-injection
S12
Worktree Isolation
Different agents should not grab the same tree.
git worktree addtask/worktree bindingkeep vs removeDirectory level isolation