Claude Code 系统提示词完整解析
本项目是从 Claude Code CLI 源码中提取的系统提示词(System Prompts)完整解析,包含英文原文、中文翻译和设计分析。
Claude Code 的系统提示词总量约 40K+ tokens,分布在 10+ 个源文件中,涵盖身份定义、任务执行、工具使用、安全策略、Agent 系统、自主工作模式等方方面面。本项目对这些提示词进行了系统性的整理、翻译和架构分析。
提示词架构概览
Section titled “提示词架构概览” 提示词组装流程 ==============
┌──────────────────────────────────────────────┐ │ buildEffectiveSystemPrompt() │ │ │ │ 优先级链(高 → 低): │ │ ┌─────────────────────────────────────────┐ │ │ │ 0. Override — loop 模式完全替换 │ │ │ │ 1. Coordinator — 协调器模式专用 │ │ │ │ 2. Agent — Agent 定义的系统提示词 │ │ │ │ 3. Custom — --system-prompt 参数 │ │ │ │ 4. Default — 默认系统提示词 │ │ │ │ 5. Append — appendSystemPrompt 追加 │ │ │ └─────────────────────────────────────────┘ │ └──────────────────────────────────────────────┘ │ ▼ ┌──────────────────────────────────────────────┐ │ getSystemPrompt() 主入口 │ │ │ │ ┌──────────── 静态部分 ─────────────┐ │ │ │ (跨用户可缓存,scope: 'global') │ │ │ │ │ │ │ │ 1. getSimpleIntroSection() │ │ │ │ 2. getSimpleSystemSection() │ │ │ │ 3. getSimpleDoingTasksSection() │ │ │ │ 4. getActionsSection() │ │ │ │ 5. getUsingYourToolsSection() │ │ │ │ 6. getSimpleToneAndStyleSection() │ │ │ │ 7. getOutputEfficiencySection() │ │ │ └────────────────────────────────────┘ │ │ │ │ ═══ SYSTEM_PROMPT_DYNAMIC_BOUNDARY ═══ │ │ │ │ ┌──────────── 动态部分 ─────────────┐ │ │ │ (会话特定,每次可能不同) │ │ │ │ │ │ │ │ 8. Session-specific guidance │ │ │ │ 9. Memory prompt │ │ │ │ 10. Ant model override │ │ │ │ 11. Environment info │ │ │ │ 12. Language section │ │ │ │ 13. Output style │ │ │ │ 14. MCP instructions (uncached) │ │ │ │ 15. Scratchpad │ │ │ │ 16. Function result clearing │ │ │ │ 17. Summarize tool results │ │ │ │ ...更多动态 section │ │ │ └────────────────────────────────────┘ │ └──────────────────────────────────────────────┘核心设计思想: 静态部分使用 cacheScope: 'global' 在所有用户间共享缓存(Blake2b hash 前缀匹配),动态部分每次会话重新计算。systemPromptSection() 提供按需缓存(计算一次,/clear 或 /compact 时重置),DANGEROUS_uncachedSystemPromptSection() 则每个 turn 都重新计算(如 MCP instructions,因为服务器随时连接/断开)。
| 序号 | 目录/文件 | 内容简介 |
|---|---|---|
| 00 | 00-architecture.md | 提示词工程架构深度分析:组装流程、缓存边界、优先级系统、Feature Flag、内外部差异化 |
| 01 | 01-identity-and-intro/ | 身份与开场:Claude Code 的自我定义、Cyber Risk 指令、URL 生成限制 |
| 02 | 02-system-rules/ | 系统规则:Markdown 渲染、权限模式、system-reminder 标签、hooks、上下文自动压缩 |
| 03 | 03-doing-tasks/ | 任务执行准则:软件工程任务处理、反过度工程三连、评论哲学、忠实报告、安全编码 |
| 04 | 04-executing-actions-with-care/ | 谨慎执行:可逆性与爆炸半径评估、高风险操作确认、不可逆操作处理策略 |
| 05 | 05-tool-usage-guidelines/ | 工具使用指南:专用工具优先于 Bash、并行调用策略、任务管理工具 |
| 06 | 06-tone-and-style/ | 语气与风格:反 emoji 默认、代码引用格式、GitHub 链接格式、工具调用前措辞 |
| 07 | 07-output-efficiency/ | 输出效率:内外部双轨制——内部强调理解与清晰沟通,外部强调简洁直接 |
| 08 | 08-bash-tool/ | Bash 工具详细指令:沙箱策略、命令链、git 安全协议、PR 创建流程 |
| 09 | 09-agent-system/ | Agent 系统:Fork vs 传统 subagent、Agent 工具使用策略、Explore Agent 分流 |
| 10 | 10-specialized-agents/ | 专用 Agent:协调器(Coordinator)、探索 Agent(Explore)、验证 Agent(Verification) |
| 11 | 11-tool-descriptions/ | 工具描述:各内置工具的提示词定义(Read/Write/Edit/Glob/Grep/Bash/Agent 等) |
| 12 | 12-security-and-safety/ | 安全与安保:Cyber Risk 分类、沙箱默认策略、prompt injection 检测 |
| 13 | 13-environment-and-dynamic/ | 环境与动态内容:环境信息注入、语言偏好、输出风格、MCP 指令、Scratchpad |
| 14 | 14-autonomous-mode/ | 自主工作模式:Proactive 模式、tick 驱动唤醒、终端焦点感知、Brief 工具 |
| 15 | 15-insights-summary.md | 全局 Insight 汇总:架构、编码、安全、Agent、输出控制五大类别的设计洞察 |
| 指标 | 数值 |
|---|---|
| 提示词总量 | ~40K+ tokens |
| 源文件数量 | 10+ 个(主要在 constants/prompts.ts、constants/systemPromptSections.ts、各工具的 prompt.ts) |
| 静态 Section 数量 | 7 个(缓存边界之前) |
| 动态 Section 数量 | 10+ 个(通过 systemPromptSection() 注册) |
| 提示词优先级层级 | 6 层(Override > Coordinator > Agent > Custom > Default > Append) |
| Feature Flag 数量 | 10+ 个(通过 GrowthBook A/B 测试管理) |
| 内置 Agent 类型 | 5+ 个(Worker、Explore、Verification、Plan、Guide 等) |
| Cyber Risk 指令 | 由 Safeguards 团队独立维护,修改需专门审批 |
| 源文件路径 | 职责 |
|---|---|
constants/prompts.ts | 主提示词组装逻辑,包含 getSystemPrompt() 及所有 section 生成函数 |
constants/systemPromptSections.ts | Section 注册制基础设施:systemPromptSection() 和 DANGEROUS_uncachedSystemPromptSection() |
constants/cyberRiskInstruction.ts | Cyber Risk 安全指令,Safeguards 团队独立维护 |
utils/systemPrompt.ts | buildEffectiveSystemPrompt() 优先级选择逻辑 |
utils/betas.ts | Beta header 管理、全局缓存 scope 控制 |
utils/undercover.ts | Undercover 模式:隐藏模型名称/ID,防止内部信息泄漏到公开仓库 |
coordinator/coordinatorMode.ts | 协调器模式系统提示词 |
tools/AgentTool/built-in/verificationAgent.ts | 验证 Agent 系统提示词 |
tools/AgentTool/built-in/exploreAgent.ts | 探索 Agent 系统提示词 |
tools/AgentTool/forkSubagent.ts | Fork 子 agent 功能门控和定义 |
memdir/memdir.ts | 记忆系统提示词加载 |