Anthropic's Official AI Coding Assistant CLI — Source Research Edition
Claude Code is a terminal-based AI coding assistant deeply integrated with Claude models. It supports code writing, debugging, refactoring, code review, multi-agent collaboration, and other complex engineering tasks. This repository is a snapshot of the core source code.

After bun install, bun run dev launches Claude Code directly from source into the interactive REPL
✨ Ready-to-use fork by @QuantaAlpha
We've patched this source snapshot into a zero-config, out-of-the-box CLI — just
bun installand go. Fully integrated with the EpochX Agent community platform, so your Claude Code can do more than assist with coding:
- 💰 Automatically pick up bounty tasks from the EpochX marketplace
- 💰 Earn 7×24 while you sleep — your Agent works for you
- 📋 Post any task on EpochX and let other people's Claude Code or OpenClaw agents complete it for you
Don't just use the tool — put your Agent to work.
👉 Drop-in fork: github.com/QuantaAlpha/claude-code 🌐 Learn more: quantaalpha.com · epochx.cc
bun --version; upgrade with bun upgrade)ANTHROPIC_API_KEY environment variable (required for interactive mode)# After cloning the repo, run in the project root:
bun install
# Option 1: Via npm script (recommended)
bun run dev
# Option 2: Run the entry file directly (equivalent)
bun run src/dev-entry.ts
# Option 3: Executable script (root directory)
./claude-dev
# Show version
bun run dev --version
# Show help
bun run dev --help
# Interactive REPL (requires ANTHROPIC_API_KEY)
export ANTHROPIC_API_KEY=your_key_here
bun run dev
# Non-interactive print mode (single conversation then exit)
bun run dev --print "Write a bubble sort for me"
# Run with a specific working directory
bun run dev --add-dir /path/to/project
claude-dev (executable script, root directory)
└── bun run src/dev-entry.ts
└── src/entrypoints/cli.tsx ← actual CLI entry
└── main() ← Commander.js command parsing + routing
├── --version / --help / --print → handled directly
└── interactive mode → launchRepl() → screens/REPL.tsx
dev-entry.ts needed?src/entrypoints/cli.tsx uses the Bun bundler-specific API bun:bundle (for compile-time feature flags / dead code elimination), which cannot be interpreted directly by bun run. dev-entry.ts simulates constants injected at bundle time via globalThis.MACRO, allowing the source code to run without a build step:
// dev-entry.ts does two key things:
// 1. Inject bundle-time constants (replacing values bun build injects at compile time)
globalThis.MACRO = {
VERSION: pkg.version,
BUILD_TIME: '',
PACKAGE_URL: pkg.name,
// ...
}
// 2. After validating all relative imports are resolvable, dynamically import the real entry
await import('./entrypoints/cli.tsx')
Some Anthropic-internal packages are not publicly published and are replaced by stub modules in the stubs/ directory:
| Package | Location | Description |
|---|---|---|
@ant/computer-use-mcp |
stubs/ant-computer-use-mcp |
macOS screen control (screenshot / mouse / keyboard) |
@ant/computer-use-input |
stubs/ant-computer-use-input |
Low-level input device control (Rust/enigo) |
@ant/computer-use-swift |
stubs/ant-computer-use-swift |
macOS Swift native screenshot API |
@ant/claude-for-chrome-mcp |
stubs/ant-claude-for-chrome-mcp |
Chrome browser control MCP service |
color-diff-napi |
stubs/color-diff-napi |
Syntax highlight diff rendering (Native Addon) |
modifiers-napi |
stubs/modifiers-napi |
Keyboard modifier key state detection |
url-handler-napi |
stubs/url-handler-napi |
macOS URL scheme registration |
These shims are empty implementations or return default values and do not affect core AI conversation and code operation capabilities.
bun:bundle compile-time decisions)The production bundle uses bun:bundle's feature() macro to decide whether to include certain code at bundle time. In development mode (launched via dev-entry.ts), all feature() calls return false, meaning all experimental features are disabled by default, keeping only the core functionality paths.
// Example: activate a specific feature only in the production bundle
if (feature('KAIROS')) {
// Advanced assistant mode code — this branch is skipped in dev mode
}
| File | Description |
|---|---|
src/dev-entry.ts |
Development startup entry, injects MACRO constants and validates dependency completeness |
src/entrypoints/cli.tsx |
CLI bootstrap, handles fast paths (--version etc.) and mode routing |
src/main.tsx |
Main application logic: Commander command tree, REPL startup, session initialization |
src/query.ts |
LLM query processing main loop |
src/QueryEngine.ts |
Query engine core, manages API calls and tool orchestration |
┌─────────────────────────────────────────────────────────┐
│ Entry Layer │
│ entrypoints/cli.tsx entrypoints/init.ts setup.ts │
└───────────────────────────┬─────────────────────────────┘
│
┌───────────────────────────▼─────────────────────────────┐
│ Main App Loop (main.tsx) │
│ Command Parsing → Message Handling → UI Mgmt │
└──────────┬──────────────────────────┬────────────────────┘
│ │
┌──────────▼──────────┐ ┌────────────▼────────────────────┐
│ Command System │ │ Query Engine │
│ commands/ (103+) │ │ query.ts + QueryEngine.ts │
│ PromptCommand │ │ ↕ services/api/claude.ts │
│ LocalCommand │ │ (Anthropic SDK) │
└─────────────────────┘ └─────────────┬───────────────────┘
│
┌────────────▼────────────────────┐
│ Tool Execution Layer │
│ tools/ (44+) + toolHooks.ts │
│ PreToolUse → call → PostToolUse│
└─────────────┬───────────────────┘
│
┌───────────────────────────┼───────────────────────┐
│ │ │
┌──────────▼──────┐ ┌─────────────▼──────┐ ┌───────────▼──────┐
│ Permission Layer │ │ State Layer │ │ UI Layer │
│ useCanUseTool │ │ AppState (Zustand) │ │ React + Ink │
│ permissions/ │ │ context/ │ │ components/ │
└─────────────────┘ └────────────────────┘ └──────────────────┘
│
┌──────────▼──────────────────────────────────────────────────────────┐
│ Support Services │
│ MCP Integration | OAuth | LSP | Context Compression | Analytics │
└─────────────────────────────────────────────────────────────────────┘
src/
├── entrypoints/ # Multiple application entry points
│ ├── cli.tsx # CLI main entry, handles --version, --dump-system-prompt, etc.
│ └── init.ts # Initialization: Node version check, Session management, Worktree support
├── main.tsx # Application main loop (4,683 lines)
├── setup.ts # Startup config: permission modes, Tmux integration, logging init
├── query.ts # Query processing main logic (1,729 lines)
├── QueryEngine.ts # Query engine core (1,295 lines)
├── Tool.ts # Tool type definitions and interfaces (792 lines)
├── commands.ts # Command registry (100+ commands)
├── context.ts # Git status and system context management
│
├── tools/ # 44+ tool implementations
│ ├── BashTool/
│ ├── FileEditTool/
│ ├── FileReadTool/
│ ├── FileWriteTool/
│ ├── GlobTool/
│ ├── GrepTool/
│ ├── WebFetchTool/
│ ├── WebSearchTool/
│ ├── MCPTool/
│ ├── AgentTool/
│ ├── SkillTool/
│ ├── TaskCreateTool/
│ ├── EnterPlanModeTool/
│ ├── NotebookEditTool/
│ └── ... (more tools)
│
├── commands/ # 103+ command implementations
│ ├── commit/
│ ├── review/
│ ├── config/
│ ├── mcp/
│ ├── skills/
│ ├── memory/
│ ├── tasks/
│ └── ... (more commands)
│
├── services/ # 38+ services
│ ├── api/ # Anthropic API client (22 sub-modules)
│ │ ├── claude.ts # API calls, streaming, retry logic
│ │ └── errors.ts
│ ├── tools/ # Tool execution orchestration
│ │ ├── toolOrchestration.ts
│ │ ├── toolExecution.ts
│ │ └── StreamingToolExecutor.ts
│ ├── mcp/ # MCP server management (25 sub-modules)
│ ├── compact/ # Automatic context compression
│ ├── analytics/ # Analytics tracking
│ ├── lsp/ # Language Server Protocol
│ ├── oauth/ # OAuth 2.0 authentication
│ └── ...
│
├── state/ # Application state management
│ ├── AppState.tsx # React state definitions
│ ├── AppStateStore.ts # State store
│ └── store.ts # Zustand store implementation
│
├── hooks/ # 87+ React Hooks
│ ├── useCanUseTool.ts # Tool permission checks
│ ├── useTasksV2.ts # Task management
│ ├── useQueueProcessor.ts
│ ├── useVoice.ts # Voice integration
│ └── ...
│
├── components/ # 146+ React components
├── ink/ # Terminal UI rendering layer (50 files)
├── types/ # TypeScript type definitions
│ ├── message.ts
│ ├── command.ts
│ ├── hooks.ts
│ └── permissions.ts
│
├── utils/ # 298+ utility function modules
│ ├── config.ts
│ ├── permissions/
│ ├── model/
│ ├── bash/ # Bash parser (bashParser.ts 4,436 lines)
│ └── ...
│
├── bootstrap/ # Startup state initialization
├── tasks/ # Task system implementation
├── skills/ # Skills system
├── plugins/ # Plugin system
├── bridge/ # Bridge communication (33 files)
├── coordinator/ # Multi-agent coordination
├── memdir/ # Memory directory management
├── migrations/ # Data migrations
├── remote/ # Remote operations
├── schemas/ # Data schemas
├── vim/ # Vim mode support
└── keybindings/ # Keyboard shortcut configuration
The query engine is the heart of the system, responsible for interacting with the Claude API and orchestrating tool calls.
Main entries: src/query.ts + src/QueryEngine.ts
export type QueryEngineConfig = {
cwd: string
tools: Tools
commands: Command[]
mcpClients: MCPServerConnection[]
canUseTool: CanUseToolFn
getAppState: () => AppState
setAppState: (f: (prev: AppState) => AppState) => void
customSystemPrompt?: string
userSpecifiedModel?: string
thinkingConfig?: ThinkingConfig
maxTurns?: number
maxBudgetUsd?: number
}
Execution flow:
User input
↓
Message normalization (normalizeMessagesForAPI)
↓
System prompt preparation (getSystemPrompt)
↓
API call (services/api/claude.ts) — streaming response
↓
Tool call handling (runTools)
├── Concurrency-safe tools → parallel execution
└── Destructive tools → serial execution
↓
Result aggregation → continue conversation or end
Tools are the basic units through which Claude interacts with external systems.
Tool interface definition (src/Tool.ts):
export type Tool<Input, Output, P extends ToolProgressData> = {
name: string
aliases?: string[]
// Core execution method
call(args: z.infer<Input>, context: ToolUseContext, canUseTool: CanUseToolFn): Promise<ToolResult<Output>>
// Concurrency and read-only declarations
isConcurrencySafe(input: z.infer<Input>): boolean
isReadOnly(input: z.infer<Input>): boolean
isDestructive?(input: z.infer<Input>): boolean
// Input validation schema
readonly inputSchema: Input
}
Built-in tool list:
| Category | Tools |
|---|---|
| File operations | FileRe |
$ claude mcp add claude-code \
-- python -m otcore.mcp_server <graph>