DDCC
Based on Claude Code source · 13 interactive chapters

Deep Dive
Claude Code

Production Claude Code has 960+ files, 50+ integrated tools, 380K+ lines of code
These 13 chapters take you from the core loop to the full engineering picture, layer by layer.

SOURCE CODE WALKTHROUGH

Core Agentic Loop

Every AI Agent is essentially a loop. Claude Code's core is implemented in QueryEngine.ts (46KB) and query.ts (67KB). Click each step to see the corresponding source code location and implementation details.

Tool results feed back, loop continues
1

User Input

User enters natural language instructions in the REPL

// src/entrypoints/cli.tsx
const userInput = await readline()
messages.push({ role: "user", content: userInput })
WHY DEEP DIVE

From 30 Lines to 960 Files

A teaching Agent's core loop is just 30 lines, but how much engineering does production Claude Code stack on top of the same loop?

Teaching~30 lines Python
# A complete Agent core
while True:
response = llm.call(messages)
if response.stop_reason != "tool_use":
break
result = execute(response.tool)
messages.append(result)
Synchronous API calls
No permission checks
No context management
Crash = data loss
Single Agent
Production Claude CodeSame loop + 12 layers of engineering
Ch01
Streaming + Retry
AsyncGenerator streaming, exponential backoff, fallback models
Ch02
50+ Tool Registry
Unified schema validation + conditional compilation + timeout
Ch03
Dynamic Prompt
4-layer pipeline assembly, CLAUDE.md project config
Ch04
300KB Security
Bash AST parsing + path sandbox + AI classifier
Ch05
Permission Engine
allow/deny/ask rules + env variable sanitization
Ch06
3-Layer Compaction
Micro-compact + auto-compact + dream memory consolidation
Ch07
MCP Protocol
External tool discovery + OAuth + multi-level config
Ch09
Multi-Agent
Subagent / Teammate / Swarm 3-tier collaboration
ARCHITECTURE LAYERS

Five Architecture Layers

960 TypeScript files organized into five architecture layers. Click to expand and see core files, design patterns, and corresponding chapters.

L1
Engine Core
5 chapters in depth
L2
Tools & Security
2 chapters in depth
L3
Context Management
1 chapters in depth
L4
Protocols & Collaboration
4 chapters in depth
L5
Hidden Features
1 chapters in depth
HIDDEN FEATURES

8 Hidden Features in the Source Code

Gated by compile-time feature('FLAG'), removed by DCE in external builds, but fully preserved in the restored source.

KEY SOURCE FILES

Key Source Files

Understanding these key files gives you a grasp of the entire system. File size reflects engineering complexity.

LEARNING PATH

13 Chapters of Source Deep Dive

Each chapter focuses on a core subsystem with source analysis + architecture visualization + runnable demos. Filter by architecture layer, or follow the sequence.

Ch01

Agent Loop

Heart of the conversation loop

Every Agent is essentially a loop: call model → execute tool → return result

113KB🔑 Needs API Key
Ch02

Tool System

Registry & dispatch of 50+ tools

Register a handler, gain a capability — the loop never changes

46KB+▶ Directly runnable
Ch03

Prompt Engineering

Dynamic assembly pipeline

System Prompt is not a string — it's a dynamically assembled pipeline

287KB▶ Directly runnable
Ch04

Shell Security

300KB+ security validation

The most powerful tool needs the tightest security

535KB▶ Directly runnable
Ch05

Permission Engine

Every operation is checked

Permissions are not an afterthought — they are the skeleton of the architecture

136KB▶ Directly runnable
Ch06

Context Management

Infinite work in a finite window

Context always fills up — the key is how to compress

130KB+🔑 Needs API Key
Ch07

MCP Protocol

Unified tool calling standard

MCP lets any service become an AI tool

253KB▶ Directly runnable
Ch08

Plugin Ecosystem

Extensible capability boundary

Plugins are capability multipliers

199KB▶ Directly runnable
Ch09

Multi-Agent

Agent/Team/Swarm

Scale comes from division of labor, not larger context

300KB+▶ Directly runnable
Ch10

CLI Transport

Bridge from terminal to remote

The transport layer determines where an Agent can run

100KB+▶ Directly runnable
Ch11

Bootstrap

From Enter to prompt

Fast path determines experience, full path determines capability

785KB▶ Directly runnable
Ch12

Production Patterns

Demo → Production

Making an Agent reliable requires 10x engineering effort

300KB+▶ Directly runnable
Ch13

Hidden Features

Feature flag-gated hidden modules

Behind every feature('FLAG') lies an unreleased product decision

500KB+▶ Directly runnable

The model is the agent. Our job is to give it tools and get out of the way.

But that 'getting out of the way' requires 960 files and 380,000+ lines of TypeScript engineering.