Claude Code Orange Book
A book-length analysis ('Orange Book') dissecting Anthropic's AI engineering decisions from the 510,000 lines / 1,902 TypeScript files that shipped inside an npm package. Chapters cover the agent loop, context compaction, the hook system, and sub-agents - the concepts, not just the code.
View source on GitHubKey takeaways
- 01
Agent loop, compaction, hooks, and sub-agents each get chapter-level treatment
- 02
Frames every mechanism as an engineering decision with trade-offs
- 03
Best source for architecture diagrams' underlying concepts
Flows built on this research
Agent Architecture
Design a Single-Loop Agent
Build the core agent loop the leading coding agents use: one model, one loop, tools in, results folded back into context.
5 steps · 90-150 minutes
Agent Architecture
Sub-Agent Delegation with Context Isolation
Delegate bounded work to sub-agents that run in fresh context and return only distilled results - the pattern behind scalable long tasks.
4 steps · 90-150 minutes
Memory & Context
Implement Context Compaction
Keep long agent sessions alive by compacting old conversation into structured summaries before the context window fills.
4 steps · 90-120 minutes
Agent Architecture
Assemble a System Prompt Like the Pros
Structure your agent's system prompt the way leading harnesses do: layered sections, dynamic context, and enforceable rules.
4 steps · 60-90 minutes
MCP & Tooling
Deferred Tool Loading
Stop paying context for tools the task never needs: load a core set eagerly and expand the toolset on demand.
4 steps · 90-120 minutes
From the archive
Verbatim excerpts mined from our local archive of this repository — the prompts, schemas, and patterns worth stealing.
The Orange Book's framing: decisions over code
This book is not a source code reading journal. It dissects the design decisions behind Claude Code. Why does search use grep instead of a vector database? Why does the memory system only store preferences, not code? Why does Auto mode run a second AI for safety reviews? Why Bun over Node.js? Every choice has a reason. Those reasons are more valuable than the code itself, because they are transferable. Chapters include: The Tool System: 4 Primitives, 59 Tools · The Memory System: Remember Preferences, Forget Code · Search: Why grep Beats RAG · Multi-Agent Architecture: Run Like a Company · The Harness Engineering Playbook.
The chapter titles alone are a design philosophy: grep over RAG, preferences over code in memory, and a second AI as a safety reviewer.
README.md