Skip to content

thyagofarya/Deep-Dive-Claude-Code

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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:

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

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!

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 99.6%
  • Other 0.4%