This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Decompiled TypeScript source of Claude Code v2.1.88, extracted from the npm package @anthropic-ai/claude-code. The published package ships a single bundled cli.js (~12MB); src/ contains the unbundled source (~1,884 files). This repo is for research/study only — it is not a buildable product repo in the traditional sense.
npm install # Install dependencies (esbuild, typescript)
npm run build # Best-effort build: prepare-src + esbuild bundle → dist/cli.js
npm run check # TypeScript type-check (no emit)
npm run prepare-src # Just the source transformation step
node dist/cli.js # Run the built CLIThe build is best-effort — it cannot fully replicate Bun's compile-time intrinsics (feature(), MACRO, bun:bundle). 108 feature-gated internal modules are missing and get stubbed out. The build script transforms feature('X') → false and MACRO.VERSION → '2.1.88' before bundling with esbuild.
There are no tests in this repository.
src/entrypoints/cli.tsx → fast-path version/help checks → src/main.tsx → full initialization (system prompts, commands, tools, MCP config). Startup is optimized with profiling checkpoints and parallel prefetching.
QueryEngine.ts manages the per-conversation multi-turn loop via submitMessage(). The query() generator in query.ts orchestrates the actual LLM interaction: building messages, executing tools, managing context compaction, token budgets, and streaming.
Tool.ts defines the tool interface. tools.ts is the registry that conditionally loads 45+ tools (Bash, FileEdit, FileRead, Glob, Grep, Agent, Skill, Task, Team, MCP, WebSearch, LSP, etc.) with feature-gate filtering and permission checks. Each tool lives in its own directory under tools/ (e.g., tools/BashTool/).
commands.ts registers 100+ user-invocable commands. Skills (skills/) are prompt-based commands with lazy-loaded file support; bundled skills are registered via registerBundledSkill() and user-defined skills are discovered from .claude/skills/.
Key service directories under services/:
api/— Claude API communication and bootstrap dataanalytics/— Event logging, GrowthBook feature flags, telemetrymcp/— Model Context Protocol client/server registrycompact/— Auto-compaction and message summarizationtools/— Streaming tool executor and orchestrationplugins/— Plugin loading and command extractionpolicyLimits/— Rate limiting and quota enforcement
state/AppState.tsx wraps React context with a Zustand-based store (AppStateStore.ts). Holds permission contexts, tool settings, file caches, notifications, and UI state. The CLI uses Ink (React-based terminal UI).
coordinator/coordinatorMode.ts enables multi-agent orchestration, gating whether spawned agents get full or restricted tool access. Feature-gated via COORDINATOR_MODE.
- Feature gates:
feature('FLAG_NAME')frombun:bundle— resolved at Bun compile time. In this repo, all are stubbed tofalse, so feature-gated code paths are dead code. - MACRO constants:
MACRO.VERSION,MACRO.BUILD_ID, etc. — Bun compile-time defines, replaced byscripts/build.mjs. - Stubs:
stubs/bun-bundle.tsprovides thefeature()stub;stubs/macros.tsprovides MACRO constants;vendor/contains native module stubs (e.g.,bun:ffi). - Path aliases:
bun:bundle→stubs/bun-bundle.ts,src/*→src/*(configured intsconfig.json).