Skip to main content

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.

Scope

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

👤
User Input
📥
cli.tsx - Bootstrap
⚙️
main.tsx - Initialization
🖥️
REPL Screen - React/Ink
⌨️
Prompt Input
💬
Message Display
Slash Command?
📋
Yes: Command System
⚙️
No: Query Engine
Query Engine Pipeline
📝
System Prompt Assembly
📡
API Call - Anthropic/Bedrock/Vertex
📡
Streaming Response
Tool Use?
Yes: Tool Pipeline
🔒
Permission Check
🔧
Tool Execution
📤
Tool Result → back to API
No: Render Response
Extensions
MCP Servers
Plugins
Skills
State
Zustand Store
React Contexts
CLAUDE.md Layers

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

MetricValue
Source files4,756
Core source (src/ + vendor/)1,906 files
Built-in tools45+
Slash commands100+
Feature flags90+
npm dependencies489 packages
Build output~22 MB
Version analyzed2.1.88

Technology Stack

TechnologyRole
TypeScriptTypeScript 6.0Language
ReactReact 19 + Ink 6Terminal UI framework
BunBunBuild tool
ZustandCustom storeState management
ZodZodSchema validation
CommanderCommanderArgument parsing
AnthropicAnthropic SDKAPI client
MCPMCP SDKModel Context Protocol
OTELOpenTelemetryObservability