# code
**Repository Path**: phodit/code
## Basic Information
- **Project Name**: code
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2026-04-01
- **Last Updated**: 2026-04-01
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Claude Code 源代码快照
**据报道,2026年3月31日通过发布的源代码映射暴露的源代码快照的探索性镜像**
[
](#tech-stack)
[
](#tech-stack)
[
](#directory-structure)
[
](#-explore-with-mcp-server)
> 原始导入的快照保存在此存储库的 [`backup` 分支](https://github.com/777genius/claude-code-source-code/tree/backup) 中。`main` 分支包含添加的文档、工具和存储库元数据。
还可以查看这两个很酷的项目:
1. [claude_agent_teams_ui](https://github.com/777genius/claude_agent_teams_ui) - 你是CTO,代理是你的团队。他们自己处理任务,互相发送消息,审查彼此的代码。你只需要看看板和喝咖啡。
2. [claude-notifications-go](https://github.com/777genius/claude-notifications-go) - 🔔 Claude Code 的跨平台智能通知插件。6种类型。点击聚焦。1行安装。
---
## 目录
- [泄露经过](#how-it-leaked)
- [什么是 Claude Code?](#what-is-claude-code)
- [文档](#-documentation)
- [使用 MCP 服务器探索](#-explore-with-mcp-server)
- [目录结构](#directory-structure)
- [架构](#architecture)
- [工具系统](#1-tool-system)
- [命令系统](#2-command-system)
- [服务层](#3-service-layer)
- [桥接系统](#4-bridge-system)
- [权限系统](#5-permission-system)
- [功能标志](#6-feature-flags)
- [关键文件](#key-files)
- [技术栈](#tech-stack)
- [设计模式](#design-patterns)
- [GitPretty 设置](#gitpretty-setup)
- [贡献](#contributing)
- [免责声明](#disclaimer)
---
## 泄露经过
[Chaofan Shou (@Fried_rice)](https://x.com/Fried_rice) 发现,发布的 Claude Code npm 包包含一个 `.map` 文件,该文件引用了完整的、未混淆的 TypeScript 源代码 — 可从 Anthropic 的 R2 存储桶下载为 zip 文件。
> **"Claude 代码源代码已通过其 npm 注册表中的 map 文件泄露!"**
>
> — [@Fried_rice, 2026年3月31日](https://x.com/Fried_rice/status/2038894956459290963)
---
## 什么是 Claude Code?
Claude Code 是 Anthropic 的官方 CLI 工具,用于直接从终端与 Claude 交互:编辑文件、运行命令、搜索代码库、管理 git 工作流程等。此存储库包含源代码快照以及添加的文档、MCP 工具和存储库元数据,以帮助检查它。
| | |
|---|---|
| **泄露时间** | 2026-03-31 |
| **语言** | TypeScript (严格模式) |
| **运行时** | [Bun](https://bun.sh) |
| **终端 UI** | [React](https://react.dev) + [Ink](https://github.com/vadimdemedes/ink) |
| **规模** | ~1,900 文件 · 512,000+ 代码行 |
---
## 文档
有关深入指南,请参阅 [`docs/`](docs/) 目录:
| 指南 | 描述 |
|-------|-------------|
| **[架构](docs/architecture.md)** | 核心管道、启动序列、状态管理、渲染、数据流 |
| **[工具参考](docs/tools.md)** | 所有 ~40 个代理工具的完整目录,包含类别和权限模型 |
| **[命令参考](docs/commands.md)** | 所有 ~85 个斜杠命令按类别组织 |
| **[子系统指南](docs/subsystems.md)** | 深入探讨 Bridge、MCP、权限、插件、技能、任务、内存、语音 |
| **[探索指南](docs/exploration-guide.md)** | 如何导航代码库 — 学习路径、grep 模式、关键文件 |
另请参阅:[CONTRIBUTING.md](CONTRIBUTING.md) · [MCP Server README](mcp-server/README.md)
---
## 使用 MCP 服务器探索
此存储库还附带一个 [MCP 服务器](https://modelcontextprotocol.io/),允许任何 MCP 兼容客户端(Claude Code、Claude Desktop、VS Code Copilot、Cursor)交互式探索快照。
### 从 npm 安装
MCP 服务器在 npm 上发布为 [`claude-code-explorer-mcp`](https://www.npmjs.com/package/claude-code-explorer-mcp) — 无需克隆存储库:
```bash
# Claude Code
claude mcp add claude-code-explorer -- npx -y claude-code-explorer-mcp
```
### 一行式设置(从源代码)
```bash
git clone https://github.com/777genius/claude-code-source-code.git ~/claude-code-source-code \
&& cd ~/claude-code-source-code/mcp-server \
&& npm install && npm run build \
&& claude mcp add claude-code-explorer -- node ~/claude-code-source-code/mcp-server/dist/index.js
```
分步设置
```bash
# 1. 克隆存储库
git clone https://github.com/777genius/claude-code-source-code.git
cd claude-code-source-code/mcp-server
# 2. 安装和构建
npm install && npm run build
# 3. 注册到 Claude Code
claude mcp add claude-code-explorer -- node /absolute/path/to/claude-code-source-code/mcp-server/dist/index.js
```
将 `/absolute/path/to/claude-code-source-code` 替换为你的实际克隆路径。
VS Code / Cursor / Claude Desktop 配置
**VS Code** — 添加到 `.vscode/mcp.json`:
```json
{
"servers": {
"claude-code-explorer": {
"type": "stdio",
"command": "node",
"args": ["${workspaceFolder}/mcp-server/dist/index.js"],
"env": { "CLAUDE_CODE_SRC_ROOT": "${workspaceFolder}/src" }
}
}
}
```
**Claude Desktop** — 添加到你的配置文件:
```json
{
"mcpServers": {
"claude-code-explorer": {
"command": "node",
"args": ["/absolute/path/to/claude-code-source-code/mcp-server/dist/index.js"],
"env": { "CLAUDE_CODE_SRC_ROOT": "/absolute/path/to/claude-code-source-code/src" }
}
}
}
```
**Cursor** — 添加到 `~/.cursor/mcp.json`(与 Claude Desktop 相同格式)。
### 可用工具和提示
| 工具 | 描述 |
|------|-------------|
| `list_tools` | 列出所有 ~40 个代理工具及其源文件 |
| `list_commands` | 列出所有 ~50 个斜杠命令及其源文件 |
| `get_tool_source` | 读取任何工具的完整源代码(例如 BashTool、FileEditTool) |
| `get_command_source` | 读取任何斜杠命令的源代码(例如 review、mcp) |
| `read_source_file` | 按路径读取 `src/` 中的任何文件 |
| `search_source` | 在整个源代码树中进行 grep 搜索 |
| `list_directory` | 浏览 `src/` 目录 |
| `get_architecture` | 高级架构概览 |
| 提示 | 描述 |
|--------|-------------|
| `explain_tool` | 深入探讨特定工具的工作原理 |
| `explain_command` | 了解斜杠命令的实现 |
| `architecture_overview` | 完整架构的导览 |
| `how_does_it_work` | 解释任何子系统(权限、MCP、桥接等) |
| `compare_tools` | 两个工具的并排比较 |
**尝试询问:** *"BashTool 如何工作?"* · *"搜索权限检查的位置"* · *"显示 /review 命令的源代码"*
### 自定义源代码路径 / 移除
```bash
# 自定义源代码位置
claude mcp add claude-code-explorer -e CLAUDE_CODE_SRC_ROOT=/path/to/src -- node /path/to/mcp-server/dist/index.js
# 移除
claude mcp remove claude-code-explorer
```
---
## 目录结构
```
src/
├── main.tsx # 入口点 — Commander.js CLI 解析器 + React/Ink 渲染器
├── QueryEngine.ts # 核心 LLM API 调用器 (~46K 行)
├── Tool.ts # 工具类型定义 (~29K 行)
├── commands.ts # 命令注册表 (~25K 行)
├── tools.ts # 工具注册表
├── context.ts # 系统/用户上下文收集
├── cost-tracker.ts # 令牌成本跟踪
│
├── tools/ # 代理工具实现 (~40)
├── commands/ # 斜杠命令实现 (~50)
├── components/ # Ink UI 组件 (~140)
├── services/ # 外部服务集成
├── hooks/ # React hooks(包括权限检查)
├── types/ # TypeScript 类型定义
├── utils/ # 实用函数
├── screens/ # 全屏 UI(Doctor、REPL、Resume)
│
├── bridge/ # IDE 集成(VS Code、JetBrains)
├── coordinator/ # 多代理编排
├── plugins/ # 插件系统
├── skills/ # 技能系统
├── server/ # 服务器模式
├── remote/ # 远程会话
├── memdir/ # 持久内存目录
├── tasks/ # 任务管理
├── state/ # 状态管理
│
├── voice/ # 语音输入
├── vim/ # Vim 模式
├── keybindings/ # 键绑定配置
├── schemas/ # 配置模式(Zod)
├── migrations/ # 配置迁移
├── entrypoints/ # 初始化逻辑
├── query/ # 查询管道
├── ink/ # Ink 渲染器包装器
├── buddy/ # 伙伴精灵(彩蛋 🐣)
├── native-ts/ # 原生 TypeScript 工具
├── outputStyles/ # 输出样式
└── upstreamproxy/ # 代理配置
```
---
## 架构
### 1. 工具系统
> `src/tools/` — Claude 可以调用的每个工具都是一个自包含的模块,具有自己的输入模式、权限模型和执行逻辑。
| 工具 | 描述 |
|---|---|
| **文件 I/O** | |
| `FileReadTool` | 读取文件(图像、PDF、笔记本) |
| `FileWriteTool` | 创建/覆盖文件 |
| `FileEditTool` | 部分修改(字符串替换) |
| `NotebookEditTool` | Jupyter 笔记本编辑 |
| **搜索** | |
| `GlobTool` | 文件模式匹配 |
| `GrepTool` | 基于 ripgrep 的内容搜索 |
| `WebSearchTool` | 网络搜索 |
| `WebFetchTool` | 获取 URL 内容 |
| **执行** | |
| `BashTool` | Shell 命令执行 |
| `SkillTool` | 技能执行 |
| `MCPTool` | MCP 服务器工具调用 |
| `LSPTool` | 语言服务器协议集成 |
| **代理和团队** | |
| `AgentTool` | 子代理生成 |
| `SendMessageTool` | 代理间消息传递 |
| `TeamCreateTool` / `TeamDeleteTool` | 团队管理 |
| `TaskCreateTool` / `TaskUpdateTool` | 任务管理 |
| **模式和状态** | |
| `EnterPlanModeTool` / `ExitPlanModeTool` | 计划模式切换 |
| `EnterWorktreeTool` / `ExitWorktreeTool` | Git worktree 隔离 |
| `ToolSearchTool` | 延迟工具发现 |
| `SleepTool` | 主动模式等待 |
| `CronCreateTool` | 定时触发器 |
| `RemoteTriggerTool` | 远程触发器 |
| `SyntheticOutputTool` | 结构化输出生成 |
### 2. 命令系统
> `src/commands/` — 在 REPL 中使用 `/` 调用的面向用户的斜杠命令。
| 命令 | 描述 | | 命令 | 描述 |
|---|---|---|---|---|
| `/commit` | Git 提交 | | `/memory` | 持久内存 |
| `/review` | 代码审查 | | `/skills` | 技能管理 |
| `/compact` | 上下文压缩 | | `/tasks` | 任务管理 |
| `/mcp` | MCP 服务器管理 | | `/vim` | Vim 模式切换 |
| `/config` | 设置 | | `/diff` | 查看更改 |
| `/doctor` | 环境诊断 | | `/cost` | 检查使用成本 |
| `/login` / `/logout` | 认证 | | `/theme` | 更改主题 |
| `/context` | 上下文可视化 | | `/share` | 共享会话 |
| `/pr_comments` | PR 评论 | | `/resume` | 恢复会话 |
| `/desktop` | 桌面切换 | | `/mobile` | 移动设备切换 |
### 3. 服务层
> `src/services/` — 外部集成和核心基础设施。
| 服务 | 描述 |
|---|---|
| `api/` | Anthropic API 客户端、文件 API、引导 |
| `mcp/` | 模型上下文协议连接和管理 |
| `oauth/` | OAuth 2.0 认证 |
| `lsp/` | 语言服务器协议管理器 |
| `analytics/` | GrowthBook 功能标志和分析 |
| `plugins/` | 插件加载器 |
| `compact/` | 对话上下文压缩 |
| `extractMemories/` | 自动内存提取 |
| `teamMemorySync/` | 团队内存同步 |
| `tokenEstimation.ts` | 令牌计数估计 |
| `policyLimits/` | 组织策略限制 |
| `remoteManagedSettings/` | 远程管理设置 |
### 4. 桥接系统
> `src/bridge/` — 连接 IDE 扩展(VS Code、JetBrains)和 CLI 的双向通信层。
关键文件:`bridgeMain.ts`(主循环)· `bridgeMessaging.ts`(协议)· `bridgePermissionCallbacks.ts`(权限回调)· `replBridge.ts`(REPL 会话)· `jwtUtils.ts`(JWT 认证)· `sessionRunner.ts`(会话执行)
### 5. 权限系统
> `src/hooks/toolPermission/` — 在每次工具调用时检查权限。
根据配置的权限模式提示用户批准/拒绝或自动解决:`default`、`plan`、`bypassPermissions`、`auto` 等。
### 6. 功能标志
通过 Bun 的 `bun:bundle` 在构建时消除死代码:
```typescript
import { feature } from 'bun:bundle'
const voiceCommand = feature('VOICE_MODE')
? require('./commands/voice/index.js').default
: null
```
值得注意的标志:`PROACTIVE` · `KAIROS` · `BRIDGE_MODE` · `DAEMON` · `VOICE_MODE` · `AGENT_TRIGGERS` · `MONITOR_TOOL`
---
## 关键文件
| 文件 | 行数 | 用途 |
|------|------:|---------|
| `QueryEngine.ts` | ~46K | 核心 LLM API 引擎 — 流式处理、工具循环、思考模式、重试、令牌计数 |
| `Tool.ts` | ~29K | 所有工具的基础类型/接口 — 输入模式、权限、进度状态 |
| `commands.ts` | ~25K | 命令注册和执行,带有按环境条件导入 |
| `main.tsx` | — | CLI 解析器 + React/Ink 渲染器;在启动时并行处理 MDM、钥匙串和 GrowthBook |
---
## 技术栈
| 类别 | 技术 |
|---|---|
| 运行时 | [Bun](https://bun.sh) |
| 语言 | TypeScript(严格模式) |
| 终端 UI | [React](https://react.dev) + [Ink](https://github.com/vadimdemedes/ink) |
| CLI 解析 | [Commander.js](https://github.com/tj/commander.js)(额外类型) |
| 模式验证 | [Zod v4](https://zod.dev) |
| 代码搜索 | [ripgrep](https://github.com/BurntSushi/ripgrep)(通过 GrepTool) |
| 协议 | [MCP SDK](https://modelcontextprotocol.io) · LSP |
| API | [Anthropic SDK](https://docs.anthropic.com) |
| 遥测 | OpenTelemetry + gRPC |
| 功能标志 | GrowthBook |
| 认证 | OAuth 2.0 · JWT · macOS Keychain |
---
## 设计模式
并行预取 — 启动优化
MDM 设置、钥匙串读取和 API 预连接作为副作用在重模块评估之前并行触发:
```typescript
// main.tsx
startMdmRawRead()
startKeychainPrefetch()
```
延迟加载 — 推迟重模块
OpenTelemetry(~400KB)和 gRPC(~700KB)仅在需要时通过动态 `import()` 加载。
代理群 — 多代理编排
子代理通过 `AgentTool` 生成,由 `coordinator/` 处理编排。`TeamCreateTool` 启用团队级并行工作。
技能系统 — 可重用工作流
在 `skills/` 中定义并通过 `SkillTool` 执行。用户可以添加自定义技能。
插件架构 — 可扩展性
通过 `plugins/` 子系统加载内置和第三方插件。
---
## GitPretty 设置
在 GitHub 的文件 UI 中显示每个文件的表情提交消息
```bash
# 应用表情提交
bash ./gitpretty-apply.sh .
# 可选:为未来提交安装钩子
bash ./gitpretty-apply.sh . --hooks
# 照常推送
git push origin main
```
---
## 贡献
欢迎对文档、MCP 服务器和探索工具的贡献。对 `src/` 下的存档快照的更改不是默认贡献路径。请参阅 [CONTRIBUTING.md](CONTRIBUTING.md) 了解指南。
> **注意:** `src/` 目录是存档的源代码快照,通常应保持不变。
---
## 免责声明
此存储库存档了据报道于 **2026年3月31日** 通过 Anthropic 的 npm 分发暴露的源代码快照。它提供用于研究、文档和围绕快照的探索工具。原始 Claude Code 源代码仍然是 [Anthropic](https://www.anthropic.com) 的财产,这不是官方发布,此存储库不授予对 Anthropic 原始代码的任何权利。如果你选择使用或重新分发任何存档材料,你有责任自行评估法律影响。如有任何意见,请联系 [nichxbt](https://www.x.com/nichxbt)。