← all repositories
Windy3f3f3f3f/how-claude-code-works

A 500K-line codebase dissected with its own subject

Reverse-engineering Claude Code's internals—using Claude Code itself—to produce a 15-chapter field guide on how a production AI agent actually works.

how-claude-code-works
Velocity · 7d
+38
★ / day
Trend
steady
star history

What it does This repo is a structured teardown of Anthropic’s Claude Code, a 512,000-line TypeScript agent that edits files, runs shell commands, and manages multi-turn coding tasks. The authors read the source with Claude Code’s assistance, then wrote 15 chapters documenting the architecture, agent loop, context compression, tool system, and security model. A companion repo offers a ~4,000-line from-scratch rebuild in TypeScript or Python.

The interesting bit The project is meta in the best way: the authors used Claude Code to help reverse-engineer Claude Code, turning the tool into its own research instrument. The resulting docs cover genuinely gnarly production problems—like hiding ~1s tool latency inside a 5–30s model inference window via speculative tool execution, or a four-tier context compression pipeline that truncates, deduplicates, folds, and finally summarizes only when necessary.

Key highlights

  • 15 chapters covering agent loop, context engineering, 66-tool orchestration, memory system, multi-agent modes, and security
  • Silent recovery: 7 distinct “continue” strategies in the agent loop to absorb errors without surfacing them to the user
  • 4-level progressive compression for context windows, with automatic restoration of the 5 most recently edited files post-compression
  • 5-layer security defense including Bash AST analysis (23 checks), permission modes, and a 200ms debounce on dangerous-action confirmations
  • Multi-agent isolation via Git worktrees to prevent file-edit conflicts between concurrent agents

Caveats

  • The documentation is primarily in Chinese; an English README exists but the 15 chapters appear untranslated
  • The “512,000+ lines” and “1,884 TypeScript files” figures come from the authors’ own analysis, not independently verified
  • The companion “from scratch” repo is framed as educational; it is unclear how complete a reproduction it achieves

Verdict Worth your time if you are building or architecting AI agents and need to see how a production system handles context limits, tool concurrency, and safety. Less useful if you want runnable code or English-language deep dives.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.