Based on 512,664 Lines of Source Code

How Claude
Code Works

A definitive textbook on AI Agent infrastructure design, reverse-engineered from Claude Code's production source.

基于 Claude Code 512,664 行 TypeScript 源码的系统性逆向分析,深入拆解 AI Agent Harness 的每一个设计决策与实现细节。

16
Chapters
4,922
Lines
280
Code Blocks
34
Diagrams
🇨🇳
中文版
完整中文教程
🇬🇧
English
Full English Version
微信 WeChat: felixwll
What's Inside

16 Chapters of Deep Analysis

Chapter 01
What is Harness Engineering?
The three pillars: Context Engineering, Architectural Constraints, Entropy Management. With quantitative ROI data.
TheoryBeginner
Chapter 02
Claude Code Architecture
512K LOC TypeScript. Bun runtime. React+Ink terminal UI. 37 source directories mapped.
Architecture6 Diagrams
Chapter 03
The Agent Loop
queryLoop(): 7 continue sites, 10 exit reasons, 4-level compaction, StreamingToolExecutor. Real source code.
CoreAdvanced
Chapter 04
Tool System
43+ tools. Tool interface with 60+ methods. Partition algorithm. FileEditTool's quote-aware replacement.
CoreReal Code
Chapter 05
Permission Model
5 modes, 7-level hierarchy, YOLO two-stage classifier, defense-in-depth 6 layers.
SecurityAdvanced
Chapter 06
Hooks System
26 events, 4 hook types, async protocol, prompt request protocol, 70% fast-path optimization.
ExtensibilityReal Code
Chapter 07
Sandbox & Security
Filesystem, network, process isolation. Hardcoded denials. Git bare repo attack prevention.
Security
Chapter 08
Context Engineering
CLAUDE.md, 4-type memory system, 4-level compaction pipeline, 200K window budget allocation.
ContextQuantitative
Chapter 09–12
Settings, MCP, Agents, Skills
7-level config hierarchy, 6 MCP transports, 5 agent types, skill frontmatter parsing.
Infrastructure
Chapter 13–14
Practical Guide & Philosophy
3-level harness maturity. 10 design philosophies. Entropy management patterns.
PracticeBeginner
Chapter 15
Build a Mini Harness
200-line Python implementation from scratch. 5 layers matching Claude Code. Runnable exercises.
Hands-onPython
Chapter 16
Competitor Analysis
Claude Code vs Cursor vs Copilot. 12-dimension comparison. OpenDev paper insights.
AnalysisNew