**Lecture 35: Code Agent — Production Architecture** **Total Time: 50 minutes** **Spectrum: Code Agent (∞)** **Code: claw-code (github.com/ultraworkers/claw-code)** **Punchline: From 8 tools to 184 — what scales, what breaks, what you need to add.** **[3 min] 0. Housekeeping** - Recap Lec 34: multi-agent (subagent.py), biomedical agent workflows - Today: study how a real production agent (Claude Code) is built **[7 min] 1. WHAT: From nano-claude-code to Claude Code** - nano-cc: 5 files, 8 tools, 1 agent type, ~1,200 lines — you built this - Claude Code: 184 tools, 207 commands, 5 agent types, full runtime — what's different? - The leaked source (Mar 31, 1:23 AM): npm .map file exposed the TypeScript source - claw-code: community reverse-engineered it into Python (66 files, ~2,138 lines, stubs only) **[10 min] 2. WHY: 3 Things That Change at Scale** - **#1 Routing becomes critical** — with 184 tools, the LLM can't see all schemas at once. Need: keyword matching, scoring, deferred tool loading. nano-cc sends all 8; Claude Code routes. - **#2 Context management becomes engineering** — token budget tracking, transcript compaction (summarize old turns), priority-based truncation. nano-cc: unlimited accumulation. Claude Code: query engine manages every token. - **#3 Permissions become a system** — not just safe/unsafe flags. Denied tools, denied prefixes, per-tool permission contexts, bash command analysis. nano-cc: 3 modes. Claude Code: full ToolPermissionContext class. **[15 min] 3. HOW: The Runtime Pipeline (4 stages)** - **(a) Setup**: platform detection, workspace init, prefetch - bootstrap_graph.py → staged startup sequence - **(b) Route**: score prompt against commands + tools by keyword matching - route_prompt(prompt) → ranked list of matching tools/commands - This is why 184 tools work — not all loaded at once - **(c) Execute**: wire up executors, stream events - build_execution_registry() → command/tool executors - stream_submit_message() → message_start → tool_match → permission_denial → message_delta → message_stop - **(d) Persist**: save transcript, manage session state - persist_session() → disk **[10 min] 4. HOW: AgentTool/ — Agents That Spawn Agents (16 files)** - forkSubagent.ts → isolated sub-agent (what we built in subagent.py) - resumeAgent.ts → pause/continue across sessions (nano-cc can't do this) - agentMemory.ts → per-agent persistent memory - spawnMultiAgent.ts → launch N agents in parallel - 5 built-in types: generalPurpose, explore, plan, claudeCodeGuide, verification - **Key delta from L34**: resume, persistent memory, custom agent loading from directory **[5 min] 5. Wrap-Up: nano-cc vs claw-code** | | nano-cc | claw-code | |---|---------|-----------| | Tools | 8 (all loaded) | 184 (routed) | | Context | accumulate | budget + compact | | Permissions | 3 modes | full permission system | | Agents | fork + run | fork + resume + memory | | Value | working agent | architecture map | - **Punchline**: nano-cc teaches you how agents work. claw-code teaches you how agents scale. - **Next Lec 36**: Personal Agent — OpenClaw. Same patterns, completely different domain.