Star ๅๅฒ่ถๅฟ
ๆฐๆฎๆฅๆบ: GitHub API ยท ็ๆ่ช Stargazers.cn
README.md
Deep Dive Claude Code
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



๐ 13-Chapter Learning Path
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
๐ About
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 |
๐ Chapter Index
| 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 |
๐ Getting Started
Web Platform (Recommended)
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.
CLI Demos
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!๐ Project Structure
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
๐ ๏ธ Tech Stack
Learning Platform (web/)
| 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 |
Analyzed Project (Claude Code)
| 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) |
๐ Acknowledgments
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!