Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

2 Commits

Repository files navigation

Claude Code Source - Buildable Research Fork

A buildable, modifiable, and runnable version of the Claude Code source.

Based on the Claude Code source snapshot publicly exposed on 2026-03-31 via an npm source map leak. The original snapshot contained only raw TypeScript source with no build configuration — it could not be compiled or run. This fork reconstructs the full build system and fixes all missing components to make it functional.


What Changed vs. the Original Snapshot

The original snapshot shipped no package.json, no tsconfig.json, no lockfile, and no build scripts. Over 100 internal/feature-gated modules were also missing from the source map.

Build System (Reconstructed)

FilePurpose
package.json60+ npm dependencies reverse-engineered from ~1,900 source files
tsconfig.jsonTypeScript config (ESNext + JSX + Bun bundler resolution)
bunfig.tomlBun runtime configuration
.gitignoreExcludes node_modules/, dist/, lockfiles

Stub Modules (Created)

The original source imports many Anthropic-internal packages and feature-gated modules that were not included in the leak. Minimal stubs were created so the build completes:

CategoryCountExamples
Anthropic internal packages (@ant/*)4computer-use-mcp, computer-use-swift, claude-for-chrome-mcp
Native addons3color-diff-napi, audio-capture-napi, modifiers-napi
Cloud provider SDKs6Bedrock/Foundry/Vertex SDK, AWS STS, Azure Identity
OpenTelemetry exporters10OTLP gRPC/HTTP/Proto exporters
Other optional packages2sharp, turndown
Feature-gated source modules~90Tools, commands, services, components excluded from the source map

Source Fixes

FileChange
src/main.tsxRuntime MACRO constant injection (compile-time define in production)
src/main.tsxFixed Commander.js -d2e short flag incompatibility
src/bootstrap/state.tsAdded missing isReplBridgeActive() export
src/types/connectorText.tsAdded isConnectorTextBlock function stub
src/tools/WorkflowTool/constants.tsAdded WORKFLOW_TOOL_NAME export
node_modules/bundle/Runtime polyfill for bun:bundle feature flag system

Quick Start

Prerequisites

  • Bun >= 1.3.x
  • Valid Anthropic authentication (OAuth via claude login or ANTHROPIC_API_KEY)

Install & Build

git clone https://github.com/beita6969/claude-code.git
cd claude-code
# Install dependencies
bun install
# Build (produces dist/main.js, ~20MB)
bun build src/main.tsx --outdir=dist --target=bun

Run

# Headless print mode (no TTY needed)
bun src/main.tsx -p "your prompt here" --output-format text
# JSON output
bun src/main.tsx -p "your prompt here" --output-format json
# Interactive REPL mode (needs TTY)
bun src/main.tsx

Note: If ANTHROPIC_API_KEY is set in your environment, it must be valid. To use OAuth instead, unset it:

unset ANTHROPIC_API_KEY

Architecture Overview

src/
├── main.tsx # CLI entrypoint (Commander.js + React/Ink)
├── QueryEngine.ts # Core LLM API engine
├── query.ts # Agentic loop (async generator)
├── Tool.ts # Tool type definitions
├── tools.ts # Tool registry
├── commands.ts # Command registry
├── context.ts # System prompt context
│
├── tools/ # 40+ tool implementations
│ ├── AgentTool/ # Sub-agent spawning & coordination
│ ├── BashTool/ # Shell command execution
│ ├── FileReadTool/ # File reading
│ ├── FileEditTool/ # File editing
│ ├── GrepTool/ # ripgrep-based search
│ ├── MCPTool/ # MCP server tool invocation
│ ├── SkillTool/ # Skill execution
│ └── ...
│
├── services/ # External integrations
│ ├── api/ # Anthropic API client
│ ├── mcp/ # MCP server management
│ └── ...
│
├── memdir/ # Persistent memory system
├── skills/ # Skill system (bundled + user)
├── components/ # React/Ink terminal UI
├── hooks/ # React hooks
├── coordinator/ # Multi-agent orchestration
└── stubs/ # Stub packages for missing internals

Key Systems

SystemFilesDescription
Agentic Loopquery.ts, QueryEngine.tswhile(true) async generator: query -> tool calls -> results -> loop
Memorymemdir/4-type file-based memory (user/feedback/project/reference) with MEMORY.md index
MCPservices/mcp/Model Context Protocol server management (stdio/http/sse/ws)
Skillsskills/, tools/SkillTool/Reusable workflow templates (SKILL.md format)
Agentstools/AgentTool/Custom agent types via .claude/agents/*.md
System Promptconstants/prompts.tsLayered prompt: static -> dynamic -> memory -> agent

Extension Points (No Source Modification Needed)

MechanismLocationFormat
Custom Skills.claude/skills/name/SKILL.mdYAML frontmatter + Markdown
Custom Agents.claude/agents/name.mdYAML frontmatter + Markdown
MCP Servers.mcp.jsonJSON config
Hooks~/.claude/settings.jsonJSON event-action mappings

Feature Flags

The bun:bundlefeature() function controls feature gating. In this build, all features default to disabled. To enable features, edit node_modules/bundle/index.js:

constENABLED_FEATURES=newSet([// Uncomment to enable:// 'KAIROS', // Assistant mode// 'PROACTIVE', // Proactive mode// 'BRIDGE_MODE', // IDE bridge// 'VOICE_MODE', // Voice input// 'COORDINATOR_MODE', // Multi-agent coordinator// 'EXTRACT_MEMORIES', // Background memory extraction// 'TEAMMEM', // Team memory])

Tech Stack

LayerTechnology
RuntimeBun
LanguageTypeScript (strict)
Terminal UIReact + Ink
CLICommander.js
ValidationZod v4
Searchripgrep
ProtocolsMCP SDK, LSP
APIAnthropic SDK
TelemetryOpenTelemetry

Scale

  • ~1,900 source files
  • 512,000+ lines of TypeScript
  • 40+ tools, 100+ commands, 140+ UI components
  • 20MB compiled bundle

Disclaimer

  • This repository is for educational and research purposes only.
  • The original Claude Code source is the property of Anthropic.
  • This repository is not affiliated with, endorsed by, or maintained by Anthropic.
  • Original source exposure: 2026-03-31 via npm source map leak.

About

Claude Code Source - Buildable Research Fork. Reverse-engineered build system, runnable with Bun.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages