A buildable and runnable version of Anthropic's Claude Code CLI, built from an official source snapshot.
Uses a zero-modification Bun.plugin() preload approach to resolve bun:bundle compile-time features and MACRO.* constant injection — no original source files are touched.
- Bun >= 1.3.11
- Anthropic API Key (for actual conversations)
git clone <repo-url> && cd claude-code
bun install# Development mode (runs source directly, zero modification)
bun run dev
# Or use the launcher script
./bin/claude-dev
# Non-interactive mode
ANTHROPIC_API_KEY=sk-ant-xxx bun run dev -- -p "your prompt"
# Interactive REPL
ANTHROPIC_API_KEY=sk-ant-xxx bun run devbun run build # Bundle to dist/ (~24MB, 426 chunks)
bun ./dist/cli.js # Run the bundled outputThe build output is Node.js-compatible — import.meta.require calls are automatically patched with a createRequire fallback.
claude-code/
├── entrypoints/ # Entry points
│ ├── cli.tsx # CLI bootstrap
│ ├── init.ts # Initialization pipeline
│ ├── mcp.ts # MCP Server entry
│ └── sdk/ # SDK type definitions
├── main.tsx # Core CLI logic (Commander.js)
├── tools/ # 48 built-in tools
│ ├── BashTool/ # Shell execution + security analysis
│ ├── FileEditTool/ # File editing
│ ├── AgentTool/ # Sub-agents / Swarm
│ ├── GrepTool/ # Code search
│ └── ...
├── services/ # Service layer
│ ├── api/ # Anthropic API client
│ ├── mcp/ # MCP protocol implementation
│ ├── compact/ # Context compaction
│ └── analytics/ # Telemetry & analytics
├── components/ # React/Ink terminal UI components
├── ink/ # Custom terminal renderer (not npm ink)
├── commands/ # 103 CLI commands
├── utils/ # Utilities (566 files)
├── hooks/ # React hooks
├── constants/ # Configuration constants
├── types/ # TypeScript type declarations
├── native-ts/ # Pure TS ports of native modules
│ ├── yoga-layout/ # Flexbox layout engine
│ ├── color-diff/ # Syntax-highlighted diffs
│ └── file-index/ # Fuzzy file search
├── packages/ # Monorepo workspace packages
│ ├── @ant/ # Internal package stubs
│ └── color-diff-napi/ # NAPI module TS implementation
├── shims/ # Zero-modification build shims
│ ├── preload.ts # Bun.plugin() + MACRO globals
│ └── bun-bundle.ts # feature() stub (returns false)
├── scripts/ # Automation tools
│ ├── create-type-stubs.mjs
│ ├── fix-missing-exports.mjs
│ └── health-check.ts
├── build.ts # Production build script
├── package.json # Dependencies + workspace config
└── tsconfig.json # TypeScript config
The official source depends on Bun bundler's compile-time features and cannot run directly:
| Problem | Scope | Solution |
|---|---|---|
bun:bundle feature() system |
212 files | Bun.plugin() intercept → redirect to shim |
MACRO.* build-time constants |
40+ files | Preload script injects globalThis.MACRO |
src/ path alias |
250 files | tsconfig.json paths mapping |
@ant/* internal packages |
~15 files | Monorepo workspace stubs |
| Missing internal modules | ~20 files | Auto-generated stubs via scripts |
All source files remain untouched. Build shims are injected at runtime via Bun's preload mechanism:
bun --preload ./shims/preload.ts ./entrypoints/cli.tsxshims/preload.ts does two things:
- Registers a
Bun.plugin()that interceptsimport { feature } from 'bun:bundle'and redirects to the shim - Defines
globalThis.MACROwith build-time constants (VERSION, BUILD_TIME, etc.)
shims/bun-bundle.ts exports feature() returning false for all flags — equivalent to an external (non-Anthropic) build. This means all internal feature-gated code paths (KAIROS, BRIDGE_MODE, DAEMON, etc.) are cleanly disabled.
build.ts uses Bun.build() with:
defineto inline MACRO constants at compile time (replacing runtimeglobalThis)- Plugin to intercept
bun:bundle - Code splitting for fast startup
- Post-processing to patch
import.meta.requirefor Node.js compatibility
| Provider | Configuration |
|---|---|
| Anthropic Direct | ANTHROPIC_API_KEY |
| AWS Bedrock | AWS credentials (env vars or ~/.aws/credentials) |
| Google Vertex AI | GCP credentials (gcloud auth or service account) |
| Azure Foundry | Azure credentials |
bun run lint # Biome linting
bun run lint:fix # Auto-fix lint issues
bun run format # Code formatting
bun run health # Health check (code size, lint, build status)
bun run check:unused # Dead code detection (Knip)
bun run stubs:create # Auto-generate missing type stubs from tsc errors
bun run stubs:fix-exports # Fix missing exports in stub files- Custom Ink: The terminal UI (
ink/) is a complete React-to-terminal renderer usingreact-reconciler, not the npminkpackage - Custom Yoga: Layout uses a pure TypeScript flexbox engine (
native-ts/yoga-layout/), not the npmyoga-layoutpackage - Bun Runtime APIs: All
Bun.*API calls (Bun.spawn, Bun.hash, Bun.semver, etc.) are guarded withtypeof Bun !== 'undefined'and have Node.js fallbacks - Feature Flags: 77 compile-time feature flags control dead-code elimination; all return
falsein this build - Security: Multi-layered permission system with dangerous command detection, shell injection prevention, sandbox isolation, and SSRF protection
For educational and research purposes only. Claude Code is a product of Anthropic — all rights belong to Anthropic.