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

Benchmark shows context engine reduces AI coding agent costs by 3x on SWE-bench
A benchmark of 4 coding agents using Claude Opus 4.5 on SWE-bench Verified shows a context engine achieved 73% pass rate at $0.67/task, while other agents cost up to $1.98/task for similar or lower performance.

fintool adds stock and prediction market trading to OpenClaw agents
fintool is a new OpenClaw skill that enables AI agents to trade stocks and prediction markets. Installation requires reading a GitHub file, after which agents can execute trades on Hyperliquid, Binance, and Polymarket with JSON output for clean integration.

OpenClaw iOS app adds historical Apple Health data sync up to 18 months
The latest version of the OpenClaw iOS app enables historical Apple Health data export, allowing users to sync up to 18 months of health data to their agent for personalized insights or AI training.

Tripsy Launches MCP Server for Claude: Manage Trips via Structured API
Tripsy's official MCP server lets Claude directly read, create, and update trips, activities, stays, transportation, and expenses. Setup takes ~1 minute via Claude's custom connector.