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

Home

Chapter Detail

Learning Path

๐Ÿ“š 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:

PartDescription
๐Ÿ“– 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

ChTitleMottoKey Source Files
Ch01Agent LoopThe essence of all Agents is a loopQueryEngine.ts + query.ts
Ch02Tool SystemRegister a handler, gain an abilityTool.ts + tools.ts
Ch03Prompt EngineeringSystem Prompt is a dynamically assembled pipelineprompts.ts + claudemd.ts
Ch04Shell SecurityThe most powerful tool needs the tightest defensebashSecurity.ts + bashParser.ts
Ch05Permission EnginePermissions are the skeleton, not an afterthoughtpermissions.ts + filesystem.ts
Ch06Context ManagementContext always fills up โ€” the key is how to compresscompact.ts + SessionMemory/
Ch07MCP ProtocolMCP turns any service into an AI toolmcp/client.ts + mcp/auth.ts
Ch08Plugin EcosystemPlugins are capability multiplierspluginLoader.ts
Ch09Multi-AgentScale comes from division of labor, not bigger contextAgentTool.tsx + swarm/
Ch10CLI TransportThe transport layer decides where an Agent can runcli/transports/
Ch11Bootstrap OptimizationFast path defines experience, full path defines capabilitydev-entry.ts โ†’ cli.tsx โ†’ main.tsx
Ch12Production PatternsMaking an Agent reliable takes 10x the engineeringsessionStorage.ts + analytics/
Ch13Hidden FeaturesEvery feature('FLAG') line hides a product decisionbuddy/ + 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:3200

Each 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/)

TechnologyPurpose
Next.js 15React framework, App Router
Tailwind CSS 4Dark theme styling
Framer MotionInteractive animations
Lucide ReactIcon library
unified + remark + rehypeMarkdown rendering pipeline

Analyzed Project (Claude Code)

LayerTechnology
RuntimeBun 1.3.5+
LanguageTypeScript (~960 .ts/.tsx files)
Terminal UIReact Ink
CLI FrameworkCommander.js
Tool ProtocolMCP (Model Context Protocol)
A/B TestingGrowthBook
Compile-time Eliminationfeature() 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!

ๅ…ณไบŽ About

๐Ÿ” Source code leak? Production code? 13 chapters breaking down Claude Code's production-grade architecture layer by layer โ€” the most visual + agent simulator + source code analysis

่ฏญ่จ€ Languages

TypeScript99.6%
CSS0.2%
JavaScript0.2%

ๆไบคๆดป่ทƒๅบฆ Commit Activity

ไปฃ็ ๆไบค็ƒญๅŠ›ๅ›พ
่ฟ‡ๅŽป 52 ๅ‘จ็š„ๅผ€ๅ‘ๆดป่ทƒๅบฆ
8
Total Commits
ๅณฐๅ€ผ: 8ๆฌก/ๅ‘จ
Less
More

ๆ ธๅฟƒ่ดก็Œฎ่€… Contributors