Claude Code Src Leaked
Check the link to visit the explanation of this code -
Ask AI about Claude Code Src Leaked
Powered by Claude Β· Grounded in docs
I know everything about Claude Code Src Leaked. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
Claude Code β Source
Unofficial public mirror of the Claude Code CLI source. This repository contains the TypeScript/React source code powering Claude Code β Anthropic's official AI-native CLI for software development.
Table of Contents
- Overview
- Key Features
- Architecture
- Directory Structure
- Tech Stack
- Core Systems Deep Dive
- Feature Flags
- Disclaimers
- Contributing
Overview
Claude Code is a terminal-based AI development environment built by Anthropic. It brings Claude's reasoning capabilities directly into your shell, enabling you to:
- Write, edit, and refactor code across entire codebases
- Run shell commands with AI guidance
- Perform multi-step agentic tasks autonomously
- Integrate with IDEs (VS Code, JetBrains), browsers, and mobile apps
- Extend functionality via MCP servers, skills, and plugins
- Manage remote sessions over a bridge protocol
- Schedule background AI agents via cron-like triggers
This repository is a source-level exploration of the Claude Code CLI β ~12,000+ lines of TypeScript across 332+ modules, 80+ CLI commands, 46+ tools, 147 UI components, and 88 custom hooks.
Key Features
| Feature | Description |
|---|---|
| Agentic coding | Claude autonomously edits files, runs tests, fixes bugs across multi-step tasks |
| 46+ Tools | Bash, file read/write/edit, web search/fetch, glob, grep, LSP, agents, MCP |
| 80+ Commands | commit, review, diff, mcp, skills, session, autofix-pr, bughunter, and more |
| Plan Mode | Claude drafts a plan for approval before executing any changes |
| Multi-agent | Spawns and orchestrates sub-agents for parallel workloads |
| Remote Bridge | Connect CLI to remote execution environments over WebSocket |
| Skills System | Define custom slash commands (/my-skill) in JavaScript |
| MCP Protocol | First-class support for Model Context Protocol servers |
| Vim Mode | Full vi-keybinding support in the terminal REPL |
| Voice Mode | (Feature-gated) Voice input/output support |
| IDE Integration | Bidirectional sync with VS Code and JetBrains via LSP |
| Worktrees | Git worktree isolation for parallel agent tasks |
| Cron Triggers | Schedule AI agents to run on intervals |
| Cost Tracking | Per-session token and dollar cost tracking with model pricing |
| Theming | Dark/light terminal themes with design token system |
| Compaction | Automatic context window management for long sessions |
Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β main.tsx β
β (Bootstrap β Init β Query Loop β Cleanup) β
ββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββΌβββββββββββββ
β query.ts β β Core event loop
β + QueryEngine.ts β β State, compaction, API
βββββββββββββ¬βββββββββββββ
β
βββββββββββββββΌβββββββββββββββ
β Claude API (SDK) β
β (streaming, tool_use) β
βββββββββββββββ¬βββββββββββββββ
β
ββββββββββββΌβββββββββββ
β Tool Dispatcher β
β (tools.ts) β
ββββββββββββ¬βββββββββββ
β
βββββββββββββββββΌββββββββββββββββ
β β β
ββββΌβββ ββββββΌββββ βββββββΌβββββ
βBash β βFileEditβ βAgentTool β
βTool β βTool β β(sub-agentβ
βββββββ ββββββββββ β process) β
ββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββ
β Ink (React TUI) β
β components/ + hooks/ + state/ β
β (real-time streaming terminal output) β
βββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββ
β Bridge (Remote Mode) β
β bridge/ β WebSocket β Remote Runner β
βββββββββββββββββββββββββββββββββββββββββββ
Directory Structure
claude-code-src/
β
βββ main.tsx # CLI entry point and main event loop (~4,683 lines)
βββ query.ts # Claude API query + tool execution loop (~1,729 lines)
βββ QueryEngine.ts # Query state, compaction, API orchestration (~1,295 lines)
βββ commands.ts # All 80+ CLI command exports
βββ Tool.ts # Abstract tool interface and types (~792 lines)
βββ tools.ts # Tool registry and instantiation
βββ Task.ts # Task types and ID generation
βββ history.ts # Session history and input cache
βββ context.ts # System/user context assembly
βββ cost-tracker.ts # Token + dollar cost tracking
βββ setup.ts # Pre-init: Node checks, dirs, git, worktrees
β
βββ assistant/ # KAIROS assistant mode (feature-gated)
βββ bootstrap/ # Bootstrap state management
βββ bridge/ # Remote session bridge protocol (33 files)
β βββ bridgeMain.ts # Main bridge orchestration (115KB)
β βββ replBridge.ts # REPL β remote communication (100KB)
β βββ remoteBridgeCore.ts
β βββ createSession.ts
β βββ trustedDevice.ts
β
βββ buddy/ # Companion sprite/animation system
βββ cli/ # Terminal I/O, structured output, transports
βββ commands/ # 80+ individual command implementations
β βββ commit/
β βββ review/
β βββ mcp/
β βββ session/
β βββ autofix-pr/
β βββ bughunter/
β βββ workflows/
β βββ ...
β
βββ components/ # 147 React/Ink terminal UI components
β βββ design-system/
β βββ agents/
β βββ ...
β
βββ constants/ # Product info, OAuth config, XML tags
βββ context/ # React context providers
βββ coordinator/ # Multi-agent coordinator mode
βββ entrypoints/ # cli.tsx, init.ts, mcp.ts, sdk/
βββ hooks/ # 88 custom React hooks
β βββ useCanUseTool.tsx
β βββ useGlobalKeybindings.tsx
β βββ useIDEIntegration.tsx
β βββ ...
β
βββ ink/ # Terminal rendering (Ink wrapper, 51 files)
βββ keybindings/ # Keyboard shortcut configuration
βββ memdir/ # Memory file management (CLAUDE.md)
βββ migrations/ # Database schema migrations
βββ native-ts/ # Native TypeScript runtime utilities
βββ outputStyles/ # Output formatting styles
βββ plugins/ # Plugin system + bundled plugins
βββ query/ # Query planning and optimization
βββ remote/ # Remote session (WebSocket, SessionManager)
βββ schemas/ # Zod schemas for validation
βββ screens/ # Fullscreen UI modes
βββ server/ # Local server for IDE integration
β
βββ services/ # 39 backend service modules
β βββ api/ # Claude API client, retry, rate limits
β βββ mcp/ # MCP server management
β βββ compact/ # Context compaction
β βββ analytics/ # GrowthBook, telemetry
β βββ lsp/ # Language Server Protocol
β βββ oauth/ # OAuth token management
β βββ ...
β
βββ skills/ # Skills system + 19 bundled skills
β βββ bundled/
β βββ update-config/
β βββ simplify/
β βββ loop/
β βββ schedule/
β βββ ...
β
βββ state/ # Global Zustand-like app state
βββ tasks/ # Background task management
β
βββ tools/ # 46+ tool implementations
β βββ BashTool/
β βββ FileEditTool/
β βββ FileReadTool/
β βββ FileWriteTool/
β βββ GlobTool/
β βββ GrepTool/
β βββ WebFetchTool/
β βββ WebSearchTool/
β βββ AgentTool/
β βββ SkillTool/
β βββ MCPTool/
β βββ EnterPlanModeTool/
β βββ AskUserQuestionTool/
β βββ ScheduleCronTool/
β βββ ...
β
βββ types/ # Shared TypeScript types
βββ upstreamproxy/ # Upstream HTTP proxy
βββ utils/ # 332+ utility modules
β βββ bash/
β βββ permissions/
β βββ settings/
β βββ git.ts
β βββ auth.ts
β βββ config.ts
β βββ ...
β
βββ vim/ # Vim keybinding mode
βββ voice/ # Voice input/output (feature-gated)
Tech Stack
| Layer | Technology |
|---|---|
| Language | TypeScript (strict) |
| Runtime | Node.js 18+ / Bun |
| Terminal UI | React + Ink |
| State | Custom Zustand-like store |
| API Client | @anthropic-ai/sdk |
| Schema Validation | Zod |
| CLI Framework | Commander.js |
| HTTP | Axios |
| MCP | @modelcontextprotocol/sdk |
| Analytics | GrowthBook |
| Linting | Biome |
| Colors | Chalk |
| Utilities | lodash-es |
Core Systems Deep Dive
Query Engine
query.ts and QueryEngine.ts are the heart of Claude Code:
- Context Assembly β Gathers git status, file contents, memory (CLAUDE.md), and system prompts
- API Streaming β Sends messages to Claude API and streams
text+tool_useevents - Tool Dispatch β Routes
tool_useblocks to the appropriate tool handler - Result Collection β Sends tool results back to Claude for continued reasoning
- Compaction β Automatically trims the oldest messages when the context window fills
User Input
β
Context Assembly (git, files, memory, system prompt)
β
Claude API Request (streaming)
β
[text block] β render to terminal
[tool_use block] β dispatch to tool β execute β collect result β send back
β
Loop until Claude stops calling tools
β
Final response rendered
Tool System
Every capability Claude can invoke is a Tool:
interface Tool {
name: string
description: string
inputSchema: ZodSchema
execute(input, context): AsyncIterable<ToolResult>
canUseTool(input, context): PermissionResult
}
Tools are registered in tools.ts and dispatched by QueryEngine. Key tools:
| Tool | What it does |
|---|---|
BashTool | Executes shell commands (with user confirmation) |
FileEditTool | Applies precise string-replacement edits to files |
FileReadTool | Reads files with line-number offsets and limits |
FileWriteTool | Creates or overwrites files |
GlobTool | Finds files by glob pattern, sorted by mtime |
GrepTool | Ripgrep-powered content search with regex |
WebFetchTool | Fetches and extracts text from web pages |
WebSearchTool | Performs web searches |
AgentTool | Spawns isolated sub-agent processes |
SkillTool | Executes user-defined skill scripts |
MCPTool | Invokes tools from MCP servers |
EnterPlanModeTool | Switches to plan-review mode |
AskUserQuestionTool | Prompts the user for input during a task |
ScheduleCronTool | Creates recurring cron-based agent triggers |
LSPTool | Queries language servers for completions/diagnostics |
Bridge Protocol
The bridge system (bridge/) enables Claude Code to run in remote or sandboxed environments:
Local CLI Remote Runner
β β
βββ createSession() βββ REST API ββββΊβ
β β
βββ replBridge.ts βββ WebSocket βββββΊβ
β βββ streaming results ββββββ€
β β
βββ trustedDevice.ts (JWT auth) β
βββ bridgeMain.ts (orchestration) β
Key files:
bridgeMain.ts(~115KB) β Full bridge orchestrationreplBridge.ts(~100KB) β REPL message protocol over bridgecreateSession.tsβ Session provisioning via APItrustedDevice.tsβ JWT-based device trust
Skills & Plugins
Skills are user-defined slash commands:
~/.claude/skills/my-skill.js β /my-skill
Claude Code dynamically discovers .js files in the skills directory, wraps them as SkillTool instances, and exposes them as /command-name in the REPL.
19+ bundled skills include:
update-configβ Modifysettings.jsonwith hookssimplifyβ Review and refactor changed codeloopβ Run a prompt/command on a recurring intervalscheduleβ Create scheduled remote agent triggerscommitβ Smart git commit with co-author attributionclaude-apiβ Build apps with the Anthropic SDKreview-prβ AI-powered pull request review
MCP Integration
Claude Code has first-class support for Model Context Protocol:
- Server Discovery: Loads MCP servers from official registry +
~/.claude/settings.json - Dynamic Tools: Generates
Toolobjects from MCP server capabilities at runtime - Resources: Lazily fetches MCP resources on demand
- Seamless: MCP tools appear alongside native tools in Claude's tool list
Configure MCP servers:
{
"mcpServers": {
"my-server": {
"command": "npx",
"args": ["-y", "@my-org/mcp-server"]
}
}
}
Permission System
Every potentially dangerous operation passes through a permission gate:
Tool.canUseTool()
β
Permission mode check (interactive / auto / bypass)
β
[interactive] β show confirmation dialog to user
[auto] β allow safe tools, confirm destructive ones
[bypass] β allow all (explicit opt-in)
β
Denied operations logged for analytics
Modes:
- Interactive (default) β Prompts for confirmation on destructive operations
- Auto (
--auto) β Allows most operations, still prompts for very dangerous ones - Bypass (
--dangerously-skip-permissions) β No prompts (use with caution)
State Management
Global state uses a Zustand-like custom store (state/):
// Read state
const value = useAppState(s => s.someField)
// Update state
setAppState(s => ({ ...s, someField: newValue }))
// React to changes
onChangeAppState('someField', (newVal, prevVal) => { ... })
The AppStateProvider wraps the entire React/Ink tree. State mutations are synchronous and immutable.
Feature Flags
Several features are gated by Bun's dead-code-elimination (DCE) via feature() calls:
| Flag | Feature |
|---|---|
KAIROS | KAIROS assistant mode |
VOICE_MODE | Voice input/output |
BRIDGE_MODE | Remote bridge support |
DAEMON | Daemon/background mode |
COORDINATOR_MODE | Multi-agent coordinator |
PROACTIVE | Proactive suggestions |
MONITOR_TOOL | Task monitoring tool |
AGENT_TRIGGERS | Cron-based agent scheduling |
WORKFLOW_SCRIPTS | Workflow automation scripts |
REACTIVE_COMPACT | Reactive context compaction |
CONTEXT_COLLAPSE | Context window optimization |
EXPERIMENTAL_SKILL_SEARCH | Fuzzy skill search |
Disclaimers
IMPORTANT β Please read before using, forking, or distributing this repository.
1. Intellectual Property
This repository contains source code that is the intellectual property of Anthropic, PBC. Claude Code is a commercial product actively developed and maintained by Anthropic. The code in this repository was obtained through legitimate means (client-side distribution) but may be subject to Anthropic's Terms of Service and proprietary licensing.
This is not an officially sanctioned open-source release by Anthropic.
2. No License Grant
The presence of this code on GitHub does not constitute an open-source license. No permission is granted to:
- Use this code in production systems
- Redistribute or sublicense this code
- Build commercial products based on this code
- Reverse-engineer Anthropic's systems using this code
If you wish to use Claude Code, please use the official distribution: npm install -g @anthropic-ai/claude-code
3. No Warranty
This code is provided as-is for educational and research purposes only. There is no warranty, express or implied. The author(s) of this repository take no responsibility for any damage, data loss, security vulnerabilities, or legal liability arising from use of this code.
4. Security
Do not use API keys, tokens, or credentials found in or derived from this repository. Anthropic's internal endpoints, authentication mechanisms, and session tokens visible in this code are proprietary. Attempting to access Anthropic's infrastructure using this code without authorization may violate the Computer Fraud and Abuse Act (CFAA) and equivalent laws.
5. Accuracy
This is a snapshot of the source at a specific point in time. It may be:
- Out of date compared to the production version
- Missing compiled assets, native modules, or build artifacts required to run
- Incomplete in ways that are not immediately obvious
6. Takedown
If you represent Anthropic and wish this repository to be removed, please open an issue or contact the repository owner directly. Takedown requests will be honored immediately.
Contributing
Since this is an unofficial mirror, pull requests are not accepted for feature changes.
However, contributions are welcome for:
- Documentation improvements β Better explanations, diagrams, annotations
- Research notes β Analysis of architectural patterns, performance characteristics
- Bug documentation β Identifying and documenting issues (not fixes)
To contribute documentation:
- Fork the repository
- Create a branch:
git checkout -b docs/my-improvement - Make your changes
- Open a pull request with a clear description
Resources
- Claude Code Official Docs
- Claude Code on npm
- Anthropic Website
- Model Context Protocol
- Anthropic API Docs
Star this repo if you found it useful for learning about AI-native CLI architecture.
Built with Claude Code Β· Powered by Anthropic
