English | δΈζ
Production-grade Claude Code has 960+ files, 50+ integrated tools, and 380K+ lines of code. These 13 chapters take you from the core loop to the full engineering picture, layer by layer.
π Live Demo
Phase 1: Core Loop Phase 2: Security
======================== ========================
Ch01 Agent Loop β
β
β
Ch04 Shell Security β
β
β
The essence of all Agents 300KB+ security code
| |
Ch02 Tool System β
β
β Ch05 Permission Engine β
β
β
50+ tool registration Every op is checked
|
Ch03 Prompt Engineering β
β
β
Dynamic assembly pipeline
Phase 3: Context & Extensions Phase 4: Collaboration & Eng.
======================== ========================
Ch06 Context Management β
β
β
Ch09 Multi-Agent β
β
β
Infinite work in finite ctx Agent/Team/Swarm
| |
Ch07 MCP Protocol β
β
β Ch10 CLI Transport β
ββ
Unified tool-call standard SSE/WS/Hybrid
| |
Ch08 Plugin Ecosystem β
ββ Ch11 Bootstrap Optim. β
ββ
Extensible capabilities Fast path + prefetch
|
Ch12 Production Patterns β
β
β
Demo β Production
Phase 5: Hidden Features
========================
Ch13 Hidden Features β
β
β
Buddy Β· Kairos Β· Ultraplan
Undercover Β· Daemon Β· UDS
This project is based on the source code of Claude Code. Through 13 progressive chapters, it helps developers understand the internal architecture and engineering decisions of a production-grade AI coding assistant.
The project consists of three core parts:
| Part | Description |
|---|---|
π Deep-dive Docs (docs/) |
13 source code analysis documents, each focusing on a core subsystem |
π» Runnable Demos (agents/) |
12 TypeScript demo programs, each independently runnable |
π Interactive Platform (web/) |
Next.js web app with visualizations, simulator, and source viewer |
| Ch | Title | Motto | Key Source Files |
|---|---|---|---|
| Ch01 | Agent Loop | The essence of all Agents is a loop | QueryEngine.ts + query.ts |
| Ch02 | Tool System | Register a handler, gain an ability | Tool.ts + tools.ts |
| Ch03 | Prompt Engineering | System Prompt is a dynamically assembled pipeline | prompts.ts + claudemd.ts |
| Ch04 | Shell Security | The most powerful tool needs the tightest defense | bashSecurity.ts + bashParser.ts |
| Ch05 | Permission Engine | Permissions are the skeleton, not an afterthought | permissions.ts + filesystem.ts |
| Ch06 | Context Management | Context always fills up β the key is how to compress | compact.ts + SessionMemory/ |
| Ch07 | MCP Protocol | MCP turns any service into an AI tool | mcp/client.ts + mcp/auth.ts |
| Ch08 | Plugin Ecosystem | Plugins are capability multipliers | pluginLoader.ts |
| Ch09 | Multi-Agent | Scale comes from division of labor, not bigger context | AgentTool.tsx + swarm/ |
| Ch10 | CLI Transport | The transport layer decides where an Agent can run | cli/transports/ |
| Ch11 | Bootstrap Optimization | Fast path defines experience, full path defines capability | dev-entry.ts β cli.tsx β main.tsx |
| Ch12 | Production Patterns | Making an Agent reliable takes 10x the engineering | sessionStorage.ts + analytics/ |
| Ch13 | Hidden Features | Every feature('FLAG') line hides a product decision |
buddy/ + ultraplan.tsx + undercover.ts |
cd Deep-Dive-Claude-Code/web
npm install
npm run build # Compile docs + source β build
npm run dev # http://localhost:3200Each chapter page has 4 tabs:
- Visualization β Interactive step-by-step animations (13 components)
- Simulator β Agent loop message replay (13 scenarios)
- Source β Key code snippets with TypeScript syntax highlighting
- Deep Dive β Full Markdown document rendering
Source file cards on the home page are clickable and jump to the source viewer with search highlighting.
cd Deep-Dive-Claude-Code
npm install
npx tsx agents/s01_agent_loop.ts # Requires API Key
npx tsx agents/s04_bash_security.ts # No API Key needed β try this!Deep-Dive-Claude-Code/
βββ README.md # This file (English)
βββ README.zh-CN.md # δΈζη
βββ imgs/ # Screenshots
β
βββ docs/ # π 13 deep-dive documents
β βββ ch01-agent-loop.md
β βββ ch02-tool-system.md
β βββ ch03-prompt-engineering.md
β βββ ch04-bash-security.md
β βββ ch05-permissions.md
β βββ ch06-context-management.md
β βββ ch07-mcp-protocol.md
β βββ ch08-plugin-ecosystem.md
β βββ ch09-multi-agent.md
β βββ ch10-cli-transport.md
β βββ ch11-bootstrap.md
β βββ ch12-production-patterns.md
β βββ ch13-hidden-features.md
β
βββ agents/ # π» 12 runnable demo programs
β βββ s01_agent_loop.ts
β βββ ...
β βββ s12_production.ts
β
βββ source-code/ # π Core source files (from main repo)
β βββ QueryEngine.ts
β βββ query.ts
β βββ Tool.ts
β βββ constants/prompts.ts
β βββ tools/BashTool/
β βββ tools/AgentTool/
β βββ utils/permissions/
β βββ services/mcp/
β βββ services/compact/
β
βββ web/ # π Next.js interactive platform
β βββ src/
β β βββ app/ # Pages (home, chapters, architecture, source viewer)
β β βββ components/ # Visualizations, simulator, layout, docs renderer
β β βββ hooks/ # useSteppedVisualization + useSimulator
β β βββ data/ # Scenarios JSON + generated docs/sources
β β βββ lib/ # Constants + utilities
β βββ scripts/ # Build scripts (docsβJSON, sourcesβJSON)
β
βββ package.json # agents/ dependencies
βββ .env.example # API Key template
| Technology | Purpose |
|---|---|
| Next.js 15 | React framework, App Router |
| Tailwind CSS 4 | Dark theme styling |
| Framer Motion | Interactive animations |
| Lucide React | Icon library |
| unified + remark + rehype | Markdown rendering pipeline |
| Layer | Technology |
|---|---|
| Runtime | Bun 1.3.5+ |
| Language | TypeScript (~960 .ts/.tsx files) |
| Terminal UI | React Ink |
| CLI Framework | Commander.js |
| Tool Protocol | MCP (Model Context Protocol) |
| A/B Testing | GrowthBook |
| Compile-time Elimination | feature() macro (bun:bundle) |
This project would not exist without the following open-source projects:
- claude-code-rev β Claude Code source restoration project providing complete TypeScript source code with local build support. All source code analyzed in this project originates from here.
- claw-code β Pioneer in Claude Code source analysis, providing excellent analysis approaches and documentation references.
- claudecode-src Wiki β Comprehensive file-by-file Claude Code source analysis Wiki.
- learn-claude-code β Interactive Agent teaching project. The web platform's interaction patterns (stepped visualization + agent simulator + source viewer) were inspired by this project.
Thank you to all the authors and contributors!


