Back to Vault
Claude Code Internals
Tier 1

Claude Code Orange Book

View on GitHub Fetched 2026-07-02 5 related flows

Summary

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.

Key Takeaways

  • Agent loop, compaction, hooks, and sub-agents each get chapter-level treatment
  • Frames every mechanism as an engineering decision with trade-offs
  • Best source for architecture diagrams' underlying concepts

Reliability Note

Independent reverse-engineering effort - unofficial, verify against official Anthropic docs and behavior. Original text in Chinese; concepts summarized here in English.

Flows informed by this source

5
Flows category icon
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.

01Define the loop contract
02Build the tool registry
03Implement the loop with result folding

+2 more steps to Done

Best forproduction-grade builds with strict verification

5 steps90-150 minutesAdvanced
Flows category icon
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.

01Specify the delegation contract
02Implement the isolated sub-loop
03Wire dispatch into the parent and distill

+1 more steps to Done

Best forproduction-grade builds with strict verification

4 steps90-150 minutesAdvanced
Flows category icon
Memory & Context

Implement Context Compaction

Keep long agent sessions alive by compacting old conversation into structured summaries before the context window fills.

01Add token accounting
02Design the structured summary format
03Implement the compaction operation

+1 more steps to Done

Best forproduction-grade builds with strict verification

4 steps90-120 minutesAdvanced
Flows category icon
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.

01Decompose the current prompt
02Build the section-based assembler
03Pair rules with enforcement

+1 more steps to Done

Best forbuilders who have shipped a basic app before

4 steps60-90 minutesIntermediate
Flows category icon
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.

01Measure usage and pick the core
02Build the catalog and discovery
03Implement dynamic registration

+1 more steps to Done

Best forproduction-grade builds with strict verification

4 steps90-120 minutesAdvanced

Made with Emergent