Skip to content

Rumpick/collection-claude-code-source-code

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

59 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

A collection of the newest Claude Code open source

Source archive of Claude Code and a clean-room Python rewrite research repository

πŸ”₯πŸ”₯πŸ”₯ News (Pacific Time)


Content


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

1. original-source-code

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.


2. claude-code-source-code

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.

Overall Architecture

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

Core Execution Flow

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

Tech Stack

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)

Main Module Descriptions

Tool System (40+ tools)

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

Slash Commands (~87)

/commit /commit-push-pr /review /resume /session /memory /config /skills /help /voice /desktop /mcp /permissions /theme /vim /copy and more

Permission System

  • 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

Context Management

  • Automatic compression strategies (autoCompact): reactive compression, micro-compression, trimmed compression
  • Context collapsing (CONTEXT_COLLAPSE)
  • Token counting and estimation
  • Session transcript persistence

Analysis Documents (docs/)

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

3. claw-code

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.

Overall Architecture

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

Core Classes

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

CLI Commands

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

Design Features

  • 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.py tracks gaps from the original implementation
  • Lightweight architecture: core framework implemented in 109 files, suitable for learning and extension

4. nano-claude-code

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.

Features

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

Supported Models

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

Project Structure

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-all

Memory β€” 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

Comparison of the Projects

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

License and Disclaimer

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.

About

πŸ”₯ A collection of the newest Claude Code open source

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 99.5%
  • Other 0.5%