Source archive of Claude Code and different versions of the clean-room Python rewrite research repository
- 12:20 PM Β· Apr 02, 2026: Nano Claude Code v3.0: Multi-agent packages, memory package, skill package with built-in skills, argument substitution, fork/inline execution, AI memory search, git worktree isolation, agent type definitions (~5000 Lines)
- 7:40 AM Β· Apr 02, 2026: Nano Claude Code v2.0: A Minimal Python Reimplementation (~3400 Lines), support open and closed source models, skill and memory
- 8:36 AM Β· Apr 01, 2026: Nano Claude Code v1.0: A Minimal Python Reimplementation (~1300 Lines)
- 0:20 AM Β· Apr 01, 2026: Analysis of Claude Code source code (Video: In Chinese)
- 19:45 PM Β· Mar 31, 2026: Claude Code Research Report (In Chinese)
- 17:13 PM Β· Mar 31, 2026: Architecture Analysis of Claude Code (In Chinese)
- 16:43 PM Β· Mar 31, 2026: An Overview of Claude Code Features (In Chinese)
- 15:00 PM Β· Mar 31, 2026: Hacker News Community Discussion about Claude Code Leak
- 11:48 AM Β· Mar 31, 2026: How Anthropic Built 7 Layers of Memory and a Dreaming System for Claude Code
- 9:50 AM Β· Mar 31, 2026: Claude code memory analysis
- 9:48 AM Β· Mar 31, 2026: Claude Code's source code appears to have leaked: here's what we know
- 9:04 AM Β· Mar 31, 2026: Deconstructing the Claude Code Architecture (In Chinese)
- 7:07 AM Β· Mar 31, 2026: A Walkthrough of Claude Code's Source Code (In Chinese)
- 5:41 AM Β· Mar 31, 2026: Why Claude Code Outperforms Other Tools: An Analysis
- 5:03 AM Β· Mar 31, 2026: Anthropic's AI Coding Tool Leaks Its Own Source Code
- 3:28 AM Β· Mar 31, 2026: Claude Code Source Code Unveiled: Prompts, Self-Healing Mechanisms, and Multi-Agent Architecture (In Chinese)
- 3:02 AM Β· Mar 31, 2026: Community Reaction to the Claude Code Source Exposure
- 2:57 AM Β· Mar 31, 2026: The code behind Claude Code
- 1:23 AM Β· Mar 31, 2026: A Viral Post on the Claude Code Source Leak
- 1. original-source-code
- 2. claude-code-source-code
- 3. claw-code
- 4. nano-claude-code
- Comparison of the Projects
- License and Disclaimer
This repository contains subprojects that study Claude Code (Anthropicβs official CLI tool) from multiple angles:
| Subproject | Language | Nature | File Count |
|---|---|---|---|
| original-source-code | TypeScript | Raw leaked source archive | 1,884 files |
| claude-code-source-code | TypeScript | Decompiled source archive (v2.1.88) + docs | 1,940 files |
| claw-code | Python | Clean-room architectural rewrite | 109 files |
| nano-claude-code | Python | Minimal multi-provider reimplementation | ~30 files |
The raw leaked TypeScript source of Claude Code, preserved as-is from the original exposure on March 31, 2026. Contains 1,884 TypeScript/TSX files (packaged as src.zip) spanning the full src/ directory tree β the same files that triggered community discussion and downstream research.
original-source-code/
βββ src/ # Full TypeScript source tree (1,884 .ts/.tsx files)
β βββ main.tsx # CLI entry point
β βββ query.ts # Core agent loop
β βββ commands.ts # Slash command definitions
β βββ tools.ts # Tool registration
β βββ ... # All other source directories (same layout as claude-code-source-code/src)
βββ src.zip # Compressed archive (~9.5 MB)
βββ readme.md
This directory serves as the unmodified reference snapshot. No annotations, docs, or build tooling have been added β use claude-code-source-code for the researched and annotated version.
A decompiled/unpacked source archive of Claude Code v2.1.88, reconstructed from the npm package @anthropic-ai/claude-code@2.1.88, containing approximately 163,318 lines of TypeScript code.
claude-code-source-code/
βββ src/
β βββ main.tsx # CLI entry and REPL bootstrap (4,683 lines)
β βββ query.ts # Core main agent loop (largest single file, 785KB)
β βββ QueryEngine.ts # SDK/Headless query lifecycle engine
β βββ Tool.ts # Tool interface definitions + buildTool factory
β βββ commands.ts # Slash command definitions (~25K lines)
β βββ tools.ts # Tool registration and presets
β βββ context.ts # User input context handling
β βββ history.ts # Session history management
β βββ cost-tracker.ts # API cost tracking
β βββ setup.ts # First-run initialization
β β
β βββ cli/ # CLI infrastructure (stdio, structured transports)
β βββ commands/ # ~87 slash command implementations
β βββ components/ # React/Ink terminal UI (33 subdirectories)
β βββ tools/ # 40+ tool implementations (44 subdirectories)
β βββ services/ # Business logic layer (22 subdirectories)
β βββ utils/ # Utility function library
β βββ state/ # Application state management
β βββ types/ # TypeScript type definitions
β βββ hooks/ # React Hooks
β βββ bridge/ # Claude Desktop remote bridge
β βββ remote/ # Remote mode
β βββ coordinator/ # Multi-agent coordination
β βββ tasks/ # Task management
β βββ assistant/ # KAIROS assistant mode
β βββ memdir/ # Long-term memory management
β βββ plugins/ # Plugin system
β βββ voice/ # Voice mode
β βββ vim/ # Vim mode
β
βββ docs/ # In-depth analysis docs (bilingual: Chinese/English)
β βββ en/ # English analysis
β βββ zh/ # Chinese analysis
βββ vendor/ # Third-party dependencies
βββ stubs/ # Module stubs
βββ types/ # Global type definitions
βββ utils/ # Top-level utility functions
βββ scripts/ # Build scripts
βββ package.json
User Input
β
processUserInput() # Parse /slash commands
β
query() # Main agent loop (query.ts)
βββ fetchSystemPromptParts() # Assemble system prompt
βββ StreamingToolExecutor # Parallel tool execution
βββ autoCompact() # Automatic context compression
βββ runTools() # Tool orchestration and scheduling
β
yield SDKMessage # Stream results back to the consumer
| Component | Technology |
|---|---|
| Language | TypeScript 6.0+ |
| Runtime | Bun (compiled into Node.js >= 18 bundle) |
| Claude API | Anthropic SDK |
| Terminal UI | React + Ink |
| Code Bundling | esbuild |
| Data Validation | Zod |
| Tool Protocol | MCP (Model Context Protocol) |
| Category | Tools |
|---|---|
| File Operations | FileReadTool, FileEditTool, FileWriteTool |
| Code Search | GlobTool, GrepTool |
| System Execution | BashTool |
| Web Access | WebFetchTool, WebSearchTool |
| Task Management | TaskCreateTool, TaskUpdateTool, TaskGetTool, TaskListTool |
| Sub-agents | AgentTool |
| Code Environments | NotebookEditTool, REPLTool, LSPTool |
| Git Workflow | EnterWorktreeTool, ExitWorktreeTool |
| Configuration & Permissions | ConfigTool, AskUserQuestionTool |
| Memory & Planning | TodoWriteTool, EnterPlanModeTool, ExitPlanModeTool |
| Automation | ScheduleCronTool, RemoteTriggerTool, SleepTool |
| MCP Integration | MCPTool |
/commit /commit-push-pr /review /resume /session /memory /config /skills /help /voice /desktop /mcp /permissions /theme /vim /copy and more
- Three modes:
default(ask user) /bypass(auto-allow) /strict(auto-deny) - Tool-level fine-grained control
- ML-based automated permission inference classifier
- Persistent storage of permission rules
- Automatic compression strategies (
autoCompact): reactive compression, micro-compression, trimmed compression - Context collapsing (
CONTEXT_COLLAPSE) - Token counting and estimation
- Session transcript persistence
| Document | Content |
|---|---|
| 01 - Telemetry and Privacy | Dual-layer analysis pipeline (Anthropic + Datadog), with no opt-out switch |
| 02 - Hidden Features and Model Codenames | Internal codenames such as Capybara, Tengu, Fennec, Numbat |
| 03 - Undercover Mode | Anthropic employees automatically entering undercover mode in public repositories |
| 04 - Remote Control and Emergency Switches | Hourly polling, 6+ killswitches, dangerous-change popups |
| 05 - Future Roadmap | KAIROS autonomous agent, voice mode, 17 unreleased tools |
A clean-room Python rewrite of Claude Code (without including original source copies), focused on architectural mirroring and research. Built by @instructkr (Sigrid Jin), and became one of the fastest GitHub repositories in the world to reach 30K stars.
claw-code/
βββ src/
β βββ __init__.py # Package export interface
β βββ main.py # CLI entry (~200 lines)
β βββ query_engine.py # Core query engine
β βββ runtime.py # Runtime session management
β βββ models.py # Shared data classes
β βββ commands.py # Command metadata and execution framework
β βββ tools.py # Tool metadata and execution framework
β βββ permissions.py # Permission context management
β βββ context.py # Ported context layer
β βββ setup.py # Workspace initialization
β βββ session_store.py # Session persistence
β βββ transcript.py # Session transcript storage
β βββ port_manifest.py # Workspace manifest generation
β βββ execution_registry.py # Execution registry
β βββ history.py # History logs
β βββ parity_audit.py # Parity audit against TypeScript source
β βββ remote_runtime.py # Remote mode simulation
β βββ bootstrap_graph.py # Bootstrap graph generation
β βββ command_graph.py # Command graph partitioning
β βββ tool_pool.py # Tool pool assembly
β β
β βββ reference_data/ # JSON snapshot data (drives command/tool metadata)
β β βββ commands_snapshot.json
β β βββ tools_snapshot.json
β β
β βββ commands/ # Command implementation subdirectory
β βββ tools/ # Tool implementation subdirectory
β βββ services/ # Business logic services
β βββ components/ # Terminal UI components (Python version)
β βββ state/ # State management
β βββ types/ # Type definitions
β βββ utils/ # Utility functions
β βββ remote/ # Remote mode
β βββ bridge/ # Bridge modules
β βββ hooks/ # Hook system
β βββ memdir/ # Memory management
β βββ vim/ # Vim mode
β βββ voice/ # Voice mode
β βββ plugins/ # Plugin system
β
βββ tests/ # Validation tests
| Class / Module | Responsibility |
|---|---|
QueryEnginePort |
Query engine handling message submission, streaming output, and session compression |
PortRuntime |
Runtime manager responsible for routing, session startup, and turn-loop execution |
PortManifest |
Workspace manifest that generates Markdown overviews |
ToolPermissionContext |
Tool permission context (allow / deny / ask) |
WorkspaceSetup |
Environment detection and initialization reporting |
TranscriptStore |
Session transcript storage with append, compaction, and replay support |
python3 -m src.main [COMMAND]
# Overview
summary # Markdown workspace overview
manifest # Print manifest
subsystems # List Python modules
# Routing and indexing
commands # List all commands
tools # List all tools
route [PROMPT] # Route prompt to corresponding command/tool
# Execution
bootstrap [PROMPT] # Start runtime session
turn-loop [PROMPT] # Run turn loop (--max-turns)
exec-command NAME # Execute command
exec-tool NAME # Execute tool
# Session management
flush-transcript # Persist session transcript
load-session ID # Load saved session
# Remote mode
remote-mode TARGET # Simulate remote control
ssh-mode TARGET # Simulate SSH branch
teleport-mode TARGET # Simulate Teleport branch
# Audit and config
parity-audit # Compare consistency with TypeScript source
setup-report # Startup configuration report
bootstrap-graph # Bootstrap phase graph
command-graph # Command graph partition view
tool-pool # Tool pool assembly view- Snapshot-driven: command/tool metadata is loaded through JSON snapshots without requiring full logical implementations
- Clean-room rewrite: does not include original TypeScript code; independently implemented
- Parity audit: built-in
parity_audit.pytracks gaps from the original implementation - Lightweight architecture: core framework implemented in 109 files, suitable for learning and extension
A minimal, fully-runnable Python reimplementation of Claude Code (~5,000 lines). Unlike claw-code (which focuses on architectural mapping), nano-claude-code is a real coding assistant that can be used immediately. It supports 20+ closed-source models and local open-source models, and has grown from a ~900-line prototype to a feature-rich v3.0 with multi-agent orchestration, persistent memory, and a skill system.
| Feature | Details |
|---|---|
| Multi-provider | Anthropic Β· OpenAI Β· Gemini Β· Kimi Β· Qwen Β· Zhipu Β· DeepSeek Β· Ollama Β· LM Studio Β· Custom endpoint |
| Interactive REPL | readline history, Tab-complete slash commands |
| Agent loop | Streaming API + automatic tool-use loop |
| 18 built-in tools | Read Β· Write Β· Edit Β· Bash Β· Glob Β· Grep Β· WebFetch Β· WebSearch Β· MemorySave Β· MemoryDelete Β· MemorySearch Β· MemoryList Β· Agent Β· SendMessage Β· CheckAgentResult Β· ListAgentTasks Β· ListAgentTypes Β· Skill Β· SkillList |
| Diff view | Git-style red/green diff display for Edit and Write |
| Context compression | Auto-compact long conversations to stay within model limits |
| Persistent memory | Dual-scope memory (user + project) with 4 types, AI search, staleness warnings |
| Multi-agent | Spawn typed sub-agents (coder/reviewer/researcher/β¦), git worktree isolation, background mode |
| Skills | Built-in /commit Β· /review + custom markdown skills with argument substitution and fork/inline execution |
| Plugin tools | Register custom tools via tool_registry.py |
| Permission system | auto / accept-all / manual modes |
| 17 slash commands | /model Β· /config Β· /save Β· /cost Β· /memory Β· /skills Β· /agents Β· β¦ |
| Context injection | Auto-loads CLAUDE.md, git status, cwd, persistent memory |
| Session persistence | Save / load conversations to ~/.nano_claude/sessions/ |
| Extended Thinking | Toggle on/off (Claude models only) |
| Cost tracking | Token usage + estimated USD cost |
| Non-interactive mode | --print flag for scripting / CI |
Closed-source (API): Claude (Anthropic), GPT / o-series (OpenAI), Gemini (Google), Kimi (Moonshot AI), Qwen (Alibaba DashScope), GLM (Zhipu), DeepSeek
Open-source (local via Ollama): llama3.3/3.2, qwen2.5-coder, deepseek-r1, phi4, mistral, mixtral, gemma3, codellama, and any model on ollama list
Self-hosted: vLLM, LM Studio, or any OpenAI-compatible endpoint via CUSTOM_BASE_URL
nano-claude-code/
βββ nano_claude.py # Entry point: REPL + slash commands + rendering (~748 lines)
βββ agent.py # Agent loop: message format + tool dispatch (~174 lines)
βββ providers.py # Multi-provider adapters + message conversion (~507 lines)
βββ tools.py # Tool dispatch + auto-registration of all packages (~467 lines)
βββ tool_registry.py # Central tool registry + plugin entry point (~98 lines)
βββ context.py # System prompt builder: CLAUDE.md + git + memory (~135 lines)
βββ compaction.py # Context compression (auto-compact) (~196 lines)
βββ config.py # Config load/save/defaults (~72 lines)
βββ memory.py # Backward-compat shim β memory/
βββ skills.py # Backward-compat shim β skill/
βββ subagent.py # Backward-compat shim β multi_agent/
β
βββ memory/ # Persistent memory package
β βββ store.py # Save/load/delete/search memory entries
β βββ scan.py # Index scanning, age/freshness helpers
β βββ context.py # System-prompt injection + AI-ranked search
β βββ types.py # MEMORY_TYPES definitions
β βββ tools.py # MemorySave Β· MemoryDelete Β· MemorySearch Β· MemoryList
β
βββ skill/ # Skill system package
β βββ loader.py # SkillDef, file parsing, argument substitution
β βββ builtin.py # Built-in skills: /commit, /review
β βββ executor.py # Inline + fork execution modes
β βββ tools.py # Skill Β· SkillList
β
βββ multi_agent/ # Multi-agent orchestration package
β βββ subagent.py # AgentDefinition, SubAgentTask, SubAgentManager, worktree helpers
β βββ tools.py # Agent Β· SendMessage Β· CheckAgentResult Β· ListAgentTasks Β· ListAgentTypes
β
βββ tests/ # 101 tests (monkeypatched, no real ~/.nano_claude touched)
βββ docs/ # Docs and demo assets
βββ requirements.txt
Quick start:
pip install anthropic openai httpx rich
export ANTHROPIC_API_KEY=sk-ant-...
python nano_claude.py
# Switch provider at startup
python nano_claude.py --model gpt-4o
python nano_claude.py --model ollama/qwen2.5-coder
# Non-interactive / CI
python nano_claude.py --print "Write a Python fibonacci function" --accept-allMemory β persistent across sessions, dual-scope (user ~/.nano_claude/memory/ and project .nano_claude/memory/):
/memory # list all memories with staleness info
MemorySave(name="...", type="feedback", content="...", scope="user")
MemorySearch(query="...", use_ai=True)
Skills β reusable prompt templates, invoke from REPL:
/commit # built-in: review staged changes and create a git commit
/review 123 # built-in: review PR #123
/skills # list all available skills with triggers and hints
Multi-agent β spawn typed sub-agents with optional git worktree isolation:
Agent(prompt="...", subagent_type="coder", isolation="worktree", wait=False)
SendMessage(agent_name="my-agent", message="...")
/agents # show all active and finished sub-agent tasks
| Dimension | original-source-code | claude-code-source-code | claw-code | nano-claude-code |
|---|---|---|---|---|
| Language | TypeScript | TypeScript | Python | Python |
| Code Size | ~163,000 lines | ~163,000 lines + docs | ~5,000 lines | ~5,000 lines |
| Nature | Raw leaked source archive | Decompiled source archive + analysis | Clean-room architectural rewrite | Minimal functional reimplementation |
| Functional Completeness | Complete (100%) | Complete (100%) | Architectural framework (~20%) | Core loop + memory + multi-agent + skills |
| Core Loop | query.ts (785KB) |
query.ts (785KB) |
QueryEnginePort (~200 lines) |
agent.py (~174 lines) |
| Tool System | 40+ fully implemented tools | 40+ fully implemented tools | Snapshot metadata + execution framework | 18 fully implemented tools + plugin registry |
| Memory System | Yes (7-layer, complex) | Yes (7-layer, complex) | No | Yes (dual-scope, 4 types, AI search) |
| Multi-agent | Yes (full coordinator) | Yes (full coordinator) | No | Yes (typed agents, worktree isolation) |
| Skills | Yes (~87 commands) | Yes (~87 commands) | Snapshot metadata only | Yes (built-in + custom markdown skills) |
| Multi-provider | No (Anthropic only) | No (Anthropic only) | No | Yes (10+ providers) |
| Immediately Runnable | No | No | Limited (CLI metadata only) | Yes |
| Main Use Case | Raw reference snapshot | Deep study of full implementation details | Architectural understanding and porting research | Lightweight full-featured coding assistant |
This repository is for academic research and educational purposes only. All subprojects are built from publicly accessible information. Users are responsible for complying with applicable laws, regulations, and service terms.