Skip to content

Commit e4fe623

Browse files
sanbuphyclaude
andcommitted
Add Chinese README, docs links, and collapsible module tables
- Add README_CN.md with full Chinese translation - Add language switcher (EN/ZH) and docs/ links to README.md - Collapse long module tables (Internal Code, Tools, Assets) into <details> - Point to docs/ directory for deep analysis reports Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent de14c0a commit e4fe623

2 files changed

Lines changed: 305 additions & 0 deletions

File tree

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
> Extracted from npm package `@anthropic-ai/claude-code` version **2.1.88**.
44
> The published package ships a single bundled `cli.js` (~12MB). The `src/` directory in this repo contains the **unbundled TypeScript source** extracted from the npm tarball.
55
6+
**Language**: **English** | [中文](README_CN.md)
7+
8+
---
9+
10+
> **Deep Analysis Reports**: Full source code analysis reports are available in the [`docs/`](docs/) directory (bilingual EN/ZH):
11+
> - Telemetry & Privacy (opt-out-free data collection pipeline)
12+
> - Hidden Features & Model Codenames (Tengu, Capybara, Fennec, Numbat)
13+
> - Undercover Mode (AI attribution stripping in open-source contributions)
14+
> - Remote Control & Killswitches (managed settings, feature flags)
15+
> - Future Roadmap (Numbat model, KAIROS autonomous mode, voice input)
16+
>
17+
> **English**: [`docs/en/`](docs/en/) | **中文**: [`docs/zh/`](docs/zh/)
18+
619
---
720

821
## Missing Modules Notice (108 modules)
@@ -15,6 +28,9 @@
1528

1629
These modules have no source files anywhere in the npm package. They are internal Anthropic infrastructure.
1730

31+
<details>
32+
<summary>Click to expand full list</summary>
33+
1834
| Module | Purpose | Feature Gate |
1935
|--------|---------|-------------|
2036
| `daemon/main.js` | Background daemon supervisor | `DAEMON` |
@@ -61,10 +77,15 @@ These modules have no source files anywhere in the npm package. They are interna
6177
| `udsClient.js` / `udsMessaging.js` | UDS messaging client | `UDS_INBOX` |
6278
| `systemThemeWatcher.js` | Theme watcher | `AUTO_THEME` |
6379

80+
</details>
81+
6482
### Feature-Gated Tools (~20 modules, DCE'd from bundle)
6583

6684
These tools have type signatures in `sdk-tools.d.ts` but their implementations were stripped at compile time.
6785

86+
<details>
87+
<summary>Click to expand full list</summary>
88+
6889
| Tool | Purpose | Feature Gate |
6990
|------|---------|-------------|
7091
| `REPLTool` | Interactive REPL (VM sandbox) | `ant` (internal) |
@@ -85,10 +106,15 @@ These tools have type signatures in `sdk-tools.d.ts` but their implementations w
85106
| `ListPeersTool` | List active peers | `UDS_INBOX` |
86107
| `DiscoverSkillsTool` | Skill discovery | `EXPERIMENTAL_SKILL_SEARCH` |
87108

109+
</details>
110+
88111
### Text/Prompt Assets (~6 files)
89112

90113
These are internal prompt templates and documentation, never published.
91114

115+
<details>
116+
<summary>Click to expand</summary>
117+
92118
| File | Purpose |
93119
|------|---------|
94120
| `yolo-classifier-prompts/auto_mode_system_prompt.txt` | Auto-mode system prompt for classifier |
@@ -98,6 +124,8 @@ These are internal prompt templates and documentation, never published.
98124
| `verify/examples/cli.md` | CLI verification examples |
99125
| `verify/examples/server.md` | Server verification examples |
100126

127+
</details>
128+
101129
### Why They're Missing
102130

