Claude Code Anatomy
How Claude Code actually works, from the decompiled source.
Why This Exists
Claude Code ships as an opaque binary. You can't read how it picks tools, gates permissions, or coordinates agents. So we decompiled it from npm source maps and documented the internals across 4,756 TypeScript files. Key sections include framework comparisons (ADK, OpenAI Agents SDK, LangChain, LangGraph) so the patterns are portable to your own agent architecture.
Some areas of the recovered tree are feature-gated, stubbed, or only partially present. When a subsystem could not be verified directly from source, this site intentionally avoids speculating beyond the observable implementation.
How to Read This Site
Sequential — Read Core Architecture in order: Agent Loop → Sub-Agents → Headless Query Engine & SDK Protocol → Tool System → Task Management → Prompt, Memory & Context → State & Sessions. This traces how the local and headless runtimes fit together.
By topic — Jump to any section. Extensions and Security are self-contained. Runtime & Infrastructure covers startup, rendering, API internals, and remote session architecture.
As a reference — The Appendix has the full directory map, all 90+ feature flags, the command catalog, complete tool definitions, and a glossary.
Architecture at a Glance
Source Recovery
This analysis is based on source code recovered from the @anthropic-ai/claude-code v2.1.88 npm package. The published bundle includes a source map (cli.js.map) containing all 4,756 original TypeScript source files with full sourcesContent, enabling lossless restoration:
# Extract sources from the source map
node -e "
const fs = require('fs'), path = require('path');
const map = JSON.parse(fs.readFileSync('package/cli.js.map', 'utf8'));
for (let i = 0; i < map.sources.length; i++) {
const content = map.sourcesContent[i];
if (!content) continue;
let relPath = map.sources[i];
while (relPath.startsWith('../')) relPath = relPath.slice(3);
const outPath = path.join('./claude-code-source', relPath);
fs.mkdirSync(path.dirname(outPath), { recursive: true });
fs.writeFileSync(outPath, content);
}
"
By the Numbers
| Metric | Value |
|---|---|
| Source files | 4,756 |
| Core source (src/ + vendor/) | 1,906 files |
| Built-in tools | 45+ |
| Slash commands | 100+ |
| Feature flags | 90+ |
| npm dependencies | 489 packages |
| Build output | ~22 MB |
| Version analyzed | 2.1.88 |
Technology Stack
| Technology | Role | |
|---|---|---|
| TypeScript 6.0 | Language | |
| React 19 + Ink 6 | Terminal UI framework | |
| Bun | Build tool | |
| Custom store | State management | |
| Zod | Schema validation | |
| Commander | Argument parsing | |
| Anthropic SDK | API client | |
| MCP SDK | Model Context Protocol | |
| OpenTelemetry | Observability |