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

OmniRecall Beta: FAISS-Powered Memory Injection for Cloud LLM Chats
OmniRecall is a local mitmproxy bypass that intercepts traffic to cloud chat interfaces like DeepSeek, adding a permanent memory layer using FAISS indexing and sentence-transformers MiniLM-L6. It's currently in beta, requires CPU-only operation, and uses an aggressively restrictive source-available license.

AgentMind: A Claude Code Plugin That Learns and Applies Your Coding Preferences
AgentMind is a Claude Code plugin that observes your coding patterns, learns preferences like tool choices and style rules, and automatically injects that context into future sessions. It uses a six-step core loop and confidence scoring to determine when to apply learned preferences.

Beagle SCM: A Source Code Management System That Stores AST Trees
Beagle is an experimental source code management system that stores abstract syntax trees instead of binary blobs, using a CRDT-ish data format called BASON and backing storage with key-value databases like RocksDB.

LLM Matrix: Community-Voted Model Comparisons Built with Claude Code
A data scientist built llm-matrix.vercel.app to compare LLM scores across multiple dimensions simultaneously, with community votes shaping rankings. The site was developed entirely using Claude Code with two specific plugins.