Claude Code Architecture Analysis from Leaked Source Maps

✍️ OpenClawRadar📅 Published: April 4, 2026🔗 Source
Claude Code Architecture Analysis from Leaked Source Maps
Ad

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 rendering
  • commands.ts - Command registry with 100+ commands
  • tools.ts - Tool registry with 38+ tools
  • Tool.ts - Tool type definitions
  • QueryEngine.ts - LLM query engine (~46K lines)
  • query.ts - Main query loop (~1,729 lines)
  • context.ts - System/user context collection
  • cost-tracker.ts - Token cost tracking
  • commands/ - Slash command implementations (100+)
  • tools/ - Tool implementations (38+)
  • components/ - Ink UI components (~140)
  • hooks/ - React Hooks + permission hooks
  • services/ - External service integrations including API, MCP, LSP, context compression, memory extraction, and analytics
  • constants/ - System prompts + constants
  • bridge/ - IDE integration bridge
  • coordinator/ - Multi-agent coordinator
  • plugins/ - Plugin system
  • skills/ - Skill system
  • memdir/ - Persistent memory system
  • tasks/ - Task management system
  • state/ - State management
  • remote/ - Remote sessions
  • server/ - Server mode
  • vim/ - Vim mode with complete state machine
  • voice/ - Voice input
  • keybindings/ - Keybinding system
  • screens/ - Fullscreen UI (Doctor, REPL, Resume)
  • schemas/ - Zod config schemas
  • migrations/ - Config migrations
  • query/ - Query pipeline submodules
  • outputStyles/ - Output styles
  • buddy/ - Companion sprite (easter egg)
Ad

Core Data Flow

The system follows this data flow pattern:

  1. User input (terminal / IDE / remote)
  2. main.tsx → Commander.js parsing
  3. REPL.tsx (main interaction loop)
  4. QueryEngine.submitMessage() ← session lifecycle
  5. Message preparation stage includes:
    • applyToolResultBudget() - result size cap
    • snipCompact() - snippet compaction
    • microCompact() - micro compaction
    • contextCollapse() - context collapse
    • autoCompact() - 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

Ad

👀 See Also