490 lines
32 KiB
Markdown
490 lines
32 KiB
Markdown
|
||
# A collection of the newest Claude Code open source
|
||
|
||
> Source archive of Claude Code and different versions of the clean-room Python rewrite research repository
|
||
|
||
## 🔥🔥🔥 News (Pacific Time)
|
||
- Apr 04, 2026: [Deep-dive analysis docs added (docs/cc_analysis/analysis_20260401): context compression, multi-agent architecture, memory system, hidden features, model-switching, rollback mechanism, effort level, and tracking-data cleanup guide](#5-docscc_analysis)
|
||
- 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)](https://github.com/SafeRL-Lab/nano-claude-code)
|
||
- 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](https://github.com/SafeRL-Lab/nano-claude-code)
|
||
- 8:36 AM · Apr 01, 2026: [Nano Claude Code v1.0: A Minimal Python Reimplementation (~1300 Lines)](https://github.com/SafeRL-Lab/nano-claude-code)
|
||
- 0:20 AM · Apr 01, 2026: [Analysis of Claude Code source code (Video: In Chinese)](https://www.youtube.com/watch?v=xsg6_Gvr2J0&t=10s)
|
||
- 19:45 PM · Mar 31, 2026: [Claude Code Research Report (In Chinese)](https://github.com/chauncygu/collection-claude-code-source-code/blob/main/docs/claude-code-deep-dive-xelatex.pdf)
|
||
- 17:13 PM · Mar 31, 2026: [Architecture Analysis of Claude Code (In Chinese)](https://mp.weixin.qq.com/s?__biz=MzI0ODk2NDIyMQ==&mid=2247502519&idx=1&sn=1072dd7a822a78709bc7cc3bf0e1dcc2&chksm=e8de6705e2bacc854211663aa02903738560f9e858eb6ce72b94c32fdbf67917badfab2d6536&mpshare=1&scene=1&srcid=0401KpkqfaXFBReRof6AwJ74&sharer_shareinfo=30fa54f1602d1d8bb1a65e7008074e08&sharer_shareinfo_first=30fa54f1602d1d8bb1a65e7008074e08#rd)
|
||
- 16:43 PM · Mar 31, 2026: [An Overview of Claude Code Features (In Chinese)](https://mp.weixin.qq.com/s?__biz=MzAxODI5ODMwOA==&mid=2666572944&idx=1&sn=c54e34711e67a2e961acb341f51d2190&chksm=81ca164af949bdfe90a616c8ef8d7e729116a4a12a480cd9d012f42f5b8d7ecd6d05e284db09&mpshare=1&scene=1&srcid=04017JkKs9qrCh4AHcfZq7qL&sharer_shareinfo=95eb268167dd1b3d98271b8b26e7553e&sharer_shareinfo_first=95eb268167dd1b3d98271b8b26e7553e#rd)
|
||
- 15:00 PM · Mar 31, 2026: [Hacker News Community Discussion about Claude Code Leak](https://news.ycombinator.com/item?id=47586778)
|
||
- 11:48 AM · Mar 31, 2026: [How Anthropic Built 7 Layers of Memory and a Dreaming System for Claude Code](https://x.com/troyhua/status/2039052328070734102)
|
||
- 9:50 AM · Mar 31, 2026: [Claude code memory analysis](https://x.com/henryl_ai/status/2039022608310808965)
|
||
- 9:48 AM · Mar 31, 2026: [Claude Code's source code appears to have leaked: here's what we know](https://venturebeat.com/technology/claude-codes-source-code-appears-to-have-leaked-heres-what-we-know)
|
||
- 9:04 AM · Mar 31, 2026: [Deconstructing the Claude Code Architecture (In Chinese)](https://mp.weixin.qq.com/s?__biz=MzA3NzUxMzM5MQ==&mid=2453898430&idx=1&sn=1c4051fb17a15b17e449b7eb85d3e1c5&chksm=897cc501d472cdd6916679a0766ab146b5347bc78e48171d9da97de282a05c10eea8d22c3605&mpshare=1&scene=1&srcid=0401oXuLa2VmhvrcRZk7VHfH&sharer_shareinfo=e7ff02258e887208db510104bc343079&sharer_shareinfo_first=6c39c564855be1e2372289b5c09b6247#rd)
|
||
- 7:07 AM · Mar 31, 2026: [A Walkthrough of Claude Code's Source Code (In Chinese)](https://mp.weixin.qq.com/s?__biz=MjM5ODI5Njc2MA==&mid=2655937729&idx=1&sn=0afb97062ef5f229910e3e54dd36abb6&chksm=bc66bca5b0f4171b56075506f208efea18381031c5ffa33070701ee1200bef7e411ea10188e9&mpshare=1&scene=1&srcid=0331PBEUSD8CVryQYEluyZbc&sharer_shareinfo=c5a329d2cc3ec432238f5fc1d9d70723&sharer_shareinfo_first=c5a329d2cc3ec432238f5fc1d9d70723#rd)
|
||
- 5:41 AM · Mar 31, 2026: [Why Claude Code Outperforms Other Tools: An Analysis](https://x.com/YukerX/status/2038959908968919297)
|
||
- 5:03 AM · Mar 31, 2026: [Anthropic's AI Coding Tool Leaks Its Own Source Code](https://www.ndtv.com/science/anthropics-ai-coding-tool-leaks-its-own-source-code-for-the-second-time-in-a-year-11291517)
|
||
- 3:28 AM · Mar 31, 2026: [Claude Code Source Code Unveiled: Prompts, Self-Healing Mechanisms, and Multi-Agent Architecture (In Chinese)](https://mp.weixin.qq.com/s?__biz=MzI3ODY3ODg2Nw==&mid=2247484425&idx=1&sn=f77d3b97e88cb8019f014ca2eb95db65&chksm=ea98ee5bb2249e1c637520cf02b525b98b434671f2cc23ec554e5faa868e890deeead939c578&mpshare=1&scene=1&srcid=0401kVgDQ41tx7AECPzvch3W&sharer_shareinfo=5d97c04d957d52383c9b59245e421c5a&sharer_shareinfo_first=5d97c04d957d52383c9b59245e421c5a#rd)
|
||
- 3:02 AM · Mar 31, 2026: [Community Reaction to the Claude Code Source Exposure](https://x.com/hank_aibtc/status/2038919948370616330)
|
||
- 2:57 AM · Mar 31, 2026: [The code behind Claude Code](https://x.com/mal_shaik/status/2038918662489510273)
|
||
- 1:23 AM · Mar 31, 2026: [A Viral Post on the Claude Code Source Leak](https://x.com/Fried_rice/status/2038894956459290963?s=20)
|
||
|
||
---
|
||
|
||
## Content
|
||
|
||
* [1. original-source-code](#1-original-source-code)
|
||
* [2. claude-code-source-code](#2-claude-code-source-code)
|
||
+ [Overall Architecture](#overall-architecture)
|
||
+ [Core Execution Flow](#core-execution-flow)
|
||
+ [Tech Stack](#tech-stack)
|
||
+ [Main Module Descriptions](#main-module-descriptions)
|
||
- [Tool System (40+ tools)](#tool-system--40--tools-)
|
||
- [Slash Commands (~87)](#slash-commands---87-)
|
||
- [Permission System](#permission-system)
|
||
- [Context Management](#context-management)
|
||
- [Analysis Documents (`docs/`)](#analysis-documents---docs---)
|
||
* [3. claw-code](#3-claw-code)
|
||
+ [Overall Architecture](#overall-architecture-1)
|
||
+ [Core Classes](#core-classes)
|
||
+ [CLI Commands](#cli-commands)
|
||
+ [Design Features](#design-features)
|
||
* [4. nano-claude-code](#4-nano-claude-code)
|
||
+ [Features](#features)
|
||
+ [Supported Models](#supported-models)
|
||
+ [Project Structure](#project-structure)
|
||
* [5. docs/cc\_analysis](#5-docscc_analysis)
|
||
* [Comparison of the Projects](#comparison-of-the-projects)
|
||
* [License and Disclaimer](#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](#1-original-source-code) | TypeScript | Raw leaked source archive | 1,884 files |
|
||
| [claude-code-source-code](#2-claude-code-source-code) | TypeScript | Decompiled source archive (v2.1.88) + docs| 1,940 files |
|
||
| [claw-code](#3-claw-code) | Python | Clean-room architectural rewrite | 109 files |
|
||
| [nano-claude-code](#4-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.
|
||
|
||
```text
|
||
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
|
||
|
||
```text
|
||
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
|
||
|
||
```text
|
||
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](https://github.com/instructkr) (Sigrid Jin), and became one of the fastest GitHub repositories in the world to reach 30K stars.
|
||
|
||
### Overall Architecture
|
||
|
||
```text
|
||
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
|
||
|
||
```bash
|
||
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
|
||
|
||
```text
|
||
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:**
|
||
|
||
```bash
|
||
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
|
||
```
|
||
|
||
---
|
||
|
||
## 5. docs/cc\_analysis
|
||
|
||
Independent deep-dive analysis documents produced from the leaked Claude Code source snapshot (2026-03-31). All documents are based on the TypeScript source and are primarily written in Chinese.
|
||
|
||
### analysis\_20260401
|
||
|
||
| Document | Content |
|
||
| -------- | ------- |
|
||
| [Claude Code 上下文管理算法学习笔记](docs/cc_analysis/analysis_20260401/Claude_Code_Context_Management_Notes.md) | Step-by-step walkthrough of the context management algorithm: `autoCompact`, micro/reactive/trimmed compression strategies, and `toolResultStorage` |
|
||
| [Claude Code 多 Agent 架构深度分析](docs/cc_analysis/analysis_20260401/claude-code-multi-agent-architecture.md) | Deep analysis of the multi-agent architecture across 37+ files: `src/utils/swarm/`, `AgentTool/`, `coordinator/` |
|
||
| [Claude Code 值得借鉴的算法与设计模式](docs/cc_analysis/analysis_20260401/Claude_Code_Notable_Algorithms.md) | Notable algorithms and design patterns worth borrowing from the source (complements the context management notes) |
|
||
| [Claude Code 自动回滚机制解析与版本切换指南](docs/cc_analysis/analysis_20260401/Claude-Code-Version-Rollback.md) | How the automatic rollback mechanism works and a practical version-switching guide |
|
||
| [Claude Code 上下文压缩算法深度分析](docs/cc_analysis/analysis_20260401/Claude_Code上下文压缩算法深度分析.md) | Detailed reverse-engineering of the 11-file `src/services/compact/` compression pipeline |
|
||
| [Claude Code 是否偷换模型?模型切换机制深度分析](docs/cc_analysis/analysis_20260401/Claude_Code模型切换机制深度分析.md) | Source-level analysis of model-selection logic: `model.ts`, `withRetry.ts`, and `claude.ts` |
|
||
| [Claude Code Memory 记忆系统深度分析](docs/cc_analysis/analysis_20260401/Claude_Code记忆系统深度分析.md) | Full analysis of the 7-layer memory system: `memdir/`, `extractMemories/`, `SessionMemory/`, `teamMemorySync/` |
|
||
| [Claude Code 隐藏高级功能全景图](docs/cc_analysis/analysis_20260401/Claude_Code隐藏高级功能全景图.md) | Map of 55+ feature flags, 20+ hidden commands, and several undisclosed subsystems |
|
||
| [Claude Code 默认 Effort Level 设置笔记](docs/cc_analysis/analysis_20260401/Claude%20Code%20默认%20Effort%20Level%20设置笔记.md) | How to persist `/effort max` across sessions (default resets to `medium` on restart) |
|
||
| [清除 Claude Code 追踪数据指南](docs/cc_analysis/analysis_20260401/清除Claude_Code追踪数据指南.md) | macOS guide for clearing telemetry and tracking data stored by Claude Code |
|
||
| [Claude Code 深度分析报告 (PDF)](docs/cc_analysis/analysis_20260401/Claude_Code_深度分析报告.pdf) | Comprehensive analysis report in PDF format (Chinese) |
|
||
| [Claude Code Deep Analysis Report (PDF)](docs/cc_analysis/analysis_20260401/Claude_Code_Deep_Analysis_Report.pdf) | Comprehensive analysis report in PDF format (English) |
|
||
|
||
---
|
||
|
||
## 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.
|
||
|