Claude Code Architecture Analysis from Leaked Source Maps

Technical Stack and Architecture
The Claude Code package published to npm on March 31, 2026, included .map files that revealed the complete TypeScript source code. The codebase consists of approximately 1,900 files with 512,000+ lines of TypeScript.
Core Technologies
- Runtime: Bun
- Language: TypeScript (strict mode)
- Terminal UI: React + Ink (React for CLI)
- CLI Parsing: Commander.js with extra typings
- Schema Validation: Zod v4
- Code Search: ripgrep via GrepTool
- Protocols: MCP SDK, LSP (vscode-jsonrpc)
- API: Anthropic SDK
- Telemetry: OpenTelemetry + gRPC (lazy-loaded, ~400KB + 700KB)
- Feature Flags: GrowthBook
- Auth: OAuth 2.0, JWT, macOS Keychain
- State Management: Zustand (React-based store)
Directory Structure Highlights
The src/ directory contains:
main.tsx- Entry point with Commander.js CLI + React/Ink renderingcommands.ts- Command registry with 100+ commandstools.ts- Tool registry with 38+ toolsTool.ts- Tool type definitionsQueryEngine.ts- LLM query engine (~46K lines)query.ts- Main query loop (~1,729 lines)context.ts- System/user context collectioncost-tracker.ts- Token cost trackingcommands/- Slash command implementations (100+)tools/- Tool implementations (38+)components/- Ink UI components (~140)hooks/- React Hooks + permission hooksservices/- External service integrations including API, MCP, LSP, context compression, memory extraction, and analyticsconstants/- System prompts + constantsbridge/- IDE integration bridgecoordinator/- Multi-agent coordinatorplugins/- Plugin systemskills/- Skill systemmemdir/- Persistent memory systemtasks/- Task management systemstate/- State managementremote/- Remote sessionsserver/- Server modevim/- Vim mode with complete state machinevoice/- Voice inputkeybindings/- Keybinding systemscreens/- Fullscreen UI (Doctor, REPL, Resume)schemas/- Zod config schemasmigrations/- Config migrationsquery/- Query pipeline submodulesoutputStyles/- Output stylesbuddy/- Companion sprite (easter egg)
Core Data Flow
The system follows this data flow pattern:
- User input (terminal / IDE / remote)
main.tsx→ Commander.js parsingREPL.tsx(main interaction loop)QueryEngine.submitMessage()← session lifecycle- Message preparation stage includes:
applyToolResultBudget()- result size capsnipCompact()- snippet compactionmicroCompact()- micro compactioncontextCollapse()- context collapseautoCompact()- automatic compaction
This analysis is based on the leaked source code that provides insight into how a production AI coding agent manages context, tools, and multi-agent coordination.
📖 Read the full source: r/ClaudeAI
👀 See Also

Engramx v3.4: MCP Server + SQLite Knowledge Graph Cuts Claude Code Token Usage by 89%
Engramx v3.4 intercepts file reads for Claude Code agents, returning structural summaries instead of raw content. Benchmarks show 89.1% aggregate token reduction across an 87-file codebase.

ClawCall: OpenClaw skill for AI phone calls with bridge mode
ClawCall is an OpenClaw skill that enables AI agents to make actual phone calls, navigate menus, wait on hold, and conduct conversations. It includes a bridge mode that patches you in when a human picks up.

OpenClaw Client Adds Live API Cost Tracking, Spending Caps, and Granular Agent Controls
OpenClaw Client now features live usage UI with circular progress bars, per-agent spending caps, sub-agent management, skill toggling, and model switching from different providers.

MCP Marketplace Launches Security-Scanned Directory of 1,900+ MCP Tool Plugins
MCP Marketplace (mcp-marketplace.io) provides a security-focused directory of 1,900+ MCP servers with multi-layer security analysis, risk scoring, and one-click installation for Claude Desktop, Cursor, ChatGPT, and VS Code.