mirror of
https://github.com/sanbuphy/claude-code-source-code.git
synced 2026-04-03 11:34:54 +08:00
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 <noreply@anthropic.com>
This commit is contained in:
28
README.md
28
README.md
@@ -3,6 +3,19 @@
|
||||
> Extracted from npm package `@anthropic-ai/claude-code` version **2.1.88**.
|
||||
> 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.
|
||||
|
||||
**Language**: **English** | [中文](README_CN.md)
|
||||
|
||||
---
|
||||
|
||||
> **Deep Analysis Reports**: Full source code analysis reports are available in the [`docs/`](docs/) directory (bilingual EN/ZH):
|
||||
> - Telemetry & Privacy (opt-out-free data collection pipeline)
|
||||
> - Hidden Features & Model Codenames (Tengu, Capybara, Fennec, Numbat)
|
||||
> - Undercover Mode (AI attribution stripping in open-source contributions)
|
||||
> - Remote Control & Killswitches (managed settings, feature flags)
|
||||
> - Future Roadmap (Numbat model, KAIROS autonomous mode, voice input)
|
||||
>
|
||||
> **English**: [`docs/en/`](docs/en/) | **中文**: [`docs/zh/`](docs/zh/)
|
||||
|
||||
---
|
||||
|
||||
## Missing Modules Notice (108 modules)
|
||||
@@ -15,6 +28,9 @@
|
||||
|
||||
These modules have no source files anywhere in the npm package. They are internal Anthropic infrastructure.
|
||||
|
||||
<details>
|
||||
<summary>Click to expand full list</summary>
|
||||
|
||||
| Module | Purpose | Feature Gate |
|
||||
|--------|---------|-------------|
|
||||
| `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
|
||||
| `udsClient.js` / `udsMessaging.js` | UDS messaging client | `UDS_INBOX` |
|
||||
| `systemThemeWatcher.js` | Theme watcher | `AUTO_THEME` |
|
||||
|
||||
</details>
|
||||
|
||||
### Feature-Gated Tools (~20 modules, DCE'd from bundle)
|
||||
|
||||
These tools have type signatures in `sdk-tools.d.ts` but their implementations were stripped at compile time.
|
||||
|
||||
<details>
|
||||
<summary>Click to expand full list</summary>
|
||||
|
||||
| Tool | Purpose | Feature Gate |
|
||||
|------|---------|-------------|
|
||||
| `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
|
||||
| `ListPeersTool` | List active peers | `UDS_INBOX` |
|
||||
| `DiscoverSkillsTool` | Skill discovery | `EXPERIMENTAL_SKILL_SEARCH` |
|
||||
|
||||
</details>
|
||||
|
||||
### Text/Prompt Assets (~6 files)
|
||||
|
||||
These are internal prompt templates and documentation, never published.
|
||||
|
||||
<details>
|
||||
<summary>Click to expand</summary>
|
||||
|
||||
| File | Purpose |
|
||||
|------|---------|
|
||||
| `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.
|
||||
| `verify/examples/cli.md` | CLI verification examples |
|
||||
| `verify/examples/server.md` | Server verification examples |
|
||||
|
||||
</details>
|
||||
|
||||
### Why They're Missing
|
||||
|
||||
```
|
||||
|
||||
277
README_CN.md
Normal file
277
README_CN.md
Normal file
@@ -0,0 +1,277 @@
|
||||
# Claude Code v2.1.88 — 源码分析
|
||||
|
||||
> 从 npm 包 `@anthropic-ai/claude-code` **2.1.88** 版本中提取。
|
||||
> 发布的包只有一个打包后的 `cli.js`(~12MB)。本仓库的 `src/` 目录包含从 npm 包中解包的 **TypeScript 源码**。
|
||||
|
||||
**语言**: [English](README.md) | **中文**
|
||||
|
||||
---
|
||||
|
||||
> **深度分析文档**: 完整的源码分析报告已发布在 [`docs/`](docs/) 目录下,包含中英双语版本:
|
||||
> - 遥测与隐私(无法退出的数据收集管道)
|
||||
> - 隐藏功能与模型代号(Tengu、Capybara、Fennec、Numbat)
|
||||
> - 卧底模式(在开源项目中隐藏 AI 身份)
|
||||
> - 远程控制与紧急开关(托管设置、feature flag)
|
||||
> - 未来路线图(Numbat 模型、KAIROS 自主模式、语音输入)
|
||||
>
|
||||
> **英文文档**: [`docs/en/`](docs/en/) | **中文文档**: [`docs/zh/`](docs/zh/)
|
||||
|
||||
---
|
||||
|
||||
## 缺失模块说明(108 个模块)
|
||||
|
||||
> **源码不完整。** 108 个被 `feature()` 门控的模块**未包含**在 npm 包中。
|
||||
> 它们仅存在于 Anthropic 的内部 monorepo 中,在编译时被死代码消除。
|
||||
> **无法**从 `cli.js`、`sdk-tools.d.ts` 或任何已发布的制品中恢复。
|
||||
|
||||
### Anthropic 内部代码(~70 个模块,从未发布)
|
||||
|
||||
这些模块在 npm 包中没有任何源文件。它们是 Anthropic 内部基础设施。
|
||||
|
||||
<details>
|
||||
<summary>点击展开完整列表</summary>
|
||||
|
||||
| Module | Purpose | Feature Gate |
|
||||
|--------|---------|-------------|
|
||||
| `daemon/main.js` | 后台守护进程管理器 | `DAEMON` |
|
||||
| `daemon/workerRegistry.js` | 守护进程 worker 注册 | `DAEMON` |
|
||||
| `proactive/index.js` | 主动通知系统 | `PROACTIVE` |
|
||||
| `contextCollapse/index.js` | 上下文折叠服务(实验性) | `CONTEXT_COLLAPSE` |
|
||||
| `contextCollapse/operations.js` | 折叠操作 | `CONTEXT_COLLAPSE` |
|
||||
| `contextCollapse/persist.js` | 折叠持久化 | `CONTEXT_COLLAPSE` |
|
||||
| `skillSearch/featureCheck.js` | 远程技能特性检查 | `EXPERIMENTAL_SKILL_SEARCH` |
|
||||
| `skillSearch/remoteSkillLoader.js` | 远程技能加载器 | `EXPERIMENTAL_SKILL_SEARCH` |
|
||||
| `skillSearch/remoteSkillState.js` | 远程技能状态 | `EXPERIMENTAL_SKILL_SEARCH` |
|
||||
| `skillSearch/telemetry.js` | 技能搜索遥测 | `EXPERIMENTAL_SKILL_SEARCH` |
|
||||
| `skillSearch/localSearch.js` | 本地技能搜索 | `EXPERIMENTAL_SKILL_SEARCH` |
|
||||
| `skillSearch/prefetch.js` | 技能预取 | `EXPERIMENTAL_SKILL_SEARCH` |
|
||||
| `coordinator/workerAgent.js` | 多代理协调器 worker | `COORDINATOR_MODE` |
|
||||
| `bridge/peerSessions.js` | 桥接对等会话管理 | `BRIDGE_MODE` |
|
||||
| `assistant/index.js` | KAIROS 助手模式 | `KAIROS` |
|
||||
| `assistant/AssistantSessionChooser.js` | 助手会话选择器 | `KAIROS` |
|
||||
| `compact/reactiveCompact.js` | 响应式上下文压缩 | `CACHED_MICROCOMPACT` |
|
||||
| `compact/snipCompact.js` | 基于裁剪的压缩 | `HISTORY_SNIP` |
|
||||
| `compact/snipProjection.js` | 裁剪投影 | `HISTORY_SNIP` |
|
||||
| `compact/cachedMCConfig.js` | 缓存微压缩配置 | `CACHED_MICROCOMPACT` |
|
||||
| `sessionTranscript/sessionTranscript.js` | 会话转录服务 | `TRANSCRIPT_CLASSIFIER` |
|
||||
| `commands/agents-platform/index.js` | 内部代理平台 | `ant` (内部) |
|
||||
| `commands/assistant/index.js` | 助手命令 | `KAIROS` |
|
||||
| `commands/buddy/index.js` | Buddy 系统通知 | `BUDDY` |
|
||||
| `commands/fork/index.js` | Fork 子代理命令 | `FORK_SUBAGENT` |
|
||||
| `commands/peers/index.js` | 多对等命令 | `BRIDGE_MODE` |
|
||||
| `commands/proactive.js` | 主动命令 | `PROACTIVE` |
|
||||
| `commands/remoteControlServer/index.js` | 远程控制服务器 | `DAEMON` + `BRIDGE_MODE` |
|
||||
| `commands/subscribe-pr.js` | GitHub PR 订阅 | `KAIROS_GITHUB_WEBHOOKS` |
|
||||
| `commands/torch.js` | 内部调试工具 | `TORCH` |
|
||||
| `commands/workflows/index.js` | 工作流命令 | `WORKFLOW_SCRIPTS` |
|
||||
| `jobs/classifier.js` | 内部任务分类器 | `TEMPLATES` |
|
||||
| `memdir/memoryShapeTelemetry.js` | 记忆形态遥测 | `MEMORY_SHAPE_TELEMETRY` |
|
||||
| `services/sessionTranscript/sessionTranscript.js` | 会话转录 | `TRANSCRIPT_CLASSIFIER` |
|
||||
| `tasks/LocalWorkflowTask/LocalWorkflowTask.js` | 本地工作流任务 | `WORKFLOW_SCRIPTS` |
|
||||
| `protectedNamespace.js` | 内部命名空间守卫 | `ant` (内部) |
|
||||
| `protectedNamespace.js` (envUtils) | 受保护命名空间运行时 | `ant` (内部) |
|
||||
| `coreTypes.generated.js` | 生成的核心类型 | `ant` (内部) |
|
||||
| `devtools.js` | 内部开发工具 | `ant` (内部) |
|
||||
| `attributionHooks.js` | 内部归属钩子 | `COMMIT_ATTRIBUTION` |
|
||||
| `systemThemeWatcher.js` | 系统主题监视器 | `AUTO_THEME` |
|
||||
| `udsClient.js` / `udsMessaging.js` | UDS 消息客户端 | `UDS_INBOX` |
|
||||
|
||||
</details>
|
||||
|
||||
### Feature-Gated 工具(~20 个模块)
|
||||
|
||||
这些工具有类型签名,但实现被编译时移除。
|
||||
|
||||
<details>
|
||||
<summary>点击展开完整列表</summary>
|
||||
|
||||
| Tool | Purpose | Feature Gate |
|
||||
|------|---------|-------------|
|
||||
| `REPLTool` | 交互式 REPL(VM 沙箱) | `ant` (内部) |
|
||||
| `SnipTool` | 上下文裁剪 | `HISTORY_SNIP` |
|
||||
| `SleepTool` | 代理循环中的休眠/延迟 | `PROACTIVE` / `KAIROS` |
|
||||
| `MonitorTool` | MCP 监控 | `MONITOR_TOOL` |
|
||||
| `OverflowTestTool` | 溢出测试 | `OVERFLOW_TEST_TOOL` |
|
||||
| `WorkflowTool` | 工作流执行 | `WORKFLOW_SCRIPTS` |
|
||||
| `WebBrowserTool` | 浏览器自动化 | `WEB_BROWSER_TOOL` |
|
||||
| `TerminalCaptureTool` | 终端捕获 | `TERMINAL_PANEL` |
|
||||
| `TungstenTool` | 内部性能监控 | `ant` (内部) |
|
||||
| `VerifyPlanExecutionTool` | 计划验证 | `CLAUDE_CODE_VERIFY_PLAN` |
|
||||
| `SendUserFileTool` | 向用户发送文件 | `KAIROS` |
|
||||
| `SubscribePRTool` | GitHub PR 订阅 | `KAIROS_GITHUB_WEBHOOKS` |
|
||||
| `SuggestBackgroundPRTool` | 建议后台 PR | `KAIROS` |
|
||||
| `PushNotificationTool` | 推送通知 | `KAIROS` |
|
||||
| `CtxInspectTool` | 上下文检查 | `CONTEXT_COLLAPSE` |
|
||||
| `ListPeersTool` | 列出活跃对等方 | `UDS_INBOX` |
|
||||
| `DiscoverSkillsTool` | 技能发现 | `EXPERIMENTAL_SKILL_SEARCH` |
|
||||
|
||||
</details>
|
||||
|
||||
### 文本/Prompt 资源(~6 个文件)
|
||||
|
||||
| File | Purpose |
|
||||
|------|---------|
|
||||
| `yolo-classifier-prompts/auto_mode_system_prompt.txt` | 自动模式分类器系统提示 |
|
||||
| `yolo-classifier-prompts/permissions_anthropic.txt` | Anthropic 内部权限提示 |
|
||||
| `yolo-classifier-prompts/permissions_external.txt` | 外部用户权限提示 |
|
||||
| `verify/SKILL.md` | 验证技能文档 |
|
||||
| `verify/examples/cli.md` | CLI 验证示例 |
|
||||
| `verify/examples/server.md` | 服务端验证示例 |
|
||||
|
||||
### 为什么缺失
|
||||
|
||||
```
|
||||
Anthropic 内部 Monorepo 发布的 npm 包
|
||||
────────────────────── ─────────────────────
|
||||
feature('DAEMON') → true ──构建──→ feature('DAEMON') → false
|
||||
↓ ↓
|
||||
daemon/main.js ← 包含 ──打包──→ daemon/main.js ← 删除 (DCE)
|
||||
tools/REPLTool ← 包含 ──打包──→ tools/REPLTool ← 删除 (DCE)
|
||||
proactive/ ← 包含 ──打包──→ (被引用但 src/ 中不存在)
|
||||
```
|
||||
|
||||
Bun 的 `feature()` 是**编译时内建函数**:
|
||||
- 在 Anthropic 内部构建中返回 `true` → 代码保留在 bundle 中
|
||||
- 在发布构建中返回 `false` → 代码被死代码消除
|
||||
- 108 个模块在已发布的制品中根本不存在
|
||||
|
||||
---
|
||||
|
||||
## 版权与免责声明
|
||||
|
||||
```
|
||||
Copyright (c) Anthropic PBC. All rights reserved.
|
||||
|
||||
本仓库中所有源码均为 Anthropic 的知识产权。
|
||||
本仓库仅用于技术研究和教育目的。严禁商业使用。
|
||||
|
||||
如果您是版权所有者并认为本仓库侵犯了您的权利,
|
||||
请联系仓库所有者立即删除。
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 统计数据
|
||||
|
||||
| 项目 | 数量 |
|
||||
|------|------|
|
||||
| 源文件 (.ts/.tsx) | ~1,884 |
|
||||
| 代码行数 | ~512,664 |
|
||||
| 最大单文件 | `query.ts` (~785KB) |
|
||||
| 内置工具 | ~40+ |
|
||||
| 斜杠命令 | ~80+ |
|
||||
| 依赖 (node_modules) | ~192 个包 |
|
||||
| 运行时 | Bun(编译为 Node.js >= 18 bundle)|
|
||||
|
||||
---
|
||||
|
||||
## 代理模式
|
||||
|
||||
```
|
||||
核心循环
|
||||
========
|
||||
|
||||
用户 --> messages[] --> Claude API --> 响应
|
||||
|
|
||||
stop_reason == "tool_use"?
|
||||
/ \
|
||||
是 否
|
||||
| |
|
||||
执行工具 返回文本
|
||||
追加 tool_result
|
||||
循环回退 -----------------> messages[]
|
||||
|
||||
|
||||
这就是最小的代理循环。Claude Code 在此循环上
|
||||
包裹了生产级线束:权限、流式传输、并发、
|
||||
压缩、子代理、持久化和 MCP。
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 目录参考
|
||||
|
||||
```
|
||||
src/
|
||||
├── main.tsx # REPL 引导程序,4,683 行
|
||||
├── QueryEngine.ts # SDK/headless 查询生命周期引擎
|
||||
├── query.ts # 主代理循环 (785KB,最大文件)
|
||||
├── Tool.ts # 工具接口 + buildTool 工厂
|
||||
├── Task.ts # 任务类型、ID、状态基类
|
||||
├── tools.ts # 工具注册、预设、过滤
|
||||
├── commands.ts # 斜杠命令定义
|
||||
├── context.ts # 用户输入上下文
|
||||
├── cost-tracker.ts # API 成本累积
|
||||
├── setup.ts # 首次运行设置流程
|
||||
│
|
||||
├── bridge/ # Claude Desktop / 远程桥接
|
||||
│ ├── bridgeMain.ts # 会话生命周期管理器
|
||||
│ ├── bridgeApi.ts # HTTP 客户端
|
||||
│ ├── bridgeConfig.ts # 连接配置
|
||||
│ ├── bridgeMessaging.ts # 消息中继
|
||||
│ ├── sessionRunner.ts # 进程生成
|
||||
│ ├── jwtUtils.ts # JWT 刷新
|
||||
│ ├── workSecret.ts # 认证令牌
|
||||
│ └── capacityWake.ts # 基于容量的唤醒
|
||||
│
|
||||
├── cli/ # CLI 基础设施
|
||||
│ ├── handlers/ # 命令处理器
|
||||
│ └── transports/ # I/O 传输 (stdio, structured)
|
||||
│
|
||||
├── commands/ # ~80 个斜杠命令
|
||||
├── components/ # React/Ink 终端 UI
|
||||
├── entrypoints/ # 应用入口点
|
||||
├── hooks/ # React hooks
|
||||
├── services/ # 业务逻辑层
|
||||
├── state/ # 应用状态
|
||||
├── tasks/ # 任务实现
|
||||
├── tools/ # 40+ 工具实现
|
||||
├── types/ # 类型定义
|
||||
├── utils/ # 工具函数(最大目录)
|
||||
└── vendor/ # 原生模块源码存根
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 架构概览
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────────┐
|
||||
│ 入口层 │
|
||||
│ cli.tsx ──> main.tsx ──> REPL.tsx (交互式) │
|
||||
│ └──> QueryEngine.ts (headless/SDK) │
|
||||
└──────────────────────────────┬──────────────────────────────────────┘
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────────────────────────────────────────────────┐
|
||||
│ 查询引擎 │
|
||||
│ submitMessage(prompt) ──> AsyncGenerator<SDKMessage> │
|
||||
│ ├── fetchSystemPromptParts() ──> 组装系统提示词 │
|
||||
│ ├── processUserInput() ──> 处理 /命令 │
|
||||
│ ├── query() ──> 主代理循环 │
|
||||
│ │ ├── StreamingToolExecutor ──> 并行工具执行 │
|
||||
│ │ ├── autoCompact() ──> 上下文压缩 │
|
||||
│ │ └── runTools() ──> 工具编排 │
|
||||
│ └── yield SDKMessage ──> 流式传输给消费者 │
|
||||
└──────────────────────────────┬──────────────────────────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 构建说明
|
||||
|
||||
本源码**不能直接从本仓库编译**:
|
||||
|
||||
- 缺少 `tsconfig.json`、构建脚本和 Bun bundler 配置
|
||||
- `feature()` 调用是 Bun 编译时内建函数 — 在打包时解析
|
||||
- `MACRO.VERSION` 在构建时注入
|
||||
- `process.env.USER_TYPE === 'ant'` 部分是 Anthropic 内部的
|
||||
- 编译后的 `cli.js` 是一个自包含的 12MB bundle,只需 Node.js >= 18
|
||||
|
||||
**构建说明详见 [QUICKSTART.md](QUICKSTART.md)。**
|
||||
|
||||
---
|
||||
|
||||
## 许可证
|
||||
|
||||
本仓库中所有源码版权归 **Anthropic PBC** 所有。本仓库仅用于技术研究和教育目的。完整许可条款请参阅原始 npm 包。
|
||||
Reference in New Issue
Block a user