Author: Zhuoran Yang

Claude Code is Anthropic’s agentic coding assistant — 512K lines of TypeScript, a React-based terminal UI, approximately 40 tools governed by a three-tier permission system, and ML classifiers that gate every shell command. This series provides a systematic, source-level walkthrough of how it all fits together.
The analysis is based on the v2.1.88 source tree, recovered from a source map that was inadvertently included in the npm package. The full extracted source is available at github.com/Exhen/claude-code-2.1.88.
Browse all 1,888 source files with enriched descriptions, export maps, and architecture-layer tagging. Open the Code Explorer →
The Series
I. Overview
| I.1 |
Bird’s Eye Architecture |
Shared engine, six layers, context engineering as the key differentiator |
| I.2 |
End-to-End Workflow |
Tracing a single query through the entire pipeline, from CLI input to streaming output |
II. Agent Harness
| II.1 |
Agent Loop & Query Engine |
The agent loop is an async generator — a coroutine that yields streaming events |
| II.2 |
Agent SDK & Structured I/O |
Three entry modes (CLI, SDK, MCP) sharing one agent engine through a data/control plane split |
| II.3 |
Multi-Agent Orchestration |
Sub-agents are fork() for AI — five agent types, subagent prompts, worktree isolation |
| II.4 |
Plan Mode |
Read-only planning with explicit approval gates — separating reasoning from action |
III. Context Engineering
| III.1 |
Prompt Assembly |
65+ fragments assembled through a middleware pipeline before the model sees anything |
| III.2 |
Context Compaction |
Context management is cache eviction applied to conversation history |
| III.3 |
Memory Hierarchy |
Five memory tiers from session to team — a cache hierarchy; plus MagicDocs appendix |
| III.4 |
Hooks & Lifecycle |
Over 25 lifecycle events and system reminders that inject real-time state into context |
V. Invocation
| V.1 |
CLI, Commands & UI |
A full React app in a TTY; plus prompt suggestion, speculation, tips, buddy, and installer appendices |
| V.2 |
Auth, Providers & Flags |
OAuth for terminal apps and feature flags enabling continuous delivery |
VII. Remote Runtime
| VII.1 |
Remote Runtime & Bridge |
The terminal is just one frontend — bridge, remote sessions, and transport abstractions |
IX. Transparency & Trust
| IX.1 |
Transparency & Trust |
Invisible tokens, remote feature flags, opt-out telemetry, enterprise control plane, and silent history rewriting |
Analysis based on Claude Code v2.1.88 (March 2026). All code snippets are reconstructed from the source map for educational purposes. The full extracted source is available at github.com/Exhen/claude-code-2.1.88.