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

QCAI Mobile App Adds OpenClaw Gateway Control with Native Tailscale VPN
QCAI for iOS and Android now integrates with OpenClaw Control Center, allowing direct gateway management from mobile devices via secure Tailscale VPN tunnels without open ports.

Prompt-Master: Claude Skill for Generating Accurate AI Tool Prompts
Prompt-Master is a free Claude skill that writes accurate prompts for various AI tools including Cursor, Claude Code, GPT, Midjourney, Kling, and Eleven Labs. The tool has reached 600+ stars on GitHub and processes 4000+ traffic.

Keyoku Plugin Replaces OpenClaw's Static Heartbeat with Memory-Driven Autonomy
Keyoku is a free OpenClaw plugin that changes the agent's heartbeat from reading a static HEARTBEAT.md file to scanning the agent's actual memory store for stalled work, dropped commitments, conflicting information, and quiet relationships. It uses a local Go engine with SQLite + HNSW and offers three autonomy levels: observe, suggest, and act.

Free macOS Menu Bar App Shows Real-Time Claude Usage Stats via SQLite Cookie Decryption
Claude Usage Tracker is a free macOS menu bar app that reads Claude desktop app encrypted SQLite cookies, decrypts them via Keychain, and displays session %, weekly limit, spend, and routine runs locally — no API key needed.