Skip to content

Claude Code 系统提示词完整解析

本项目是从 Claude Code CLI 源码中提取的系统提示词(System Prompts)完整解析,包含英文原文、中文翻译和设计分析。

Claude Code 的系统提示词总量约 40K+ tokens,分布在 10+ 个源文件中,涵盖身份定义、任务执行、工具使用、安全策略、Agent 系统、自主工作模式等方方面面。本项目对这些提示词进行了系统性的整理、翻译和架构分析。


提示词组装流程
==============
┌──────────────────────────────────────────────┐
│ 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,因为服务器随时连接/断开)。


序号目录/文件内容简介
0000-architecture.md提示词工程架构深度分析:组装流程、缓存边界、优先级系统、Feature Flag、内外部差异化
0101-identity-and-intro/身份与开场:Claude Code 的自我定义、Cyber Risk 指令、URL 生成限制
0202-system-rules/系统规则:Markdown 渲染、权限模式、system-reminder 标签、hooks、上下文自动压缩
0303-doing-tasks/任务执行准则:软件工程任务处理、反过度工程三连、评论哲学、忠实报告、安全编码
0404-executing-actions-with-care/谨慎执行:可逆性与爆炸半径评估、高风险操作确认、不可逆操作处理策略
0505-tool-usage-guidelines/工具使用指南:专用工具优先于 Bash、并行调用策略、任务管理工具
0606-tone-and-style/语气与风格:反 emoji 默认、代码引用格式、GitHub 链接格式、工具调用前措辞
0707-output-efficiency/输出效率:内外部双轨制——内部强调理解与清晰沟通,外部强调简洁直接
0808-bash-tool/Bash 工具详细指令:沙箱策略、命令链、git 安全协议、PR 创建流程
0909-agent-system/Agent 系统:Fork vs 传统 subagent、Agent 工具使用策略、Explore Agent 分流
1010-specialized-agents/专用 Agent:协调器(Coordinator)、探索 Agent(Explore)、验证 Agent(Verification)
1111-tool-descriptions/工具描述:各内置工具的提示词定义(Read/Write/Edit/Glob/Grep/Bash/Agent 等)
1212-security-and-safety/安全与安保:Cyber Risk 分类、沙箱默认策略、prompt injection 检测
1313-environment-and-dynamic/环境与动态内容:环境信息注入、语言偏好、输出风格、MCP 指令、Scratchpad
1414-autonomous-mode/自主工作模式:Proactive 模式、tick 驱动唤醒、终端焦点感知、Brief 工具
1515-insights-summary.md全局 Insight 汇总:架构、编码、安全、Agent、输出控制五大类别的设计洞察

指标数值
提示词总量~40K+ tokens
源文件数量10+ 个(主要在 constants/prompts.tsconstants/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.tsSection 注册制基础设施:systemPromptSection()DANGEROUS_uncachedSystemPromptSection()
constants/cyberRiskInstruction.tsCyber Risk 安全指令,Safeguards 团队独立维护
utils/systemPrompt.tsbuildEffectiveSystemPrompt() 优先级选择逻辑
utils/betas.tsBeta header 管理、全局缓存 scope 控制
utils/undercover.tsUndercover 模式:隐藏模型名称/ID,防止内部信息泄漏到公开仓库
coordinator/coordinatorMode.ts协调器模式系统提示词
tools/AgentTool/built-in/verificationAgent.ts验证 Agent 系统提示词
tools/AgentTool/built-in/exploreAgent.ts探索 Agent 系统提示词
tools/AgentTool/forkSubagent.tsFork 子 agent 功能门控和定义
memdir/memdir.ts记忆系统提示词加载