(Alleged) Leaked source of Claude Code
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 257 lines 9.8 kB view raw view rendered
1# Claude Code — Leaked Source (2026-03-31) 2 3> **On March 31, 2026, the full source code of Anthropic's Claude Code CLI was leaked** via a `.map` file exposed in their npm registry. 4 5--- 6 7## How It Leaked 8 9[Chaofan Shou (@Fried_rice)](https://x.com/Fried_rice) discovered the leak and posted it publicly: 10 11> **"Claude code source code has been leaked via a map file in their npm registry!"** 12> 13> — [@Fried_rice, March 31, 2026](https://x.com/Fried_rice/status/2038894956459290963) 14 15The 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. 16 17--- 18 19## Overview 20 21Claude Code is Anthropic's official CLI tool that lets you interact with Claude directly from the terminal to perform software engineering tasks — editing files, running commands, searching codebases, managing git workflows, and more. 22 23This repository contains the leaked `src/` directory. 24 25- **Leaked on**: 2026-03-31 26- **Language**: TypeScript 27- **Runtime**: Bun 28- **Terminal UI**: React + [Ink](https://github.com/vadimdemedes/ink) (React for CLI) 29- **Scale**: ~1,900 files, 512,000+ lines of code 30 31--- 32 33## Directory Structure 34 35``` 36src/ 37├── main.tsx # Entrypoint (Commander.js-based CLI parser) 38├── commands.ts # Command registry 39├── tools.ts # Tool registry 40├── Tool.ts # Tool type definitions 41├── QueryEngine.ts # LLM query engine (core Anthropic API caller) 42├── context.ts # System/user context collection 43├── cost-tracker.ts # Token cost tracking 44 45├── commands/ # Slash command implementations (~50) 46├── tools/ # Agent tool implementations (~40) 47├── components/ # Ink UI components (~140) 48├── hooks/ # React hooks 49├── services/ # External service integrations 50├── screens/ # Full-screen UIs (Doctor, REPL, Resume) 51├── types/ # TypeScript type definitions 52├── utils/ # Utility functions 53 54├── bridge/ # IDE integration bridge (VS Code, JetBrains) 55├── coordinator/ # Multi-agent coordinator 56├── plugins/ # Plugin system 57├── skills/ # Skill system 58├── keybindings/ # Keybinding configuration 59├── vim/ # Vim mode 60├── voice/ # Voice input 61├── remote/ # Remote sessions 62├── server/ # Server mode 63├── memdir/ # Memory directory (persistent memory) 64├── tasks/ # Task management 65├── state/ # State management 66├── migrations/ # Config migrations 67├── schemas/ # Config schemas (Zod) 68├── entrypoints/ # Initialization logic 69├── ink/ # Ink renderer wrapper 70├── buddy/ # Companion sprite (Easter egg) 71├── native-ts/ # Native TypeScript utils 72├── outputStyles/ # Output styling 73├── query/ # Query pipeline 74└── upstreamproxy/ # Proxy configuration 75``` 76 77--- 78 79## Core Architecture 80 81### 1. Tool System (`src/tools/`) 82 83Every tool Claude Code can invoke is implemented as a self-contained module. Each tool defines its input schema, permission model, and execution logic. 84 85| Tool | Description | 86|---|---| 87| `BashTool` | Shell command execution | 88| `FileReadTool` | File reading (images, PDFs, notebooks) | 89| `FileWriteTool` | File creation / overwrite | 90| `FileEditTool` | Partial file modification (string replacement) | 91| `GlobTool` | File pattern matching search | 92| `GrepTool` | ripgrep-based content search | 93| `WebFetchTool` | Fetch URL content | 94| `WebSearchTool` | Web search | 95| `AgentTool` | Sub-agent spawning | 96| `SkillTool` | Skill execution | 97| `MCPTool` | MCP server tool invocation | 98| `LSPTool` | Language Server Protocol integration | 99| `NotebookEditTool` | Jupyter notebook editing | 100| `TaskCreateTool` / `TaskUpdateTool` | Task creation and management | 101| `SendMessageTool` | Inter-agent messaging | 102| `TeamCreateTool` / `TeamDeleteTool` | Team agent management | 103| `EnterPlanModeTool` / `ExitPlanModeTool` | Plan mode toggle | 104| `EnterWorktreeTool` / `ExitWorktreeTool` | Git worktree isolation | 105| `ToolSearchTool` | Deferred tool discovery | 106| `CronCreateTool` | Scheduled trigger creation | 107| `RemoteTriggerTool` | Remote trigger | 108| `SleepTool` | Proactive mode wait | 109| `SyntheticOutputTool` | Structured output generation | 110 111### 2. Command System (`src/commands/`) 112 113User-facing slash commands invoked with `/` prefix. 114 115| Command | Description | 116|---|---| 117| `/commit` | Create a git commit | 118| `/review` | Code review | 119| `/compact` | Context compression | 120| `/mcp` | MCP server management | 121| `/config` | Settings management | 122| `/doctor` | Environment diagnostics | 123| `/login` / `/logout` | Authentication | 124| `/memory` | Persistent memory management | 125| `/skills` | Skill management | 126| `/tasks` | Task management | 127| `/vim` | Vim mode toggle | 128| `/diff` | View changes | 129| `/cost` | Check usage cost | 130| `/theme` | Change theme | 131| `/context` | Context visualization | 132| `/pr_comments` | View PR comments | 133| `/resume` | Restore previous session | 134| `/share` | Share session | 135| `/desktop` | Desktop app handoff | 136| `/mobile` | Mobile app handoff | 137 138### 3. Service Layer (`src/services/`) 139 140| Service | Description | 141|---|---| 142| `api/` | Anthropic API client, file API, bootstrap | 143| `mcp/` | Model Context Protocol server connection and management | 144| `oauth/` | OAuth 2.0 authentication flow | 145| `lsp/` | Language Server Protocol manager | 146| `analytics/` | GrowthBook-based feature flags and analytics | 147| `plugins/` | Plugin loader | 148| `compact/` | Conversation context compression | 149| `policyLimits/` | Organization policy limits | 150| `remoteManagedSettings/` | Remote managed settings | 151| `extractMemories/` | Automatic memory extraction | 152| `tokenEstimation.ts` | Token count estimation | 153| `teamMemorySync/` | Team memory synchronization | 154 155### 4. Bridge System (`src/bridge/`) 156 157A bidirectional communication layer connecting IDE extensions (VS Code, JetBrains) with the Claude Code CLI. 158 159- `bridgeMain.ts` — Bridge main loop 160- `bridgeMessaging.ts` — Message protocol 161- `bridgePermissionCallbacks.ts` — Permission callbacks 162- `replBridge.ts` — REPL session bridge 163- `jwtUtils.ts` — JWT-based authentication 164- `sessionRunner.ts` — Session execution management 165 166### 5. Permission System (`src/hooks/toolPermission/`) 167 168Checks 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.). 169 170### 6. Feature Flags 171 172Dead code elimination via Bun's `bun:bundle` feature flags: 173 174```typescript 175import { feature } from 'bun:bundle' 176 177// Inactive code is completely stripped at build time 178const voiceCommand = feature('VOICE_MODE') 179 ? require('./commands/voice/index.js').default 180 : null 181``` 182 183Notable flags: `PROACTIVE`, `KAIROS`, `BRIDGE_MODE`, `DAEMON`, `VOICE_MODE`, `AGENT_TRIGGERS`, `MONITOR_TOOL` 184 185--- 186 187## Key Files in Detail 188 189### `QueryEngine.ts` (~46K lines) 190 191The core engine for LLM API calls. Handles streaming responses, tool-call loops, thinking mode, retry logic, and token counting. 192 193### `Tool.ts` (~29K lines) 194 195Defines base types and interfaces for all tools — input schemas, permission models, and progress state types. 196 197### `commands.ts` (~25K lines) 198 199Manages registration and execution of all slash commands. Uses conditional imports to load different command sets per environment. 200 201### `main.tsx` 202 203Commander.js-based CLI parser + React/Ink renderer initialization. At startup, parallelizes MDM settings, keychain prefetch, and GrowthBook initialization for faster boot. 204 205--- 206 207## Tech Stack 208 209| Category | Technology | 210|---|---| 211| Runtime | [Bun](https://bun.sh) | 212| Language | TypeScript (strict) | 213| Terminal UI | [React](https://react.dev) + [Ink](https://github.com/vadimdemedes/ink) | 214| CLI Parsing | [Commander.js](https://github.com/tj/commander.js) (extra-typings) | 215| Schema Validation | [Zod v4](https://zod.dev) | 216| Code Search | [ripgrep](https://github.com/BurntSushi/ripgrep) (via GrepTool) | 217| Protocols | [MCP SDK](https://modelcontextprotocol.io), LSP | 218| API | [Anthropic SDK](https://docs.anthropic.com) | 219| Telemetry | OpenTelemetry + gRPC | 220| Feature Flags | GrowthBook | 221| Auth | OAuth 2.0, JWT, macOS Keychain | 222 223--- 224 225## Notable Design Patterns 226 227### Parallel Prefetch 228 229Startup time is optimized by prefetching MDM settings, keychain reads, and API preconnect in parallel — before heavy module evaluation begins. 230 231```typescript 232// main.tsx — fired as side-effects before other imports 233startMdmRawRead() 234startKeychainPrefetch() 235``` 236 237### Lazy Loading 238 239Heavy modules (OpenTelemetry ~400KB, gRPC ~700KB) are deferred via dynamic `import()` until actually needed. 240 241### Agent Swarms 242 243Sub-agents are spawned via `AgentTool`, with `coordinator/` handling multi-agent orchestration. `TeamCreateTool` enables team-level parallel work. 244 245### Skill System 246 247Reusable workflows defined in `skills/` and executed through `SkillTool`. Users can add custom skills. 248 249### Plugin Architecture 250 251Built-in and third-party plugins are loaded through the `plugins/` subsystem. 252 253--- 254 255## Disclaimer 256 257This 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](https://www.anthropic.com).