MCPcopy Index your code
hub / github.com/QuantaAlpha/claude-code

github.com/QuantaAlpha/claude-code @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
11,961 symbols 42,623 edges 2,015 files 1,595 documented · 13%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Claude Code

Anthropic's Official AI Coding Assistant CLI — Source Research Edition

TypeScript Bun Files Lines

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.

Claude Code running: bun install + bun run dev starts successfully

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 install and 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


Quick Start

Prerequisites

  • Bun v1.3.5+ (verify with bun --version; upgrade with bun upgrade)
  • ANTHROPIC_API_KEY environment variable (required for interactive mode)

Installation

# After cloning the repo, run in the project root:
bun install

Launch

# 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

Common Commands

# 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

How It Works

Startup Entry Chain

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

Why is 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')

Shims Explained

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.

Feature Flags (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
}

Key Source Files

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

Table of Contents


Architecture Overview

┌─────────────────────────────────────────────────────────┐
│                      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    │
└─────────────────────────────────────────────────────────────────────┘

Directory Structure

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

Core Concepts

Query Engine

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

Tool System

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

Extension points exported contracts — how you extend this code

Transport (Interface)
(no doc) [6 implementers]
src/cli/transports/Transport.ts
IParsedCommand (Interface)
(no doc) [4 implementers]
src/utils/bash/ParsedCommand.ts
Props (Interface)
(no doc)
src/components/ContextVisualization.tsx
InstallProps (Interface)
(no doc)
src/commands/install.tsx
Diagnostic (Interface)
(no doc)
src/services/diagnosticTracking.ts
IDEPathConverter (Interface)
(no doc) [2 implementers]
src/utils/idePathConversion.ts
TeleportResumeWrapperProps (Interface)
(no doc)
src/components/TeleportResumeWrapper.tsx
CheckExistingSecretStepProps (Interface)
(no doc)
src/commands/install-github-app/CheckExistingSecretStep.tsx

Core symbols most depended-on inside this repo

logForDebugging
called by 2724
src/utils/debug.ts
logEvent
called by 1088
src/services/analytics/index.ts
has
called by 700
src/utils/fileStateCache.ts
get
called by 628
src/utils/secureStorage/types.ts
logError
called by 623
src/utils/log.ts
set
called by 502
src/utils/secureStorage/types.ts
max
called by 437
src/utils/fileStateCache.ts
lazySchema
called by 410
src/utils/lazySchema.ts

Shape

Function 10,574
Method 1,039
Class 262
Interface 85
Enum 1

Languages

TypeScript100%

Modules by API surface

src/bootstrap/state.ts212 symbols
src/utils/sessionStorage.ts156 symbols
src/native-ts/yoga-layout/index.ts144 symbols
src/utils/messages.ts122 symbols
src/utils/Cursor.ts105 symbols
src/utils/bash/bashParser.ts84 symbols
src/utils/attachments.ts74 symbols
src/utils/auth.ts69 symbols
src/utils/hooks.ts67 symbols
src/services/mcp/client.ts67 symbols
src/utils/sandbox/sandbox-adapter.ts59 symbols
src/ink/ink.tsx54 symbols

For agents

$ claude mcp add claude-code \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page