DDCC

Claude Code Architecture Overview

Top-to-bottom layered architecture, ~960 TypeScript files

CLI Entry
cli.tsx → main.tsx
~800KB
Query Engine
QueryEngine.ts + query.ts
113KB
Prompt Pipeline
prompts.ts + claudemd.ts + messages.ts
287KB
Tool System
50+ tools, Tool.ts + tools.ts
1MB+
Security & Permissions
bashSecurity + permissions/
535KB
Context Compaction
compact/ + SessionMemory/ + autoDream/
130KB+
MCP + Plugins
mcp/ + plugins/
450KB+
Multi-Agent
AgentTool + swarm/ + teammate*
300KB+
Transport Layer
transports/ + structuredIO
100KB+
Production Engineering
sessionStorage + analytics + errors
300KB+
Hidden Features (Feature Flags)
buddy/ + ultraplan + undercover + daemon + kairos
500KB+

Data Flow

User Input
  │
  ▼
QueryEngine.submitMessage(prompt)    ← AsyncGenerator
  │
  ├─ fetchSystemPromptParts()        ← Dynamic Prompt Assembly
  │    ├─ Core Identity
  │    ├─ Tool Instructions (50+ tools/*/prompt.ts)
  │    ├─ CLAUDE.md (Multi-level lookup)
  │    └─ Environment Context
  │
  ├─ query() Loop                    ← Core Loop
  │    ├─ API Call (streaming)
  │    ├─ canUseTool() Permission Check
  │    ├─ tool.call() Execution
  │    ├─ microCompact() Micro-compaction
  │    └─ autoCompact() Auto-compaction
  │
  └─ yield SDKMessage                ← Streaming Output
       ├─ Terminal (React Ink)
       ├─ IDE (SSE/WebSocket)
       └─ SDK (NDJSON stdio)

Code Statistics

~960
TypeScript Files
50+
Tools
535KB
Security Code
785KB
Largest File

📦 Want the full source?

This project only extracts core files for teaching. If you want to read the complete Claude Code source, compile and run it locally, visit this repository:

oboard/claude-code-rev

Supports local bun install + bun build to compile and run the full Claude Code.

📖 Full Source Analysis Wiki

Want to systematically read the Claude Code source file by file? Here is a complete source analysis Wiki covering every module with detailed annotations.

claudecode-src Wiki