解剖 Claude Code 的 Plan 子代理提示词:一个只读“软件架构师”如何产出实施计划
2026/9/7 17:42:26 网站建设 项目流程

解剖 Claude Code 的 Plan 子代理提示词:一个只读“软件架构师”如何产出实施计划

【免费下载链接】system_prompts_leaksExtracted system prompts from Anthropic - Claude Fable 5, Opus 5, Claude Design, Claude Code. OpenAI - ChatGPT GPT-5.6-Sol, Codex. Google - Gemini 3.5 Flash, 3.1 Pro, Antigravity. xAI - Grok, Cursor, Copilot, VS Code, Perplexity, and more. Updated regularly.项目地址: https://gitcode.com/GitHub_Trending/sy/system_prompts_leaks

本文基于 system_prompts_leaks 仓库中捕获的 Claude Code Plan 子代理系统提示词(Anthropic/claude-code/agents/Plan.md),逐段解析这个内置“软件架构师”代理的 frontmatter 配置、只读约束、四步规划流程和强制输出契约,并结合 Claude Code 主系统提示词中的 Agent 工具说明与 Plan Mode 工具链,讲清它在子代理体系中的定位、运行机制,以及你可以如何借鉴其提示词设计来编写自己的.claude/agents/*.md子代理。读完后,你将能够完整复述 Plan 代理的提示词结构,并理解其工具白名单、model: inherit等配置项背后的设计意图。

一、Plan 代理在 Claude Code 子代理体系中的定位

Plan 是 Claude Code 内置的一组子代理(subagent)之一。在本仓库捕获的 Claude Code 主系统提示词(以 Fable 5.1 版本为例,见 Anthropic/claude-code/claude-code-fable-5.1.md)中,Agent工具启动的可用代理类型被逐一列出,Plan 代理的运行时描述为:

Plan: Software architect agent for designing implementation plans. Use this when you need to plan the implementation strategy for a task. Returns step-by-step plans, identifies critical files, and considers architectural trade-offs. (Tools: All tools except Agent, Artifact, ArtifactComments, ArtifactData, ArtifactCheck, ExitPlanMode, Edit, Write, NotebookEdit)

同组并列的内置代理还包括:

  • Explore(Anthropic/claude-code/agents/Explore.md):快速只读搜索代理,定位文件与符号;
  • general-purpose(Anthropic/claude-code/agents/general-purpose.md):通用研究与多步任务代理;
  • claude-code-guide(Anthropic/claude-code/agents/claude-code-guide.md):回答 Claude Code / Agent SDK / API 使用问题的文档代理,其 frontmatter 使用model: haikutools: Bash, Read, WebFetch, WebSearch与 Plan 形成鲜明对比;
  • statusline-setup(Anthropic/claude-code/agents/statusline-setup.md):配置状态栏的代理,其 frontmatter 使用tools: [Read, Edit]model: sonnet,展示了另一种“精确授权少量工具”的写法;
  • claude(Anthropic/claude-code/agents/claude.md):兜底代理,带appendSystemPrompt: true,用于后台任务的进度播报与result:完成信号。

主系统提示词对 Agent 工具的说明(claude-code-fable-5.1.md#L299)证实了这些.md文件的性质:“每个 agent 类型的模型、推理强度和工具都来自它的定义(.claude/agents/*.md的 frontmatter 或 SDKagents)”。也就是说,本仓库收录的Plan.md并不是普通文档,而是一个真实生效的子代理定义文件:frontmatter 决定调度与权限,正文就是注入该子代理会话的系统提示词

二、frontmatter 配置逐项解析

Plan 代理的完整定义文件如下(Anthropic/claude-code/agents/Plan.md,frontmatter 部分):

--- name: Plan whenToUse: Software architect agent for designing implementation plans. Use this when you need to plan the implementation strategy for a task. Returns step-by-step plans, identifies critical files, and considers architectural trade-offs. disallowedTools: [Agent, Artifact, ExitPlanMode, Edit, Write, NotebookEdit] model: inherit ---

各字段的作用(结合主系统提示词中的 Agent 工具 schema 佐证):

字段取值作用
namePlan代理类型名。父会话通过Agent工具的subagent_type参数按此名称选择该代理(见 claude-code-fable-5.1.md#L315-L318 中subagent_type的说明)。
whenToUse一段自然语言描述写进父会话可用的代理列表中,供主循环模型判断“什么任务该派给它”。它同时回答了三个问题:角色(软件架构师)、触发时机(需要规划实施策略时)、产出形态(分步计划 + 关键文件 + 架构权衡)。
disallowedTools[Agent, Artifact, ExitPlanMode, Edit, Write, NotebookEdit]工具黑名单。与 Explore 代理(Explore.md#L5)完全相同的列表,构成“只读架构师/搜索者”这一类代理的权限基线。
modelinherit继承父会话的模型。主系统提示词中Agent工具的model参数说明:“省略时使用代理定义的 model……fork 除外——fork 总是继承父模型”,即 frontmatter 的model是这一层的默认值。

对比同目录其他代理的 frontmatter 可以看出三种配置范式:

  1. 继承 + 黑名单(Plan、Explore、general-purpose):model: inherit,用disallowedTools收窄能力;
  2. 精确白名单 + 固定模型(statusline-setup:tools: [Read, Edit]model: sonnet;claude-code-guide:tools: Bash, Read, WebFetch, WebSearchmodel: haiku):能力面最小的专用代理用便宜模型,降低成本;
  3. 追加提示词(claude:appendSystemPrompt: true):把正文追加而非替换系统提示词,用于需要叠加在默认行为上的场景。

一个值得注意的细节:disallowedTools里显式禁掉了Agent工具本身——从源码结构看,这是防止子代理再套娃派生下一级子代理,控制递归深度与 token 消耗;而主系统提示词在“反馈草稿”一节也把“spawned more subagents than the task warranted(派生了超出任务所需数量的子代理)”列为模型行为问题类别之一(subagent_overspawn,见 claude-code-fable-5.1.md#L2168),可见官方对子代理过度派生持明确的约束态度。

另一个被禁用的工具是ExitPlanMode。主系统提示词中EnterPlanMode/ExitPlanMode是“主循环专属”的规划模式工具链:EnterPlanMode用于在开始非平凡实现任务前切换到计划模式并请用户批准(claude-code-fable-5.1.md#L1322-L1356);ExitPlanMode则“读取你写好的计划文件、请求用户批准,本身不接受计划内容参数”(#L1477-L1495)。Plan 子代理被剥夺ExitPlanMode,意味着用户批准这个环节永远由父会话持有:子代理只负责产出计划文本,父会话决定何时向用户请求批准。这一设计与whenToUse中“plan the implementation strategy”(规划,而非执行)的定位严格对应。

三、全文只读约束:提示词层面的“第二道锁”

工具黑名单是第一道锁,但 Plan 提示词正文用一整段高规格约束做第二道锁(Plan.md#L10-L20):

=== CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS === This is a READ-ONLY planning task. You are STRICTLY PROHIBITED from: - Creating new files (no `Write`, `touch`, or file creation of any kind) - Modifying existing files (no `Edit` operations) - Deleting files (no `rm` or deletion) - Moving or copying files (no `mv` or `cp`) - Creating temporary files anywhere, including `/tmp` - Using redirect operators (`>`, `>>`, `|`) or heredocs to write to files - Running ANY commands that change system state Your role is EXCLUSIVELY to explore the codebase and design implementation plans. You do NOT have access to file editing tools - attempting to edit files will fail.

这段约束值得逐条品味,它封堵了工具黑名单覆盖不到的所有绕行路径

  • 不只有Write/Edit工具被禁用——touchmkdir等 shell 级别的创建动作同样被点名禁止;
  • 重定向操作符(>,>>,|)与 heredoc 被显式列出:这是 Bash 工具里最典型的“借命令写文件”路径;
  • /tmp下的临时文件都不许创建,杜绝“先写草稿再提交”的间接修改;
  • 最后用“你没有文件编辑工具,尝试编辑会失败”给出事实性陈述而非仅仅是命令——从提示词工程角度看,这告诉模型一个不可违背的环境事实,比单纯“不许”更能抑制幻觉式的调用尝试。

Explore 代理(Explore.md#L14-L24)使用几乎逐字相同的只读段落,说明这段“READ-ONLY MODE”文本是 Claude Code 只读类子代理的公共模板,而非 Plan 独有。

四、四步规划流程:理解 → 探索 → 设计 → 细化

提示词正文给出了编号清晰的四阶段工作流(Plan.md#L24-L45),原文如下:

## Your Process 1. **Understand Requirements**: Focus on the requirements provided and apply your assigned perspective throughout the design process. 2. **Explore Thoroughly**: - Read any files provided to you in the initial prompt - Find existing patterns and conventions using `Glob`, `Grep`, and `Read` - Understand the current architecture - Identify similar features as reference - Trace through relevant code paths - Use `Bash` ONLY for read-only operations (`ls`, `git status`, `git log`, `git diff`, `find`, `cat`, `head`, `tail`) - NEVER use `Bash` for: `mkdir`, `touch`, `rm`, `cp`, `mv`, `git add`, `git commit`, `npm install`, `pip install`, or any file creation/modification 3. **Design Solution**: - Create implementation approach based on your assigned perspective - Consider trade-offs and architectural decisions - Follow existing patterns where appropriate 4. **Detail the Plan**: - Provide step-by-step implementation strategy - Identify dependencies and sequencing - Anticipate potential challenges

四个阶段的职责划分非常清晰:

  1. 理解需求:锚定初始 prompt 中给出的需求,并贯穿应用“分配的视角(perspective)”——这解释了 frontmatterwhenToUse中“optionally a perspective on how to approach the design process”的设计:调用方可以传入一个设计视角(例如“优先考虑复用现有模块”),Plan 代理必须全程贯彻它。
  2. 彻底探索:这是最重的一段。允许的 Bash 白名单是纯读命令(lsgit statusgit loggit difffindcatheadtail),禁止名单则精确到git addgit commitnpm installpip install——注意npm install都被禁,因为它会改写package.json/node_modules,属于典型的“看起来只是装依赖、实际改变系统状态”的操作。探索手段上指定GlobGrepRead组合:先按模式找文件、再按符号/关键词搜内容、最后精读,并要求“找到相似功能作为参考、追踪相关代码路径”,即强制要求基于现有架构做增量设计而非凭空发明。
  3. 设计方案:明确把“权衡(trade-offs)与架构决策”列为交付内容,且要求“在合适之处遵循既有模式”——这与 frontmatterwhenToUse中“considers architectural trade-offs”的承诺互相印证。
  4. 细化计划:要求分步策略、依赖与执行顺序、以及预判潜在难点。计划不是步骤清单,而是带风险预案的施工方案。

与 Explore 代理对比可以发现职责切分:Explore 的定位是“快速找到代码在哪、只给结论不要文件倾倒”(Explore.md#L3 的whenToUse还要求调用方指定 quick/medium/very thorough 三档搜索广度);Plan 则允许慢而深的探索,产出物从“位置报告”升级为“实施计划”。二者共享同一套只读模板与工具黑名单,但流程与输出契约完全不同。

五、强制输出契约:### Critical Files for Implementation

Plan 提示词的最后部分规定了一个机器可读的收尾格式(Plan.md#L47-L57):

## Required Output End your response with: ### Critical Files for Implementation List 3-5 files most critical for implementing this plan: - `path/to/file1.ts` - `path/to/file2.ts` - `path/to/file3.ts` REMEMBER: You can ONLY explore and plan. You CANNOT and MUST NOT write, edit, or modify any files. You do NOT have access to file editing tools.

这个契约有两个工程意义:

  1. 稳定可解析的尾段:要求以固定标题### Critical Files for Implementation收尾并列出 3–5 个关键文件(用代码格式包裹的路径),父会话拿到报告后可以确定性地提取“实施该计划要动哪几个文件”,用于后续派工、上下文聚焦,甚至校验子代理是否真的读了代码(列出的文件是否真实存在)。限定 3–5 个而非“越多越好”,迫使模型做取舍而不是罗列。
  2. 末尾再次重复只读约束REMEMBER: ... You do NOT have access to file editing tools.与开头CRITICAL段落首尾呼应——长提示词中把关键不变量在开头和结尾各放一份,是对模型“中间遗忘”的经典对策。

主系统提示词也印证了子代理报告的流转方式:“The agent's final report is not shown to the user — relay what matters.”(claude-code-fable-5.1.md#L297)——子代理的原始报告只回传给父会话,由父会话转述要点给用户。因此 Plan 报告的读者首先是另一个模型,结构化的输出契约本质上是在优化“模型对模型的交接”,这也是它与给人看的文档写法的根本区别。

六、Plan 子代理与 Plan Mode:同名而分工不同的两条链路

Claude Code 中“计划”相关的能力容易混淆,这里用仓库内证据把两条链路分清:

维度Plan Mode(主循环)Plan 子代理
触发方主循环调用EnterPlanMode,需用户同意进入(claude-code-fable-5.1.md#L1406)父会话通过Agent工具指定subagent_type: "Plan"派生
计划存放计划写入“plan mode 系统消息中指定的计划文件”,ExitPlanMode读取该文件请求批准(#L1477-L1485)计划作为报告文本返回给父会话,没有计划文件
用户批准ExitPlanMode承载批准交互;提示词还专门约束“不要用 AskUserQuestion 问‘我的计划好了吗’”(#L1495)无直接批准通道——ExitPlanModedisallowedTools移除
定位主会话自身进入“先探索设计、再请求批准、最后实施”的状态机一次性的只读设计顾问,返回分步计划与关键文件清单

从源码结构看,Plan 子代理可以视为 Plan Mode 的“可并行化、可委派的变体”:主循环在 Plan Mode 里做同样的事(探索 → 设计 → 呈现计划),但它是串行的、绑定当前会话的;而把“设计实施计划”封装成 Plan 子代理后,父会话可以把架构调研丢到后台并发执行(主系统提示词明确支持“一次性发多个 Agent 调用并行运行”,见 claude-code-fable-5.1.md#L233),例如一个 Plan 代理设计新 API 的方案、一个 Explore 代理盘点现有鉴权中间件,父会话再汇总。Explore 文件的 HTML 注释(Explore.md#L10)还提到内置代理提示词由二进制按环境生成、whenToUse/whenToUseLean两个描述分别面向经典提示与精简提示模型、model: inherit在主循环模型高于 opus 时会被覆盖为 opus——这些细节说明本仓库文件是特定版本二进制中真实渲染的提示词快照,其中inherit语义在不同构建下可能有覆盖行为,引用时应以所用 Claude Code 版本的实际渲染为准。

七、可复用的提示词设计模式

把 Plan.md 作为样本拆解,可以提炼出编写高质量 Claude Code 子代理(.claude/agents/*.md)的六条实践,全部有仓库内对应物佐证:

  1. frontmatter 只写调度信息,正文才写行为name是寻址键,whenToUse是给父模型的“路由说明”,必须同时写清角色、触发条件、产出形态三条,父模型靠它做委派决策(对照 statusline-setup.md#L1-L7 的极简版)。
  2. 权限用 frontmatter 收窄,行为用正文再锁一遍disallowedTools管工具可见性;正文的CRITICAL段管“即使工具有也可能被滥用的命令”(重定向、heredoc、npm install)。两道锁缺一不可——Plan 的 Bash 白名单/黑名单就是在工具仍可用的前提下做的命令级约束。
  3. 禁用Agent工具防止递归派生:所有只读型子代理(Plan、Explore)都禁掉了Agent,与主系统提示词对subagent_overspawn的治理口径一致。
  4. 流程写成带编号的阶段,每阶段给可执行判据:四步流程中每一步都有“用什么工具、允许哪些命令、禁止哪些命令”的具体判据,而不是“充分理解代码”这类无法验收的表述。
  5. 输出契约固定收尾格式### Critical Files for Implementation+ 3–5 个文件,让父会话可以确定性解析报告;报告读者是模型而非用户,所以优化结构而非文采。
  6. 首尾重复关键不变量:只读约束在开头(第 10–20 行)与结尾(第 57 行REMEMBER段)各出现一次,抵御长上下文中部的注意力衰减。

八、小结

Anthropic/claude-code/agents/Plan.md 这份不足六十行的文件,是观察 Claude Code 多代理协作设计的一扇小窗:它用disallowedTools+ 只读提示词双层约束把“架构师”严格限定为纯读取角色,用四步流程把“规划”分解成可验收的阶段,用强制的### Critical Files for Implementation尾段完成模型间的结构化交接,并通过禁用ExitPlanMode把用户批准权牢牢留在父会话。结合主系统提示词(claude-code-fable-5.1.md)中 Agent 工具、EnterPlanMode/ExitPlanMode 工具链与同目录的 Explore、general-purpose、statusline-setup 等代理定义对照阅读,可以完整重建 Claude Code 内置子代理体系“按角色分工、按 frontmatter 授权、按输出契约交接”的整体设计逻辑。

【免费下载链接】system_prompts_leaksExtracted system prompts from Anthropic - Claude Fable 5, Opus 5, Claude Design, Claude Code. OpenAI - ChatGPT GPT-5.6-Sol, Codex. Google - Gemini 3.5 Flash, 3.1 Pro, Antigravity. xAI - Grok, Cursor, Copilot, VS Code, Perplexity, and more. Updated regularly.项目地址: https://gitcode.com/GitHub_Trending/sy/system_prompts_leaks

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询