[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-74854":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":14,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":19,"compositeScore":20,"rankGlobal":10,"rankLanguage":10,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":24,"hasPages":22,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":26,"readmeContent":27,"aiSummary":28,"trendingCount":16,"starSnapshotCount":16,"syncStatus":29,"lastSyncTime":30,"discoverSource":31},74854,"collection-claude-code-source-code","chauncygu\u002Fcollection-claude-code-source-code","chauncygu","🔥 A collection of the newest Claude Code open source","",null,"TypeScript",2589,2366,50,6,0,24,172,72,112,"Apache License 2.0",false,"main",true,[],"2026-06-12 04:01:16","\n# A collection of the newest Claude Code open source\n\n\n> **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.\n\nSource archive of Claude Code and different versions of the clean-room Python rewrite research repository\n\n## 🔥🔥🔥 News (Pacific Time)\n- 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\u002Finline execution, AI memory search, git worktree isolation, agent type definitions (~5000 Lines)](https:\u002F\u002Fgithub.com\u002FSafeRL-Lab\u002Fclawspring)\n- 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:\u002F\u002Fgithub.com\u002FSafeRL-Lab\u002Fnano-claude-code)\n- 8:36 AM · Apr 01, 2026: [Nano Claude Code v1.0: A Minimal Python Reimplementation (~1300 Lines)](https:\u002F\u002Fgithub.com\u002FSafeRL-Lab\u002Fclawspring)\n- 0:20 AM · Apr 01, 2026: [Analysis of Claude Code source code (Video: In Chinese)](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=xsg6_Gvr2J0&t=10s)\n- 19:45 PM · Mar 31, 2026: [Claude Code Research Report (In Chinese)](https:\u002F\u002Fgithub.com\u002Fchauncygu\u002Fcollection-claude-code-source-code\u002Fblob\u002Fmain\u002Fdocs\u002Fclaude-code-deep-dive-xelatex.pdf)\n- 17:13 PM · Mar 31, 2026: [Architecture Analysis of Claude Code (In Chinese)](https:\u002F\u002Fmp.weixin.qq.com\u002Fs?__biz=MzI0ODk2NDIyMQ==&mid=2247502519&idx=1&sn=1072dd7a822a78709bc7cc3bf0e1dcc2&chksm=e8de6705e2bacc854211663aa02903738560f9e858eb6ce72b94c32fdbf67917badfab2d6536&mpshare=1&scene=1&srcid=0401KpkqfaXFBReRof6AwJ74&sharer_shareinfo=30fa54f1602d1d8bb1a65e7008074e08&sharer_shareinfo_first=30fa54f1602d1d8bb1a65e7008074e08#rd)\n - 16:43 PM · Mar 31, 2026: [An Overview of Claude Code Features (In Chinese)](https:\u002F\u002Fmp.weixin.qq.com\u002Fs?__biz=MzAxODI5ODMwOA==&mid=2666572944&idx=1&sn=c54e34711e67a2e961acb341f51d2190&chksm=81ca164af949bdfe90a616c8ef8d7e729116a4a12a480cd9d012f42f5b8d7ecd6d05e284db09&mpshare=1&scene=1&srcid=04017JkKs9qrCh4AHcfZq7qL&sharer_shareinfo=95eb268167dd1b3d98271b8b26e7553e&sharer_shareinfo_first=95eb268167dd1b3d98271b8b26e7553e#rd)\n- 15:00 PM · Mar 31, 2026: [Hacker News Community Discussion about Claude Code Leak](https:\u002F\u002Fnews.ycombinator.com\u002Fitem?id=47586778)\n- 11:48 AM · Mar 31, 2026: [How Anthropic Built 7 Layers of Memory and a Dreaming System for Claude Code](https:\u002F\u002Fx.com\u002Ftroyhua\u002Fstatus\u002F2039052328070734102)\n- 9:50 AM · Mar 31, 2026: [Claude code memory analysis](https:\u002F\u002Fx.com\u002Fhenryl_ai\u002Fstatus\u002F2039022608310808965)\n- 9:48 AM · Mar 31, 2026: [Claude Code's source code appears to have leaked: here's what we know](https:\u002F\u002Fventurebeat.com\u002Ftechnology\u002Fclaude-codes-source-code-appears-to-have-leaked-heres-what-we-know)\n- 9:04 AM · Mar 31, 2026: [Deconstructing the Claude Code Architecture (In Chinese)](https:\u002F\u002Fmp.weixin.qq.com\u002Fs?__biz=MzA3NzUxMzM5MQ==&mid=2453898430&idx=1&sn=1c4051fb17a15b17e449b7eb85d3e1c5&chksm=897cc501d472cdd6916679a0766ab146b5347bc78e48171d9da97de282a05c10eea8d22c3605&mpshare=1&scene=1&srcid=0401oXuLa2VmhvrcRZk7VHfH&sharer_shareinfo=e7ff02258e887208db510104bc343079&sharer_shareinfo_first=6c39c564855be1e2372289b5c09b6247#rd)\n- 7:07 AM · Mar 31, 2026: [A Walkthrough of Claude Code's Source Code (In Chinese)](https:\u002F\u002Fmp.weixin.qq.com\u002Fs?__biz=MjM5ODI5Njc2MA==&mid=2655937729&idx=1&sn=0afb97062ef5f229910e3e54dd36abb6&chksm=bc66bca5b0f4171b56075506f208efea18381031c5ffa33070701ee1200bef7e411ea10188e9&mpshare=1&scene=1&srcid=0331PBEUSD8CVryQYEluyZbc&sharer_shareinfo=c5a329d2cc3ec432238f5fc1d9d70723&sharer_shareinfo_first=c5a329d2cc3ec432238f5fc1d9d70723#rd)\n- 5:41 AM · Mar 31, 2026: [Why Claude Code Outperforms Other Tools: An Analysis](https:\u002F\u002Fx.com\u002FYukerX\u002Fstatus\u002F2038959908968919297)\n- 5:03 AM · Mar 31, 2026: [Anthropic's AI Coding Tool Leaks Its Own Source Code](https:\u002F\u002Fwww.ndtv.com\u002Fscience\u002Fanthropics-ai-coding-tool-leaks-its-own-source-code-for-the-second-time-in-a-year-11291517)\n- 3:28 AM · Mar 31, 2026: [Claude Code Source Code Unveiled: Prompts, Self-Healing Mechanisms, and Multi-Agent Architecture (In Chinese)](https:\u002F\u002Fmp.weixin.qq.com\u002Fs?__biz=MzI3ODY3ODg2Nw==&mid=2247484425&idx=1&sn=f77d3b97e88cb8019f014ca2eb95db65&chksm=ea98ee5bb2249e1c637520cf02b525b98b434671f2cc23ec554e5faa868e890deeead939c578&mpshare=1&scene=1&srcid=0401kVgDQ41tx7AECPzvch3W&sharer_shareinfo=5d97c04d957d52383c9b59245e421c5a&sharer_shareinfo_first=5d97c04d957d52383c9b59245e421c5a#rd)\n- 3:02 AM · Mar 31, 2026: [Community Reaction to the Claude Code Source Exposure](https:\u002F\u002Fx.com\u002Fhank_aibtc\u002Fstatus\u002F2038919948370616330)\n- 2:57 AM · Mar 31, 2026: [The code behind Claude Code](https:\u002F\u002Fx.com\u002Fmal_shaik\u002Fstatus\u002F2038918662489510273)\n- 1:23 AM · Mar 31, 2026: [A Viral Post on the Claude Code Source Leak](https:\u002F\u002Fx.com\u002FFried_rice\u002Fstatus\u002F2038894956459290963?s=20)\n\n---\n\n## Content\n\n  * [1. original-source-code](#1-original-source-code)\n  * [2. claude-code-source-code](#2-claude-code-source-code)\n    + [Overall Architecture](#overall-architecture)\n    + [Core Execution Flow](#core-execution-flow)\n    + [Tech Stack](#tech-stack)\n    + [Main Module Descriptions](#main-module-descriptions)\n      - [Tool System (40+ tools)](#tool-system--40--tools-)\n      - [Slash Commands (~87)](#slash-commands---87-)\n      - [Permission System](#permission-system)\n      - [Context Management](#context-management)\n      - [Analysis Documents (`docs\u002F`)](#analysis-documents---docs---)\n  * [3. claw-code](#3-claw-code)\n    + [Overall Architecture](#overall-architecture-1)\n    + [Core Classes](#core-classes)\n    + [CLI Commands](#cli-commands)\n    + [Design Features](#design-features)\n  * [4. nano-claude-code](#4-nano-claude-code)\n    + [Features](#features)\n    + [Supported Models](#supported-models)\n    + [Project Structure](#project-structure)\n  * [Comparison of the Projects](#comparison-of-the-projects)\n  * [License and Disclaimer](#license-and-disclaimer)\n\n\n\n---\nThis repository contains subprojects that study Claude Code (Anthropic’s official CLI tool) from multiple angles:\n\n| Subproject                                              | Language   | Nature                                    | File Count  |\n| ------------------------------------------------------- | ---------- | ----------------------------------------- | ----------- |\n| [original-source-code](#1-original-source-code)         | TypeScript | Raw leaked source archive                 | 1,884 files |\n| [claude-code-source-code](#2-claude-code-source-code)   | TypeScript | Decompiled source archive (v2.1.88) + docs| 1,940 files |\n| [claw-code](#3-claw-code)                               | Python     | Clean-room architectural rewrite          | 109 files   |\n| [nano-claude-code](#4-nano-claude-code)                 | Python     | Minimal multi-provider reimplementation   | ~30 files   |\n\n---\n\n\n\n## 1. original-source-code\n\nThe raw leaked TypeScript source of Claude Code, preserved as-is from the original exposure on March 31, 2026. Contains 1,884 TypeScript\u002FTSX files (packaged as `src.zip`) spanning the full `src\u002F` directory tree — the same files that triggered community discussion and downstream research.\n\n```text\noriginal-source-code\u002F\n├── src\u002F                  # Full TypeScript source tree (1,884 .ts\u002F.tsx files)\n│   ├── main.tsx          # CLI entry point\n│   ├── query.ts          # Core agent loop\n│   ├── commands.ts       # Slash command definitions\n│   ├── tools.ts          # Tool registration\n│   └── ...               # All other source directories (same layout as claude-code-source-code\u002Fsrc)\n├── src.zip               # Compressed archive (~9.5 MB)\n└── readme.md\n```\n\nThis 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.\n\n---\n\n\n\n## 2. claude-code-source-code\n\nA decompiled\u002Funpacked source archive of Claude Code v2.1.88, reconstructed from the npm package `@anthropic-ai\u002Fclaude-code@2.1.88`, containing approximately 163,318 lines of TypeScript code.\n\n### Overall Architecture\n\n```text\nclaude-code-source-code\u002F\n├── src\u002F\n│   ├── main.tsx              # CLI entry and REPL bootstrap (4,683 lines)\n│   ├── query.ts              # Core main agent loop (largest single file, 785KB)\n│   ├── QueryEngine.ts        # SDK\u002FHeadless query lifecycle engine\n│   ├── Tool.ts               # Tool interface definitions + buildTool factory\n│   ├── commands.ts           # Slash command definitions (~25K lines)\n│   ├── tools.ts              # Tool registration and presets\n│   ├── context.ts            # User input context handling\n│   ├── history.ts            # Session history management\n│   ├── cost-tracker.ts       # API cost tracking\n│   ├── setup.ts              # First-run initialization\n│   │\n│   ├── cli\u002F                  # CLI infrastructure (stdio, structured transports)\n│   ├── commands\u002F             # ~87 slash command implementations\n│   ├── components\u002F           # React\u002FInk terminal UI (33 subdirectories)\n│   ├── tools\u002F                # 40+ tool implementations (44 subdirectories)\n│   ├── services\u002F             # Business logic layer (22 subdirectories)\n│   ├── utils\u002F                # Utility function library\n│   ├── state\u002F                # Application state management\n│   ├── types\u002F                # TypeScript type definitions\n│   ├── hooks\u002F                # React Hooks\n│   ├── bridge\u002F               # Claude Desktop remote bridge\n│   ├── remote\u002F               # Remote mode\n│   ├── coordinator\u002F          # Multi-agent coordination\n│   ├── tasks\u002F                # Task management\n│   ├── assistant\u002F            # KAIROS assistant mode\n│   ├── memdir\u002F               # Long-term memory management\n│   ├── plugins\u002F              # Plugin system\n│   ├── voice\u002F                # Voice mode\n│   └── vim\u002F                  # Vim mode\n│\n├── docs\u002F                     # In-depth analysis docs (bilingual: Chinese\u002FEnglish)\n│   ├── en\u002F                   # English analysis\n│   └── zh\u002F                   # Chinese analysis\n├── vendor\u002F                   # Third-party dependencies\n├── stubs\u002F                    # Module stubs\n├── types\u002F                    # Global type definitions\n├── utils\u002F                    # Top-level utility functions\n├── scripts\u002F                  # Build scripts\n└── package.json\n```\n\n### Core Execution Flow\n\n```text\nUser Input\n  ↓\nprocessUserInput()         # Parse \u002Fslash commands\n  ↓\nquery()                    # Main agent loop (query.ts)\n  ├── fetchSystemPromptParts()    # Assemble system prompt\n  ├── StreamingToolExecutor       # Parallel tool execution\n  ├── autoCompact()               # Automatic context compression\n  └── runTools()                  # Tool orchestration and scheduling\n  ↓\nyield SDKMessage           # Stream results back to the consumer\n```\n\n### Tech Stack\n\n| Component       | Technology                               |\n| --------------- | ---------------------------------------- |\n| Language        | TypeScript 6.0+                          |\n| Runtime         | Bun (compiled into Node.js >= 18 bundle) |\n| Claude API      | Anthropic SDK                            |\n| Terminal UI     | React + Ink                              |\n| Code Bundling   | esbuild                                  |\n| Data Validation | Zod                                      |\n| Tool Protocol   | MCP (Model Context Protocol)             |\n\n### Main Module Descriptions\n\n#### Tool System (40+ tools)\n\n| Category                    | Tools                                                     |\n| --------------------------- | --------------------------------------------------------- |\n| File Operations             | FileReadTool, FileEditTool, FileWriteTool                 |\n| Code Search                 | GlobTool, GrepTool                                        |\n| System Execution            | BashTool                                                  |\n| Web Access                  | WebFetchTool, WebSearchTool                               |\n| Task Management             | TaskCreateTool, TaskUpdateTool, TaskGetTool, TaskListTool |\n| Sub-agents                  | AgentTool                                                 |\n| Code Environments           | NotebookEditTool, REPLTool, LSPTool                       |\n| Git Workflow                | EnterWorktreeTool, ExitWorktreeTool                       |\n| Configuration & Permissions | ConfigTool, AskUserQuestionTool                           |\n| Memory & Planning           | TodoWriteTool, EnterPlanModeTool, ExitPlanModeTool        |\n| Automation                  | ScheduleCronTool, RemoteTriggerTool, SleepTool            |\n| MCP Integration             | MCPTool                                                   |\n\n#### Slash Commands (~87)\n\n`\u002Fcommit` `\u002Fcommit-push-pr` `\u002Freview` `\u002Fresume` `\u002Fsession` `\u002Fmemory` `\u002Fconfig` `\u002Fskills` `\u002Fhelp` `\u002Fvoice` `\u002Fdesktop` `\u002Fmcp` `\u002Fpermissions` `\u002Ftheme` `\u002Fvim` `\u002Fcopy` and more\n\n#### Permission System\n\n* Three modes: `default` (ask user) \u002F `bypass` (auto-allow) \u002F `strict` (auto-deny)\n* Tool-level fine-grained control\n* ML-based automated permission inference classifier\n* Persistent storage of permission rules\n\n#### Context Management\n\n* Automatic compression strategies (`autoCompact`): reactive compression, micro-compression, trimmed compression\n* Context collapsing (`CONTEXT_COLLAPSE`)\n* Token counting and estimation\n* Session transcript persistence\n\n#### Analysis Documents (`docs\u002F`)\n\n| Document                                   | Content                                                                           |\n| ------------------------------------------ | --------------------------------------------------------------------------------- |\n| 01 - Telemetry and Privacy                 | Dual-layer analysis pipeline (Anthropic + Datadog), with no opt-out switch        |\n| 02 - Hidden Features and Model Codenames   | Internal codenames such as Capybara, Tengu, Fennec, Numbat                        |\n| 03 - Undercover Mode                       | Anthropic employees automatically entering undercover mode in public repositories |\n| 04 - Remote Control and Emergency Switches | Hourly polling, 6+ killswitches, dangerous-change popups                          |\n| 05 - Future Roadmap                        | KAIROS autonomous agent, voice mode, 17 unreleased tools                          |\n\n---\n\n## 3. claw-code\n\nA clean-room Python rewrite of Claude Code (without including original source copies), focused on architectural mirroring and research. Built by [@instructkr](https:\u002F\u002Fgithub.com\u002Finstructkr) (Sigrid Jin), and became one of the fastest GitHub repositories in the world to reach 30K stars.\n\n### Overall Architecture\n\n```text\nclaw-code\u002F\n├── src\u002F\n│   ├── __init__.py               # Package export interface\n│   ├── main.py                   # CLI entry (~200 lines)\n│   ├── query_engine.py           # Core query engine\n│   ├── runtime.py                # Runtime session management\n│   ├── models.py                 # Shared data classes\n│   ├── commands.py               # Command metadata and execution framework\n│   ├── tools.py                  # Tool metadata and execution framework\n│   ├── permissions.py            # Permission context management\n│   ├── context.py                # Ported context layer\n│   ├── setup.py                  # Workspace initialization\n│   ├── session_store.py          # Session persistence\n│   ├── transcript.py             # Session transcript storage\n│   ├── port_manifest.py          # Workspace manifest generation\n│   ├── execution_registry.py     # Execution registry\n│   ├── history.py                # History logs\n│   ├── parity_audit.py           # Parity audit against TypeScript source\n│   ├── remote_runtime.py         # Remote mode simulation\n│   ├── bootstrap_graph.py        # Bootstrap graph generation\n│   ├── command_graph.py          # Command graph partitioning\n│   ├── tool_pool.py              # Tool pool assembly\n│   │\n│   ├── reference_data\u002F           # JSON snapshot data (drives command\u002Ftool metadata)\n│   │   ├── commands_snapshot.json\n│   │   └── tools_snapshot.json\n│   │\n│   ├── commands\u002F                 # Command implementation subdirectory\n│   ├── tools\u002F                    # Tool implementation subdirectory\n│   ├── services\u002F                 # Business logic services\n│   ├── components\u002F               # Terminal UI components (Python version)\n│   ├── state\u002F                    # State management\n│   ├── types\u002F                    # Type definitions\n│   ├── utils\u002F                    # Utility functions\n│   ├── remote\u002F                   # Remote mode\n│   ├── bridge\u002F                   # Bridge modules\n│   ├── hooks\u002F                    # Hook system\n│   ├── memdir\u002F                   # Memory management\n│   ├── vim\u002F                      # Vim mode\n│   ├── voice\u002F                    # Voice mode\n│   └── plugins\u002F                  # Plugin system\n│\n└── tests\u002F                        # Validation tests\n```\n\n### Core Classes\n\n| Class \u002F Module          | Responsibility                                                                      |\n| ----------------------- | ----------------------------------------------------------------------------------- |\n| `QueryEnginePort`       | Query engine handling message submission, streaming output, and session compression |\n| `PortRuntime`           | Runtime manager responsible for routing, session startup, and turn-loop execution   |\n| `PortManifest`          | Workspace manifest that generates Markdown overviews                                |\n| `ToolPermissionContext` | Tool permission context (`allow` \u002F `deny` \u002F `ask`)                                  |\n| `WorkspaceSetup`        | Environment detection and initialization reporting                                  |\n| `TranscriptStore`       | Session transcript storage with append, compaction, and replay support              |\n\n### CLI Commands\n\n```bash\npython3 -m src.main [COMMAND]\n\n# Overview\nsummary              # Markdown workspace overview\nmanifest             # Print manifest\nsubsystems           # List Python modules\n\n# Routing and indexing\ncommands             # List all commands\ntools                # List all tools\nroute [PROMPT]       # Route prompt to corresponding command\u002Ftool\n\n# Execution\nbootstrap [PROMPT]   # Start runtime session\nturn-loop [PROMPT]   # Run turn loop (--max-turns)\nexec-command NAME    # Execute command\nexec-tool NAME       # Execute tool\n\n# Session management\nflush-transcript     # Persist session transcript\nload-session ID      # Load saved session\n\n# Remote mode\nremote-mode TARGET   # Simulate remote control\nssh-mode TARGET      # Simulate SSH branch\nteleport-mode TARGET # Simulate Teleport branch\n\n# Audit and config\nparity-audit         # Compare consistency with TypeScript source\nsetup-report         # Startup configuration report\nbootstrap-graph      # Bootstrap phase graph\ncommand-graph        # Command graph partition view\ntool-pool            # Tool pool assembly view\n```\n\n### Design Features\n\n* **Snapshot-driven**: command\u002Ftool metadata is loaded through JSON snapshots without requiring full logical implementations\n* **Clean-room rewrite**: does not include original TypeScript code; independently implemented\n* **Parity audit**: built-in `parity_audit.py` tracks gaps from the original implementation\n* **Lightweight architecture**: core framework implemented in 109 files, suitable for learning and extension\n\n---\n\n## 4. nano-claude-code\n\nA 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.\n\n### Features\n\n| Feature | Details |\n| ------- | ------- |\n| Multi-provider | Anthropic · OpenAI · Gemini · Kimi · Qwen · Zhipu · DeepSeek · Ollama · LM Studio · Custom endpoint |\n| Interactive REPL | readline history, Tab-complete slash commands |\n| Agent loop | Streaming API + automatic tool-use loop |\n| 18 built-in tools | Read · Write · Edit · Bash · Glob · Grep · WebFetch · WebSearch · MemorySave · MemoryDelete · MemorySearch · MemoryList · Agent · SendMessage · CheckAgentResult · ListAgentTasks · ListAgentTypes · Skill · SkillList |\n| Diff view | Git-style red\u002Fgreen diff display for Edit and Write |\n| Context compression | Auto-compact long conversations to stay within model limits |\n| Persistent memory | Dual-scope memory (user + project) with 4 types, AI search, staleness warnings |\n| Multi-agent | Spawn typed sub-agents (coder\u002Freviewer\u002Fresearcher\u002F…), git worktree isolation, background mode |\n| Skills | Built-in `\u002Fcommit` · `\u002Freview` + custom markdown skills with argument substitution and fork\u002Finline execution |\n| Plugin tools | Register custom tools via `tool_registry.py` |\n| Permission system | `auto` \u002F `accept-all` \u002F `manual` modes |\n| 17 slash commands | `\u002Fmodel` · `\u002Fconfig` · `\u002Fsave` · `\u002Fcost` · `\u002Fmemory` · `\u002Fskills` · `\u002Fagents` · … |\n| Context injection | Auto-loads `CLAUDE.md`, git status, cwd, persistent memory |\n| Session persistence | Save \u002F load conversations to `~\u002F.nano_claude\u002Fsessions\u002F` |\n| Extended Thinking | Toggle on\u002Foff (Claude models only) |\n| Cost tracking | Token usage + estimated USD cost |\n| Non-interactive mode | `--print` flag for scripting \u002F CI |\n\n### Supported Models\n\n**Closed-source (API):** Claude (Anthropic), GPT \u002F o-series (OpenAI), Gemini (Google), Kimi (Moonshot AI), Qwen (Alibaba DashScope), GLM (Zhipu), DeepSeek\n\n**Open-source (local via Ollama):** llama3.3\u002F3.2, qwen2.5-coder, deepseek-r1, phi4, mistral, mixtral, gemma3, codellama, and any model on `ollama list`\n\n**Self-hosted:** vLLM, LM Studio, or any OpenAI-compatible endpoint via `CUSTOM_BASE_URL`\n\n### Project Structure\n\n```text\nnano-claude-code\u002F\n├── nano_claude.py       # Entry point: REPL + slash commands + rendering   (~748 lines)\n├── agent.py             # Agent loop: message format + tool dispatch        (~174 lines)\n├── providers.py         # Multi-provider adapters + message conversion      (~507 lines)\n├── tools.py             # Tool dispatch + auto-registration of all packages (~467 lines)\n├── tool_registry.py     # Central tool registry + plugin entry point        (~98 lines)\n├── context.py           # System prompt builder: CLAUDE.md + git + memory  (~135 lines)\n├── compaction.py        # Context compression (auto-compact)                (~196 lines)\n├── config.py            # Config load\u002Fsave\u002Fdefaults                         (~72 lines)\n├── memory.py            # Backward-compat shim → memory\u002F\n├── skills.py            # Backward-compat shim → skill\u002F\n├── subagent.py          # Backward-compat shim → multi_agent\u002F\n│\n├── memory\u002F              # Persistent memory package\n│   ├── store.py         # Save\u002Fload\u002Fdelete\u002Fsearch memory entries\n│   ├── scan.py          # Index scanning, age\u002Ffreshness helpers\n│   ├── context.py       # System-prompt injection + AI-ranked search\n│   ├── types.py         # MEMORY_TYPES definitions\n│   └── tools.py         # MemorySave · MemoryDelete · MemorySearch · MemoryList\n│\n├── skill\u002F               # Skill system package\n│   ├── loader.py        # SkillDef, file parsing, argument substitution\n│   ├── builtin.py       # Built-in skills: \u002Fcommit, \u002Freview\n│   ├── executor.py      # Inline + fork execution modes\n│   └── tools.py         # Skill · SkillList\n│\n├── multi_agent\u002F         # Multi-agent orchestration package\n│   ├── subagent.py      # AgentDefinition, SubAgentTask, SubAgentManager, worktree helpers\n│   └── tools.py         # Agent · SendMessage · CheckAgentResult · ListAgentTasks · ListAgentTypes\n│\n├── tests\u002F               # 101 tests (monkeypatched, no real ~\u002F.nano_claude touched)\n├── docs\u002F                # Docs and demo assets\n└── requirements.txt\n```\n\n**Quick start:**\n\n```bash\npip install anthropic openai httpx rich\nexport ANTHROPIC_API_KEY=sk-ant-...\npython nano_claude.py\n\n# Switch provider at startup\npython nano_claude.py --model gpt-4o\npython nano_claude.py --model ollama\u002Fqwen2.5-coder\n\n# Non-interactive \u002F CI\npython nano_claude.py --print \"Write a Python fibonacci function\" --accept-all\n```\n\n**Memory** — persistent across sessions, dual-scope (user `~\u002F.nano_claude\u002Fmemory\u002F` and project `.nano_claude\u002Fmemory\u002F`):\n\n```\n\u002Fmemory               # list all memories with staleness info\nMemorySave(name=\"...\", type=\"feedback\", content=\"...\", scope=\"user\")\nMemorySearch(query=\"...\", use_ai=True)\n```\n\n**Skills** — reusable prompt templates, invoke from REPL:\n\n```\n\u002Fcommit               # built-in: review staged changes and create a git commit\n\u002Freview 123           # built-in: review PR #123\n\u002Fskills               # list all available skills with triggers and hints\n```\n\n**Multi-agent** — spawn typed sub-agents with optional git worktree isolation:\n\n```\nAgent(prompt=\"...\", subagent_type=\"coder\", isolation=\"worktree\", wait=False)\nSendMessage(agent_name=\"my-agent\", message=\"...\")\n\u002Fagents               # show all active and finished sub-agent tasks\n```\n\n---\n\n## Comparison of the Projects\n\n| Dimension               | original-source-code           | claude-code-source-code                   | claw-code                                        | nano-claude-code                              |\n| ----------------------- | ------------------------------ | ----------------------------------------- | ------------------------------------------------ | --------------------------------------------- |\n| Language                | TypeScript                     | TypeScript                                | Python                                           | Python                                        |\n| Code Size               | ~163,000 lines                 | ~163,000 lines + docs                     | ~5,000 lines                                     | ~5,000 lines                                  |\n| Nature                  | Raw leaked source archive      | Decompiled source archive + analysis      | Clean-room architectural rewrite                 | Minimal functional reimplementation           |\n| Functional Completeness | Complete (100%)                | Complete (100%)                           | Architectural framework (~20%)                   | Core loop + memory + multi-agent + skills     |\n| Core Loop               | `query.ts` (785KB)             | `query.ts` (785KB)                        | `QueryEnginePort` (~200 lines)                   | `agent.py` (~174 lines)                       |\n| Tool System             | 40+ fully implemented tools    | 40+ fully implemented tools               | Snapshot metadata + execution framework          | 18 fully implemented tools + plugin registry  |\n| Memory System           | Yes (7-layer, complex)         | Yes (7-layer, complex)                    | No                                               | Yes (dual-scope, 4 types, AI search)          |\n| Multi-agent             | Yes (full coordinator)         | Yes (full coordinator)                    | No                                               | Yes (typed agents, worktree isolation)        |\n| Skills                  | Yes (~87 commands)             | Yes (~87 commands)                        | Snapshot metadata only                           | Yes (built-in + custom markdown skills)       |\n| Multi-provider          | No (Anthropic only)            | No (Anthropic only)                       | No                                               | Yes (10+ providers)                           |\n| Immediately Runnable    | No                             | No                                        | Limited (CLI metadata only)                      | Yes                                           |\n| Main Use Case           | Raw reference snapshot         | Deep study of full implementation details | Architectural understanding and porting research | Lightweight full-featured coding assistant    |\n\n---\n\n\n\n","该项目是一个收集最新Claude Code开源代码的仓库，旨在为学术研究和教育提供资源。核心功能包括不同版本的Python重写研究库，涵盖多代理包、内存包、内置技能、参数替换等特性，并支持开源和闭源模型。项目采用TypeScript编写，适合对AI系统架构、多代理交互及记忆机制感兴趣的开发者或研究人员使用。请注意，此项目仅供学术和教育用途，用户需遵守相关法律法规和服务条款。",2,"2026-06-11 03:51:06","high_star"]