103131
```

README_CN.md

Lines changed: 277 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,277 @@
1+
# Claude Code v2.1.88 — 源码分析
2+
3+
> 从 npm 包 `@anthropic-ai/claude-code` **2.1.88** 版本中提取。
4+
> 发布的包只有一个打包后的 `cli.js`~12MB)。本仓库的 `src/` 目录包含从 npm 包中解包的 **TypeScript 源码**
5+
6+
**语言**: [English](README.md) | **中文**
7+
8+
---
9+
10+
> **深度分析文档**: 完整的源码分析报告已发布在 [`docs/`](docs/) 目录下,包含中英双语版本:
11+
> - 遥测与隐私(无法退出的数据收集管道)
12+
> - 隐藏功能与模型代号(Tengu、Capybara、Fennec、Numbat)
13+
> - 卧底模式(在开源项目中隐藏 AI 身份)
14+
> - 远程控制与紧急开关(托管设置、feature flag)
15+
> - 未来路线图(Numbat 模型、KAIROS 自主模式、语音输入)
16+
>
17+
> **英文文档**: [`docs/en/`](docs/en/) | **中文文档**: [`docs/zh/`](docs/zh/)
18+
19+
---
20+
21+
## 缺失模块说明(108 个模块)
22+
23+
> **源码不完整。** 108 个被 `feature()` 门控的模块**未包含**在 npm 包中。
24+
> 它们仅存在于 Anthropic 的内部 monorepo 中,在编译时被死代码消除。
25+
> **无法**`cli.js``sdk-tools.d.ts` 或任何已发布的制品中恢复。
26+
27+
### Anthropic 内部代码(~70 个模块,从未发布)
28+
29+
这些模块在 npm 包中没有任何源文件。它们是 Anthropic 内部基础设施。
30+
31+
<details>
32+
<summary>点击展开完整列表</summary>
33+
34+
| Module | Purpose | Feature Gate |
35+
|--------|---------|-------------|
36+
| `daemon/main.js` | 后台守护进程管理器 | `DAEMON` |
37+
| `daemon/workerRegistry.js` | 守护进程 worker 注册 | `DAEMON` |
38+
| `proactive/index.js` | 主动通知系统 | `PROACTIVE` |
39+
| `contextCollapse/index.js` | 上下文折叠服务(实验性) | `CONTEXT_COLLAPSE` |
40+
| `contextCollapse/operations.js` | 折叠操作 | `CONTEXT_COLLAPSE` |
41+
| `contextCollapse/persist.js` | 折叠持久化 | `CONTEXT_COLLAPSE` |
42+
| `skillSearch/featureCheck.js` | 远程技能特性检查 | `EXPERIMENTAL_SKILL_SEARCH` |
43+
| `skillSearch/remoteSkillLoader.js` | 远程技能加载器 | `EXPERIMENTAL_SKILL_SEARCH` |
44+
| `skillSearch/remoteSkillState.js` | 远程技能状态 | `EXPERIMENTAL_SKILL_SEARCH` |
45+
| `skillSearch/telemetry.js` | 技能搜索遥测 | `EXPERIMENTAL_SKILL_SEARCH` |
46+
| `skillSearch/localSearch.js` | 本地技能搜索 | `EXPERIMENTAL_SKILL_SEARCH` |
47+
| `skillSearch/prefetch.js` | 技能预取 | `EXPERIMENTAL_SKILL_SEARCH` |
48+
| `coordinator/workerAgent.js` | 多代理协调器 worker | `COORDINATOR_MODE` |
49+
| `bridge/peerSessions.js` | 桥接对等会话管理 | `BRIDGE_MODE` |
50+
| `assistant/index.js` | KAIROS 助手模式 | `KAIROS` |
51+
| `assistant/AssistantSessionChooser.js` | 助手会话选择器 | `KAIROS` |
52+
| `compact/reactiveCompact.js` | 响应式上下文压缩 | `CACHED_MICROCOMPACT` |
53+
| `compact/snipCompact.js` | 基于裁剪的压缩 | `HISTORY_SNIP` |
54+
| `compact/snipProjection.js` | 裁剪投影 | `HISTORY_SNIP` |
55+
| `compact/cachedMCConfig.js` | 缓存微压缩配置 | `CACHED_MICROCOMPACT` |
56+
| `sessionTranscript/sessionTranscript.js` | 会话转录服务 | `TRANSCRIPT_CLASSIFIER` |
57+
| `commands/agents-platform/index.js` | 内部代理平台 | `ant` (内部) |
58+
| `commands/assistant/index.js` | 助手命令 | `KAIROS` |
59+
| `commands/buddy/index.js` | Buddy 系统通知 | `BUDDY` |
60+
| `commands/fork/index.js` | Fork 子代理命令 | `FORK_SUBAGENT` |
61+
| `commands/peers/index.js` | 多对等命令 | `BRIDGE_MODE` |
62+
| `commands/proactive.js` | 主动命令 | `PROACTIVE` |
63+
| `commands/remoteControlServer/index.js` | 远程控制服务器 | `DAEMON` + `BRIDGE_MODE` |
64+
| `commands/subscribe-pr.js` | GitHub PR 订阅 | `KAIROS_GITHUB_WEBHOOKS` |
65+
| `commands/torch.js` | 内部调试工具 | `TORCH` |
66+
| `commands/workflows/index.js` | 工作流命令 | `WORKFLOW_SCRIPTS` |
67+
| `jobs/classifier.js` | 内部任务分类器 | `TEMPLATES` |
68+
| `memdir/memoryShapeTelemetry.js` | 记忆形态遥测 | `MEMORY_SHAPE_TELEMETRY` |
69+
| `services/sessionTranscript/sessionTranscript.js` | 会话转录 | `TRANSCRIPT_CLASSIFIER` |
70+
| `tasks/LocalWorkflowTask/LocalWorkflowTask.js` | 本地工作流任务 | `WORKFLOW_SCRIPTS` |
71+
| `protectedNamespace.js` | 内部命名空间守卫 | `ant` (内部) |
72+
| `protectedNamespace.js` (envUtils) | 受保护命名空间运行时 | `ant` (内部) |
73+
| `coreTypes.generated.js` | 生成的核心类型 | `ant` (内部) |
74+
| `devtools.js` | 内部开发工具 | `ant` (内部) |
75+
| `attributionHooks.js` | 内部归属钩子 | `COMMIT_ATTRIBUTION` |
76+
| `systemThemeWatcher.js` | 系统主题监视器 | `AUTO_THEME` |
77+
| `udsClient.js` / `udsMessaging.js` | UDS 消息客户端 | `UDS_INBOX` |
78+
79+
</details>
80+
81+
### Feature-Gated 工具(~20 个模块)
82+
83+
这些工具有类型签名,但实现被编译时移除。
84+
85+
<details>
86+
<summary>点击展开完整列表</summary>
87+
88+
| Tool | Purpose | Feature Gate |
89+
|------|---------|-------------|
90+
| `REPLTool` | 交互式 REPL(VM 沙箱) | `ant` (内部) |
91+
| `SnipTool` | 上下文裁剪 | `HISTORY_SNIP` |
92+
| `SleepTool` | 代理循环中的休眠/延迟 | `PROACTIVE` / `KAIROS` |
93+
| `MonitorTool` | MCP 监控 | `MONITOR_TOOL` |
94+
| `OverflowTestTool` | 溢出测试 | `OVERFLOW_TEST_TOOL` |
95+
| `WorkflowTool` | 工作流执行 | `WORKFLOW_SCRIPTS` |
96+
| `WebBrowserTool` | 浏览器自动化 | `WEB_BROWSER_TOOL` |
97+
| `TerminalCaptureTool` | 终端捕获 | `TERMINAL_PANEL` |
98+
| `TungstenTool` | 内部性能监控 | `ant` (内部) |
99+
| `VerifyPlanExecutionTool` | 计划验证 | `CLAUDE_CODE_VERIFY_PLAN` |
100+
| `SendUserFileTool` | 向用户发送文件 | `KAIROS` |
101+
| `SubscribePRTool` | GitHub PR 订阅 | `KAIROS_GITHUB_WEBHOOKS` |
102+
| `SuggestBackgroundPRTool` | 建议后台 PR | `KAIROS` |
103+
| `PushNotificationTool` | 推送通知 | `KAIROS` |
104+
| `CtxInspectTool` | 上下文检查 | `CONTEXT_COLLAPSE` |
105+
| `ListPeersTool` | 列出活跃对等方 | `UDS_INBOX` |
106+
| `DiscoverSkillsTool` | 技能发现 | `EXPERIMENTAL_SKILL_SEARCH` |
107+
108+
</details>
109+
110+
### 文本/Prompt 资源(~6 个文件)
111+
112+
| File | Purpose |
113+
|------|---------|
114+
| `yolo-classifier-prompts/auto_mode_system_prompt.txt` | 自动模式分类器系统提示 |
115+
| `yolo-classifier-prompts/permissions_anthropic.txt` | Anthropic 内部权限提示 |
116+
| `yolo-classifier-prompts/permissions_external.txt` | 外部用户权限提示 |
117+
| `verify/SKILL.md` | 验证技能文档 |
118+
| `verify/examples/cli.md` | CLI 验证示例 |
119+
| `verify/examples/server.md` | 服务端验证示例 |
120+
121+
### 为什么缺失
122+
123+
```
124+
Anthropic 内部 Monorepo 发布的 npm 包
125+
────────────────────── ─────────────────────
126+
feature('DAEMON') → true ──构建──→ feature('DAEMON') → false
127+
↓ ↓
128+
daemon/main.js ← 包含 ──打包──→ daemon/main.js ← 删除 (DCE)
129+
tools/REPLTool ← 包含 ──打包──→ tools/REPLTool ← 删除 (DCE)
130+
proactive/ ← 包含 ──打包──→ (被引用但 src/ 中不存在)
131+
```
132+
133+
Bun 的 `feature()`**编译时内建函数**
134+
- 在 Anthropic 内部构建中返回 `true` → 代码保留在 bundle 中
135+
- 在发布构建中返回 `false` → 代码被死代码消除
136+
- 108 个模块在已发布的制品中根本不存在
137+
138+
---
139+
140+
## 版权与免责声明
141+
142+
```
143+
Copyright (c) Anthropic PBC. All rights reserved.
144+
145+
本仓库中所有源码均为 Anthropic 的知识产权。
146+
本仓库仅用于技术研究和教育目的。严禁商业使用。
147+
148+
如果您是版权所有者并认为本仓库侵犯了您的权利,
149+
请联系仓库所有者立即删除。
150+
```
151+
152+
---
153+
154+
## 统计数据
155+
156+
| 项目 | 数量 |
157+
|------|------|
158+
| 源文件 (.ts/.tsx) | ~1,884 |
159+
| 代码行数 | ~512,664 |
160+
| 最大单文件 | `query.ts` (~785KB) |
161+
| 内置工具 | ~40+ |
162+
| 斜杠命令 | ~80+ |
163+
| 依赖 (node_modules) | ~192 个包 |
164+
| 运行时 | Bun(编译为 Node.js >= 18 bundle)|
165+
166+
---
167+
168+
## 代理模式
169+
170+
```
171+
核心循环
172+
========
173+
174+
用户 --> messages[] --> Claude API --> 响应
175+
|
176+
stop_reason == "tool_use"?
177+
/ \
178+
是 否
179+
| |
180+
执行工具 返回文本
181+
追加 tool_result
182+
循环回退 -----------------> messages[]
183+
184+
185+
这就是最小的代理循环。Claude Code 在此循环上
186+
包裹了生产级线束:权限、流式传输、并发、
187+
压缩、子代理、持久化和 MCP。
188+
```
189+
190+
---
191+
192+
## 目录参考
193+
194+
```
195+
src/
196+
├── main.tsx # REPL 引导程序,4,683 行
197+
├── QueryEngine.ts # SDK/headless 查询生命周期引擎
198+
├── query.ts # 主代理循环 (785KB,最大文件)
199+
├── Tool.ts # 工具接口 + buildTool 工厂
200+
├── Task.ts # 任务类型、ID、状态基类
201+
├── tools.ts # 工具注册、预设、过滤
202+
├── commands.ts # 斜杠命令定义
203+
├── context.ts # 用户输入上下文
204+
├── cost-tracker.ts # API 成本累积
205+
├── setup.ts # 首次运行设置流程
206+
207+
├── bridge/ # Claude Desktop / 远程桥接
208+
│ ├── bridgeMain.ts # 会话生命周期管理器
209+
│ ├── bridgeApi.ts # HTTP 客户端
210+
│ ├── bridgeConfig.ts # 连接配置
211+
│ ├── bridgeMessaging.ts # 消息中继
212+
│ ├── sessionRunner.ts # 进程生成
213+
│ ├── jwtUtils.ts # JWT 刷新
214+
│ ├── workSecret.ts # 认证令牌
215+
│ └── capacityWake.ts # 基于容量的唤醒
216+
217+
├── cli/ # CLI 基础设施
218+
│ ├── handlers/ # 命令处理器
219+
│ └── transports/ # I/O 传输 (stdio, structured)
220+
221+
├── commands/ # ~80 个斜杠命令
222+
├── components/ # React/Ink 终端 UI
223+
├── entrypoints/ # 应用入口点
224+
├── hooks/ # React hooks
225+
├── services/ # 业务逻辑层
226+
├── state/ # 应用状态
227+
├── tasks/ # 任务实现
228+
├── tools/ # 40+ 工具实现
229+
├── types/ # 类型定义
230+
├── utils/ # 工具函数(最大目录)
231+
└── vendor/ # 原生模块源码存根
232+
```
233+
234+
---
235+
236+
## 架构概览
237+
238+
```
239+
┌─────────────────────────────────────────────────────────────────────┐
240+
│ 入口层 │
241+
│ cli.tsx ──> main.tsx ──> REPL.tsx (交互式) │
242+
│ └──> QueryEngine.ts (headless/SDK) │
243+
└──────────────────────────────┬──────────────────────────────────────┘
244+
245+
246+
┌─────────────────────────────────────────────────────────────────────┐
247+
│ 查询引擎 │
248+
│ submitMessage(prompt) ──> AsyncGenerator<SDKMessage> │
249+
│ ├── fetchSystemPromptParts() ──> 组装系统提示词 │
250+
│ ├── processUserInput() ──> 处理 /命令 │
251+
│ ├── query() ──> 主代理循环 │
252+
│ │ ├── StreamingToolExecutor ──> 并行工具执行 │
253+
│ │ ├── autoCompact() ──> 上下文压缩 │
254+
│ │ └── runTools() ──> 工具编排 │
255+
│ └── yield SDKMessage ──> 流式传输给消费者 │
256+
└──────────────────────────────┬──────────────────────────────────────┘
257+
```
258+
259+
---
260+
261+
## 构建说明
262+
263+
本源码**不能直接从本仓库编译**
264+
265+
- 缺少 `tsconfig.json`、构建脚本和 Bun bundler 配置
266+
- `feature()` 调用是 Bun 编译时内建函数 — 在打包时解析
267+
- `MACRO.VERSION` 在构建时注入
268+
- `process.env.USER_TYPE === 'ant'` 部分是 Anthropic 内部的
269+
- 编译后的 `cli.js` 是一个自包含的 12MB bundle,只需 Node.js >= 18
270+
271+
**构建说明详见 [QUICKSTART.md](QUICKSTART.md)**
272+
273+
---
274+
275+
## 许可证
276+
277+
本仓库中所有源码版权归 **Anthropic PBC** 所有。本仓库仅用于技术研究和教育目的。完整许可条款请参阅原始 npm 包。

0 commit comments

Comments
 (0)