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.