On March 31, 2026, the full source code of Anthropic's Claude Code CLI was leaked via a
.mapfile exposed in their npm registry.
Chaofan Shou (@Fried_rice) discovered the leak and posted it publicly:
"Claude code source code has been leaked via a map file in their npm registry!"
The source map file in the published npm package contained a reference to the full, unobfuscated TypeScript source, which was downloadable as a zip archive from Anthropic's R2 storage bucket.
| Metric | Value |
|---|---|
| Source files | 1,902 |
TypeScript files (.ts) |
1,332 |
React/TSX files (.tsx) |
552 |
| Lines of code | 512,664 |
| Top-level directories | 36 |
| Total directories | 301 |
| Built-in tools | 43 |
| Slash commands | 101 |
| UI components | 144 |
| React hooks | 85 |
| Service modules | 36 |
| File | Lines | Role |
|---|---|---|
src/main.tsx |
4,683 | CLI entry point, Commander.js parser, Ink bootstrap |
src/QueryEngine.ts |
1,295 | Core LLM API engine, streaming, tool-call loops |
src/Tool.ts |
792 | Base type definitions for all tools |
src/commands.ts |
754 | Command registry and dispatch |
src/tools.ts |
389 | Tool registry and construction |
src/cost-tracker.ts |
323 | Token cost tracking |
src/context.ts |
189 | System/user context collection for LLM prompts |
This repository includes a comprehensive Chinese technical documentation set covering the full Claude Code source.
| Document | Difficulty | Content | Read Time |
|---|---|---|---|
| Getting Started | entry | Installation, core concepts, first session | 15 min |
| Architecture Overview | expert | Module layout, data flow, initialization, design decisions | 30 min |
| Core Principles | advanced | QueryEngine mechanism, tool loops, context management | 25 min |
| Usage Guide | intermediate | CLI arguments, slash commands, permissions, configuration | 20 min |
| Source Analysis | expert | Tool system, command system, UI layer, service layer deep dive | 40 min |
| Development & Extensions | advanced | MCP integration, custom tools, plugin system, Skills development | 25 min |
| Use Cases | intermediate | Code review, debugging, refactoring, docs generation, multi-agent | 20 min |
Quick start path (for users):
Getting Started -> Usage Guide -> Use Cases -> Core Principles
Start with practical operations, then build understanding of internals.
Developer path (for contributors / integrators):
Architecture Overview -> Core Principles -> Source Analysis -> Development & Extensions
Dive deep into the internals and learn how to extend the system.
Architect path (for technical evaluators):
Architecture Overview -> Core Principles -> Development & Extensions -> Source Analysis
Evaluate design decisions, extensibility, and integration capabilities first.
src/
|-- main.tsx # Entrypoint (Commander.js CLI parser + Ink renderer)
|-- commands.ts # Slash command registry (754 lines)
|-- tools.ts # Tool registry (389 lines)
|-- Tool.ts # Tool base type definitions (792 lines)
|-- QueryEngine.ts # LLM query engine, streaming, tool loops (1,295 lines)
|-- context.ts # System/user context collection
|-- cost-tracker.ts # Token cost tracking
|
|-- commands/ # Slash command implementations (101 modules)
|-- tools/ # Agent tool implementations (43 tools)
|-- components/ # Ink UI components (144 files)
|-- hooks/ # React hooks (85 files)
|-- services/ # External service integrations (36 modules)
|-- screens/ # Full-screen UIs (Doctor, REPL, Resume)
|-- types/ # TypeScript type definitions + generated protos
|-- utils/ # Utility functions
|
|-- bridge/ # IDE integration bridge (VS Code, JetBrains)
|-- coordinator/ # Multi-agent orchestration
|-- plugins/ # Plugin system (built-in + third-party)
|-- skills/ # Skill system (reusable workflows)
|-- keybindings/ # Keybinding configuration
|-- vim/ # Vim emulation mode
|-- voice/ # Voice input (feature-gated)
|-- remote/ # Remote session support
|-- server/ # Server mode
|-- memdir/ # Memory directory (persistent memory)
|-- tasks/ # Task management (create/update/list/stop)
|-- state/ # App state management (React context)
|-- migrations/ # Configuration version migrations
|-- schemas/ # Zod config schemas (centralized)
|-- entrypoints/ # Initialization logic
|-- ink/ # Ink renderer wrapper (layout, hooks, events)
|-- buddy/ # Companion sprite (Easter egg)
|-- native-ts/ # Native TypeScript utilities
|-- outputStyles/ # Output styling
|-- query/ # Query pipeline
|-- upstreamproxy/ # Proxy configuration
|-- assistant/ # Assistant-level logic
|-- bootstrap/ # Bootstrap / early initialization
|-- cli/ # CLI utilities
|-- constants/ # Shared constants
|-- context/ # Context providers
|-- moreright/ # Extended right-hand UI
Every tool Claude Code can invoke is implemented as a self-contained module using a consistent pattern: Zod v4 input schema, permission model, and execution logic. Tools are created via buildTool() and registered in src/tools.ts. Feature-gated tools use bun:bundle for dead code elimination.
| Tool | Description |
|---|---|
BashTool |
Shell command execution |
FileReadTool |
File reading (images, PDFs, notebooks) |
FileWriteTool |
File creation / overwrite |
FileEditTool |
Partial file modification (string replacement) |
GlobTool |
File pattern matching search |
GrepTool |
ripgrep-based content search |
WebFetchTool |
Fetch URL content |
WebSearchTool |
Web search |
AgentTool |
Sub-agent spawning |
SkillTool |
Skill execution |
MCPTool |
MCP server tool invocation |
LSPTool |
Language Server Protocol integration |
NotebookEditTool |
Jupyter notebook editing |
TaskCreateTool / TaskUpdateTool / TaskGetTool / TaskListTool / TaskStopTool |
Task lifecycle management |
TaskOutputTool |
Task output retrieval |
SendMessageTool |
Inter-agent messaging |
TeamCreateTool / TeamDeleteTool |
Team agent management |
EnterPlanModeTool / ExitPlanModeTool |
Plan mode toggle |
EnterWorktreeTool / ExitWorktreeTool |
Git worktree isolation |
ToolSearchTool |
Deferred tool discovery |
ScheduleCronTool |
Scheduled trigger creation |
RemoteTriggerTool |
Remote trigger |
SleepTool |
Proactive mode wait |
SyntheticOutputTool |
Structured output generation |
AskUserQuestionTool |
User interaction prompts |
BriefTool |
Briefing / summarization |
ConfigTool |
Runtime configuration changes |
PowerShellTool |
PowerShell command execution (Windows) |
REPLTool |
REPL session management |
ListMcpResourcesTool / ReadMcpResourceTool / McpAuthTool |
MCP resource and auth management |
TodoWriteTool |
Todo list management |
BashTool (shared utils) |
Shared tool utilities |
User-facing slash commands invoked with / prefix. 101 command modules covering development workflows, IDE integration, and system management.
| Command | Description |
|---|---|
/commit |
Create a git commit |
/review |
Code review |
/compact |
Context compression |
/mcp |
MCP server management |
/config |
Settings management |
/doctor |
Environment diagnostics |
/login / /logout |
Authentication |
/memory |
Persistent memory management |
/skills |
Skill management |
/tasks |
Task management |
/vim |
Vim mode toggle |
/diff |
View changes |
/cost |
Check usage cost |
/theme |
Change theme |
/context |
Context visualization |
/pr_comments |
View PR comments |
/resume |
Restore previous session |
/share |
Share session |
/desktop |
Desktop app handoff |
/mobile |
Mobile app handoff |
| Service | Description |
|---|---|
api/ |
Anthropic API client, file API, bootstrap |
mcp/ |
Model Context Protocol server connection and management |
oauth/ |
OAuth 2.0 authentication flow |
lsp/ |
Language Server Protocol manager |
analytics/ |
GrowthBook-based feature flags and analytics |
plugins/ |
Plugin loader |
compact/ |
Conversation context compression |
policyLimits/ |
Organization policy limits |
remoteManagedSettings/ |
Remote managed settings |
extractMemories/ |
Automatic memory extraction |
tokenEstimation.ts |
Token count estimation |
teamMemorySync/ |
Team memory synchronization |
SessionMemory/ |
Session-level memory management |
MagicDocs/ |
Magic document processing |
PromptSuggestion/ |
Prompt suggestion engine |
autoDream/ |
Automatic dream / background processing |
A bidirectional communication layer connecting IDE extensions (VS Code, JetBrains) with the Claude Code CLI via JWT-authenticated message protocol.
bridgeMain.ts-- Bridge main loopbridgeMessaging.ts-- Message protocolbridgePermissionCallbacks.ts-- Permission callbacksreplBridge.ts-- REPL session bridgejwtUtils.ts-- JWT-based authenticationsessionRunner.ts-- Session execution management
Checks permissions on every tool invocation. Either prompts the user for approval/denial or automatically resolves based on the configured permission mode (default, plan, bypassPermissions, auto, etc.).
Dead code elimination via Bun's bun:bundle feature flags:
import { feature } from 'bun:bundle'
// Inactive code is completely stripped at build time
const voiceCommand = feature('VOICE_MODE')
? require('./commands/voice/index.js').default
: nullNotable flags: PROACTIVE, KAIROS, BRIDGE_MODE, DAEMON, VOICE_MODE, AGENT_TRIGGERS, MONITOR_TOOL
| Category | Technology |
|---|---|
| Runtime | Bun |
| Language | TypeScript (strict) |
| Terminal UI | React + Ink |
| CLI Parsing | Commander.js (extra-typings) |
| Schema Validation | Zod v4 |
| Code Search | ripgrep (via GrepTool) |
| Protocols | MCP SDK, LSP |
| API | Anthropic SDK |
| Telemetry | OpenTelemetry + gRPC |
| Feature Flags | GrowthBook |
| Auth | OAuth 2.0, JWT, macOS Keychain |
Startup time is optimized by prefetching MDM settings, keychain reads, and API preconnect in parallel -- before heavy module evaluation begins.
// main.tsx -- fired as side-effects before other imports
startMdmRawRead()
startKeychainPrefetch()Heavy modules (OpenTelemetry ~400KB, gRPC ~700KB) are deferred via dynamic import() until actually needed.
Sub-agents are spawned via AgentTool, with coordinator/ handling multi-agent orchestration. TeamCreateTool enables team-level parallel work.
Reusable workflows defined in skills/ and executed through SkillTool. Users can add custom skills.
Built-in and third-party plugins are loaded through the plugins/ subsystem.
This repository archives source code that was leaked from Anthropic's npm registry on 2026-03-31. All original source code is the property of Anthropic.