Claude Code 源码泄漏事件
一、事件概述
2026年3月31日,Anthropic 官方 AI 编程 CLI 工具 Claude Code 的完整源代码被意外泄露。安全研究员 Chaofan Shou (@Fried_rice) 在 X (Twitter) 上公开披露了这一发现:
"Claude code source code has been leaked via a map file in their npm registry!"
这是继 OpenAI 系统提示词泄露后,AI 行业又一重大安全事件。
二、泄漏原因分析
2.1 技术根因:Source Map 文件暴露
Claude Code 的 npm 发布包中包含了一个 .map 源码映射文件,该文件包含了完整的、未混淆的 TypeScript 源代码。
Source Map 文件结构示例:
{
"version": 3,
"sources": ["../src/main.tsx", "../src/tools/BashTool.ts", "..."],
"sourcesContent": ["// 完整的原始源代码...", "..."],
"mappings": "AAAA,SAAS,OAAO..."
}
关键问题:
sourcesContent数组包含了所有原始源码- 任何人可通过
npm pack或直接浏览 npm 包内容获取 - 这不是新型攻击向量,但 Anthropic 仍未防范
2.2 错误链条
| 环节 | 问题 |
|---|---|
| 构建配置 | 未配置 bundler 跳过生产环境的 source map 生成 |
| 发布检查 | .npmignore 未排除 *.map 文件 |
| 质量门禁 | 无自动化检测敏感文件泄漏 |
| Bun bundler | 默认生成 source maps,未显式关闭 |
2.3 讽刺之处
Claude Code 内部有一个完整的 "Undercover Mode"(卧底模式) 系统,专门用于防止 Anthropic 内部信息泄漏。他们构建了一整套子系统来阻止 AI 在 git 提交中意外暴露内部代号……然后自己通过 .map 文件把整个源码发布出去了。
三、泄漏内容深度分析
3.1 代码规模
| 指标 | 数值 |
|---|---|
| 源码文件数 | ~1,900 个 TypeScript 文件 |
| 代码行数 | ~512,000 行 |
| 主要入口 | main.tsx (785KB) |
| 核心架构 | React + Ink 终端渲染 |
3.2 架构揭秘
3.2.1 核心组件
claude-code/
├── coordinator/ # 主编排循环 - 管理会话轮次、工具调用决策
├── QueryEngine.ts # Claude API 通信,处理流式响应
├── context/ # 上下文窗口管理,自动压缩
├── tools/ # 40+ 工具实现
├── ink/ # 基于 React/Ink 的终端渲染引擎
├── commands/ # 80+ 斜杠命令
├── services/ # API、MCP、LSP 等服务
├── skills/ # 可复用的提示模板系统
├── buddy/ # 伴侣精灵系统
└── vim/ # 完整 vim 模拟
3.2.2 工具系统(40+ 工具)
| 工具类别 | 工具名称 | 功能 |
|---|---|---|
| Shell 执行 | BashTool / PowerShellTool | 执行 shell 命令(支持沙箱) |
| 文件操作 | FileReadTool / FileEditTool / FileWriteTool | 文件读写编辑 |
| 搜索 | GlobTool / GrepTool | 文件搜索(原生 bfs/ugrep 加速) |
| 网络 | WebFetchTool / WebSearchTool / WebBrowserTool | 网页访问 |
| 代码智能 | LSPTool | Language Server Protocol 集成 |
| 子代理 | AgentTool | 生成自主子代理 |
| MCP | MCPTool / McpAuthTool | Model Context Protocol 支持 |
| 后台任务 | TaskCreateTool / TaskGetTool / TaskListTool | 后台任务管理 |
| 权限控制 | AskUserQuestionTool | 用户交互确认 |
3.2.3 斜杠命令(80+)
/compact— 压缩对话上下文/model— 切换模型/vim— 切换 vim 模式/cost— 显示 token 使用量/diff— 显示最近更改/plan— 进入规划模式/review— 代码审查/memory— 管理持久化记忆/voice— 语音输入模式/doctor— 诊断问题/security-review— 安全审查(仅内部)
四、未发布功能曝光
4.1 Buddy 伴侣精灵系统 🐾
这是最有趣的部分! Claude Code 内置了一个完整的"电子宠物"系统。
物种稀有度
| 稀有度 | 概率 | 物种 |
|---|---|---|
| Common | 60% | Pebblecrab, Dustbunny, Mossfrog, Twigling, Dewdrop, Puddlefish |
| Uncommon | 25% | Cloudferret, Gustowl, Bramblebear, Thornfox |
| Rare | 10% | Crystaldrake, Deepstag, Lavapup |
| Epic | 4% | Stormwyrm, Voidcat, Aetherling |
| Legendary | 1% | Cosmoshale, Nebulynx |
特殊机制
- Shiny 闪光变种:独立 1% 概率,与稀有度无关
- 传奇闪光概率:0.01%(1% × 1%)
- 确定性生成:同一用户永远获得相同的 Buddy(基 于 Mulberry32 PRNG + userId hash)
属性系统
每个 Buddy 拥有:
- 5 项属性:DEBUGGING, PATIENCE, CHAOS, WISDOM, SNARK(各 0-100)
- 6 种眼睛样式
- 8 种帽子选项(部分受稀有度限制)
- 灵魂描述:首次孵化时由 Claude 生成的个性描述
发布计划
代码中提到 2026年4月1-7日 作为预告窗口,2026年5月 全面发布。
4.2 KAIROS 主动助手模式
KAIROS 是一个 持久运行、主动行动 的 Claude 助手模式,不需要等待用户输入。
核心特性
| 特性 | 描述 |
|---|---|
| 后台运行 | 持续监控、记录日志、主动行动 |
| Tick 提示 | 定期接收 <tick> 提示,决定是否行动 |
| 阻塞预算 | 15 秒阻塞限制,超过则延迟执行 |
| Brief 模式 | 极简响应风格,适合持久助手 |
独占工具
| 工具 | 功能 |
|---|---|
| SendUserFile | 直接推送文件给用户(通知、摘要) |
| PushNotification | 发送推送通知到用户设备 |
| SubscribePR | 订阅并监控 PR 活动 |
4.3 ULTRAPLAN 深度规划模式
将复杂规划任务卸载到远程 Cloud Container Runtime (CCR) 会话,运行 Opus 4.6,给予最多 30 分钟思考时间。
工作流程
1. Claude Code 识别需要深度规划的任务
2. 启动远程 CCR 会话(tengu_ultraplan_model 配置)
3. 终端显示轮询状态(每 3 秒检查结果)
4. 浏览器 UI 展示规划过程,用户可批准/拒绝
5. 批准后通过 __ULTRAPLAN_TELEPORT_LOCAL__ "传送"结果
4.4 autoDream 记忆整合引擎
Claude Code 有一个叫做 "dream"(梦境) 的后台记忆整合引擎——让 Claude 做梦。
触发条件(三重门控)
| 门控 | 条件 |
|---|---|
| Time gate | 距上次 dream 24 小时 |
| Session gate | 至少 5 个会话 |
| Lock gate | 获取整合锁(防止并发 dream) |
四阶段流程
Phase 1 - Orient:定位记忆目录,读取 MEMORY.md,浏览现有主题文件
Phase 2 - Gather Recent Signal:从日志、漂流记忆、转录搜索收集新信息
Phase 3 - Consolidate:写入或更新记忆文件,转换相对日期为绝对日期,删除矛盾事实
Phase 4 - Prune and Index:保持 MEMORY.md 在 200 行/~25KB 以下
系统提示词:
"You are performing a dream - a reflective pass over your memory files. Synthesize what you've learned recently into durable, well-organized memories so that future sessions can orient quickly."
4.5 Undercover Mode(卧底模式)
Anthropic 员工(USER_TYPE === 'ant')使用 Claude Code 贡献开源项目时,此模式激活。
注入的系统提示
## UNDERCOVER MODE - CRITICAL
You are operating UNDERCOVER in a PUBLIC/OPEN-SOURCE repository. Your commit
messages, PR titles, and PR bodies MUST NOT contain ANY Anthropic-internal
information. Do not blow your cover.
NEVER include in commit messages or PR descriptions:
- Internal model codenames (animal names like Capybara, Tengu, etc.)
- Unreleased model version numbers (e.g., opus-4-7, sonnet-4-8)
- Internal repo or project names
- Internal tooling, Slack channels, or short links (e.g., go/cc, #claude-code-…)
- The phrase "Claude Code" or any mention that you are an AI
- Co-Authored-By lines or any other attribution