🔓 Claude Code — Complete Decompiled Source Code
<p align="center"> <img src="https://img.shields.io/badge/Language-TypeScript-blue?style=for-the-badge&logo=typescript"/> <img src="https://img.shields.io/badge/Runtime-Bun-black?style=for-the-badge&logo=bun"/> <img src="https://img.shields.io/badge/Files-1,884-green?style=for-the-badge"/> <img src="https://img.shields.io/badge/Lines_of_Code-512,664-red?style=for-the-badge"/> <img src="https://img.shields.io/badge/Status-Leaked-critical?style=for-the-badge"/> </p>The full internal source code of Anthropic's Claude Code CLI (v1.0.x), reverse-engineered and decompiled from the official npm package.
⚠️ Disclaimer
This repository contains decompiled source code from Anthropic's proprietary Claude Code product. It is published for educational and research purposes only. All intellectual property belongs to Anthropic, PBC. This code is not licensed for redistribution, modification, or commercial use. Use responsibly.
📌 What is Claude Code?
Claude Code is Anthropic's agentic AI coding assistant — a terminal-based CLI tool that integrates the Claude AI model directly into your development workflow. It can:
- Read, write, and edit files autonomously
- Execute shell commands with intelligent sandboxing
- Search codebases using grep, glob, and ripgrep
- Interact with MCP (Model Context Protocol) servers
- Manage multi-agent workflows ("swarms")
- Connect to IDEs (VS Code, JetBrains, etc.)
- Resume, branch, and fork conversations
- Operate in interactive (REPL) and headless (SDK) modes
This repository contains the complete decompiled src/ directory — every internal module, every tool, every prompt, every hook.
🏗️ Architecture Overview
src/
├── main.tsx # CLI entrypoint — argument parsing, migrations, session bootstrap
├── query.ts # Core agentic query loop — the heart of Claude Code
├── QueryEngine.ts # Headless query engine for SDK/non-interactive modes
├── Tool.ts # Tool type system — defines the interface for ALL tools
├── commands.ts # Slash-command registry and loader
├── context.ts # System & user context builders
├── cost-tracker.ts # Token usage & cost tracking
├── history.ts # Session history management
├── setup.ts # First-run setup and onboarding
├── tools.ts # Tool pool assembly and filtering
├── tasks.ts # Background task definitions
│
├── screens/ # Full-screen TUI screens
│ ├── REPL.tsx # The main REPL (895KB, 5,006 lines — the largest file)
│ ├── Doctor.tsx # Diagnostic screen
│ └── ResumeConversation.tsx
│
├── tools/ # All 40+ built-in tools
│ ├── BashTool/ # Shell command execution (with sandbox)
│ ├── FileEditTool/ # AI-powered file editing
│ ├── FileReadTool/ # File reading with range support
│ ├── FileWriteTool/ # Full file creation/overwrite
│ ├── GrepTool/ # Ripgrep-powered code search
│ ├── GlobTool/ # File pattern matching
│ ├── AgentTool/ # Sub-agent spawning (multi-agent)
│ ├── WebSearchTool/ # Web search capability
│ ├── WebFetchTool/ # URL content fetching
│ ├── MCPTool/ # MCP server tool proxying
│ ├── NotebookEditTool/ # Jupyter notebook editing
│ ├── REPLTool/ # REPL tool execution
│ ├── LSPTool/ # Language Server Protocol integration
│ ├── TaskCreateTool/ # Background task creation
│ ├── TeamCreateTool/ # Multi-agent team creation
│ ├── TodoWriteTool/ # TODO list management
│ ├── SkillTool/ # Skill/workflow invocation
│ ├── SleepTool/ # Timed delay tool
│ ├── ScheduleCronTool/ # Cron job scheduling
│ ├── SendMessageTool/ # Inter-agent messaging
│ └── ... (40+ tools total)
│
├── components/ # 140+ Ink (React-for-CLI) UI components
│ ├── Messages.tsx # Conversation message renderer
│ ├── PromptInput/ # User input with autocomplete, vim mode
│ ├── StatusLine.tsx # Bottom status bar
│ ├── Spinner.tsx # Activity spinner with tips
│ ├── ModelPicker.tsx # Model selection dialog
│ ├── ThemePicker.tsx # Theme customization
│ ├── PermissionRequest.tsx # Tool permission dialogs
│ ├── StructuredDiff/ # Side-by-side diff viewer
│ ├── VirtualMessageList.tsx # Virtualized scrolling message list
│ ├── ScrollKeybindingHandler.tsx # Keyboard navigation
│ ├── ConsoleOAuthFlow.tsx # OAuth authentication flow
│ └── ... (140+ components)
│
├── hooks/ # 85+ React hooks
│ ├── useCanUseTool.tsx # Tool permission checking
│ ├── useReplBridge.tsx # Remote control bridge (115KB!)
│ ├── useVoiceIntegration.tsx # Voice mode (99KB!)
│ ├── useTypeahead.tsx # Autocomplete engine (212KB!)
│ ├── useGlobalKeybindings.tsx # Keyboard shortcut system
│ └── ... (85+ hooks)
│
├── utils/ # 300+ utility modules
│ ├── auth.ts # Authentication (OAuth, API keys, keychain)
│ ├── config.ts # Configuration management
│ ├── hooks.ts # Hook lifecycle system (159KB!)
│ ├── messages.ts # Message construction & normalization (193KB!)
│ ├── sessionStorage.ts # Session persistence (180KB!)
│ ├── teleport.tsx # Session teleportation (cloud sync, 175KB!)
│ ├── attachments.ts # File/memory attachments (127KB!)
│ ├── worktree.ts # Git worktree operations
│ ├── permissions/ # Permission system
│ ├── model/ # Model selection & capabilities
│ ├── settings/ # Settings management
│ ├── swarm/ # Multi-agent swarm system
│ ├── mcp/ # MCP client utilities
│ ├── telemetry/ # Analytics & tracing
│ ├── sandbox/ # Command sandboxing
│ └── ... (300+ files)
│
├── services/ # Backend service integrations
│ ├── mcp/ # Model Context Protocol client
│ ├── oauth/ # OAuth 2.0 flow
│ ├── analytics/ # GrowthBook, Statsig, telemetry
│ ├── lsp/ # Language Server Protocol client
│ ├── compact/ # Auto-compaction (context management)
│ ├── api/ # Anthropic API client
│ ├── plugins/ # Plugin system
│ ├── tips/ # User tips & suggestions
│ └── voice.ts # Voice input/STT
│
├── commands/ # 100+ slash commands (/command)
│ ├── init.ts # /init — project initialization
│ ├── commit.ts # /commit — git commit
│ ├── review.ts # /review — code review
│ ├── compact/ # /compact — context compaction
│ ├── doctor/ # /doctor — diagnostics
│ ├── mcp/ # /mcp — MCP server management
│ ├── model/ # /model — model switching
│ ├── teleport/ # /teleport — session sync
│ ├── ultraplan.tsx # /ultraplan — advanced planning
│ ├── insights.ts # /insights — usage analytics (113KB!)
│ └── ... (100+ commands)
│
├── bridge/ # Remote Control Bridge (mobile/web)
│ ├── replBridge.ts # Bridge core (100KB!)
│ ├── bridgeMain.ts # Bridge lifecycle (115KB!)
│ ├── remoteBridgeCore.ts # Remote session bridging
│ ├── jwtUtils.ts # JWT authentication
│ └── trustedDevice.ts # Device trust management
│
├── state/ # Global state management
│ ├── AppState.tsx # React context-based state
│ ├── AppStateStore.ts # State store definition
│ └── store.ts # Zustand-like store
│
├── types/ # TypeScript type definitions
│ ├── message.ts # Message types
│ ├── permissions.ts # Permission types
│ ├── hooks.ts # Hook event types
│ └── plugin.ts # Plugin types
│
├── entrypoints/ # Multiple entry points
│ ├── cli.tsx # Interactive CLI entrypoint
│ ├── mcp.ts # MCP server mode
│ ├── sdk/ # SDK entrypoint
│ └── init.ts # Initialization
│
├── coordinator/ # Multi-agent coordinator mode
│ └── coordinatorMode.ts # Orchestrates agent teams
│
├── plugins/ # Plugin system
│ ├── builtinPlugins.ts # Built-in plugin loader
│ └── bundled/ # Bundled plugins
│
├── skills/ # Skill system
│ ├── bundledSkills.ts # Built-in skills registry
│ ├── loadSkillsDir.ts # Dynamic skill loader
│ └── bundled/ # Bundled skill definitions
│
├── migrations/ # Settings/config migrations
│ ├── migrateSonnet45ToSonnet46.ts
│ ├── migrateOpusToOpus1m.ts
│ └── ... (11 migration scripts)
│
├── vim/ # Vim mode implementation
│ ├── motions.ts # Cursor motions
│ ├── operators.ts # Vim operators
│ ├── textObjects.ts # Text objects
│ └── transitions.ts # Mode transitions
│
├── buddy/ # Companion sprite system (Easter egg)
│ ├── CompanionSprite.tsx # Animated ASCII companion
│ ├── sprites.ts # Sprite definitions
│ └── companion.ts # Companion logic
│
├── voice/ # Voice mode
│ └── voiceModeEnabled.ts # Voice feature gate
│
├── ink/ # Custom Ink (React terminal) extensions
├── keybindings/ # Keybinding system
├── outputStyles/ # Output formatting styles
├── schemas/ # Zod schemas
├── constants/ # Constants and configuration
├── context/ # React contexts
├── native-ts/ # Native TypeScript helpers
├── server/ # Direct-connect server
├── remote/ # Remote session management
├── upstreamproxy/ # Upstream proxy support
├── moreright/ # Layout system
└── memdir/ # In-memory directory abstraction
<p align="center">
<strong>⭐ Star this repo if you found it insightful</strong><br/>
<em>Understanding how AI agents work internally is key to building better ones.</em>
</p>