上期把 subagent / hook / skill / plugin 四个原语摊开比。这期只钻最容易买错的一格:这两个不是「弱版和强版」,一个往当前对话里注入指令,一个开新的 context 只把结果收回来一段话。官方继承表逐行读,再打开两个真实的 subagent 流水线 skill。
「要不要上 subagent」的答案不在任务难不难,在中间过程你还要不要看。Claude Agent SDK 的 subagents 文档把好处写成四条:context isolation、parallelization、specialized instructions and knowledge、tool restrictions。四条里只有第一条是别的手段替不了的——其余三条 skill 也能给。所以路线是:先把两边的继承契约读清楚(谁能看见什么),再点名可装可读的具体条目,最后才给判据。判据只有一句预告:你会把它的输出当成一段话读,还是当成一串步骤跟?
subagent 就是 .claude/agents/(项目)或 ~/.claude/agents/(全局)下的一个 .md 文件,两个目录都递归扫描。必填只有 name 和 description,正文是它的 system prompt。官方文档的可选字段里这几个值得记住:
# .claude/agents/api-developer.md
---
name: api-developer
description: Implement API endpoints following team conventions
tools: Read, Grep, Edit, Write, Bash # 不写 = 继承全部;漏掉的工具压根不在它会话里
model: sonnet # sonnet/opus/haiku/fable/inherit
skills: [api-conventions, error-handling-patterns] # ★ 启动时预载 skill
memory: project # user/project/local 持久记忆
isolation: worktree # ★ 给它一个独立 git worktree
omitClaudeMd: true # 不加载 CLAUDE.md(省 token)
maxTurns: 10 # 到顶的输出被标记为 partial,可 resume
---
You are an API development specialist...
skills: 这一行就把「二选一」的伪命题打掉了:subagent 可以带着 skill 跑。反过来也成立——skill 的 frontmatter 里写 context: fork 就在隔离上下文里执行,agent: 还能指定用哪个 subagent 类型(见 官方 skills 文档)。
Claude Code 自带三个内置 subagent,装机量为零、现在就能用:
# ① Explore —— 只读工具(Write/Edit 被拒),三档 thoroughness
Use the Explore subagent, very thorough, to map every place we validate JWTs
# ② Plan —— plan mode 下做调研的那个,同样只读
# ③ general-purpose —— subagent 能拿到的全部工具,可改代码
# 自己写完一个 agent 文件后,开会话前先验一遍 frontmatter
claude plugin validate .claude/agents
# 不写文件也能起:一次性 JSON 定义
claude --agents '{"code-reviewer":{"description":"Expert code reviewer.",
"prompt":"You are a senior code reviewer.","tools":["Read","Grep","Glob"],"model":"sonnet"}}'
# 让整个会话直接以某个 agent 的身份跑
claude --agent code-reviewer
Explore 替你干掉的事很具体:四十次 grep 的输出不进你的对话。什么时候别用:答案本来就一行(「这函数在哪个文件」),派它去问要等冷启动加一轮往返,省下的 context 不值这个钱。
SDK 文档写得很直白:The only content you pass from parent to subagent is the Agent tool's prompt string, so include any file paths, error messages, or decisions the subagent needs directly in that prompt. 这就是「我明明刚跟它说过」的全部原因——你跟主对话说过,没跟它说过。
交互会话里的 /subtask <描述> 起的是一个 fork:独立 context window,但全量继承父对话的历史、system prompt、输出风格、模型,以及原样工具池(跳过后台 subagent 那道过滤)。fork 是「要隔离但不能失忆」那格的答案。代价:它继承了父对话的全部 token,省下的只有后续噪音。
<system-reminder> 这类控制标签的会被插入反斜杠,以 Human: / Assistant: 开头的行会被在冒号前加反斜杠,命中时再前置一行 [harness: ...] 标记。官方同时强调两件事:它不判断恶意,也不替代限制——真正的护栏仍然是 tools / disallowedTools 和权限。让一个 subagent 去读外部网页、再把它的报告当指令执行,是一条现成的注入链。skill 的机制是指令注入:description 常驻(便宜),正文只在被调用时展开,展开后留在对话里跨 turn 生效。所以 skill 适合「接下来每一步都要守的规矩」,subagent 适合「这一段我不想看」。disable-model-invocation: true 让 skill 只能你手动喊,user-invocable: false 让它只能模型自动触发——两个字段合起来才是 skill 真正的调用契约。
subagent-driven-development# 官方 marketplace 一条命令
/plugin install superpowers@claude-plugins-official
这个 skill 的 description 只有一句:Use when executing implementation plans with independent tasks in the current session。它的做法是:先开独立 git worktree、核计划、扫冲突、建一份 ledger 记进度;然后每个任务一轮「派实现者 → 收报告 → 针对性 review → 修,最多 5 轮」,第 1–3 轮 resume 原来那个实现者,第 4–5 轮换更强的模型;最后在最强模型上做一次整支分支的总 review。替你干掉的是:一条长计划做到第七个任务时,前六个任务的噪音已经把上下文挤满了。什么时候别装:它自己写了三条——没有实现计划、任务之间紧耦合而非独立、你的平台压根没有 subagent(那就内联执行)。
dispatching-parallel-agents它的触发条件写成 2+ independent tasks that can be worked on without shared state or sequential dependencies,而正文的门槛更高:3 个以上不同根因才值得并行。最该记住的是那句机制原话——Multiple dispatch calls in one response = parallel execution. One per response = sequential. 并行不是一个开关,是你在一条回复里发了几个调用。什么时候别用:失败之间相关(修一个可能连带修好别的)、需要全局上下文才能理解、几个 agent 会互相改同一批文件、根因未知的探索式调试。它还有一句值得贴墙上的:Do NOT just increase timeouts—find the real issue.
isolation: worktree:并行写文件的唯一正经办法上面两个 skill 都从开 worktree 起手,不是巧合:多个 subagent 同时改同一棵工作树就是在互相覆盖。frontmatter 一行 isolation: worktree 就给它一棵独立的;superpowers 里还有个专门的 using-git-worktrees skill 管这条链路。什么时候别开:任务只读(Explore 那类),开 worktree 纯加 IO。
wshobson/agents:现成 agent 库/plugin marketplace add wshobson/agents
/plugin install python-development
自称 94 plugins, 202 agents, 183 skills, 105 commands(据该仓 README,2026-09 读取;MIT),一份 markdown 源生成多个 harness 的产物。价值在于读别人的 description 怎么写——subagent 能不能被自动派到全看它。什么时候别装:整包装进来就是交 description 税(见 04 节那条 15,000 token 警告),按需只装你真用的那个 plugin。
SDK 里 subagent 是 query() 的 agents 参数,AgentDefinition 的字段和文件版几乎一一对应(description / prompt 必填,其余 tools / disallowedTools / model / skills / maxTurns / background / effort 可选)。两个坑:Python SDK 里 disallowedTools / mcpServers 保持 camelCase;检测有没有真派出去要同时匹配 "Agent" 和旧名 "Task"。规模再大就不该用 subagent 了——官方指向 dynamic workflows 的 Workflow 工具,把编排搬到对话之外的脚本里。什么时候别上 Workflow:一轮里只派两三个 agent,subagent 直接够用。
/subtask 起 fork。只需要几个路径和一段报错 → 普通 subagent,把它们写进 prompt 字符串。Anthropic 在 《How we built our multi-agent research system》(2025-06-13)里给了三个数:agent 大约是聊天的 4 倍 token,多 agent 系统大约是聊天的 15 倍;他们的内部研究评测上多 agent 比单体 Claude Opus 4 好 90.2%;而 token 用量本身就解释了浏览能力差异的 80%。同一篇文章明确列了不适用的场景:所有 agent 需要共享同一份上下文的任务、agent 之间依赖很多的领域,以及「大多数编码任务」——原话是编码可并行的部分比研究少。这三个数一起读才对:15 倍换 90.2%,值不值取决于你的任务长得像研究还是像改代码。
Prompting Claude Opus 5 里写得很清楚:Claude Opus 5 delegates to subagents more readily than prior models. 官方给的对策是两层——一层是 prompt,一层是硬闸:
# ① prompt 层(官方示例,逐字可抄)
Delegate to a subagent only for large tasks that are genuinely independent and
parallelizable, such as a wide multi-file investigation. Do not delegate work you
can finish yourself in a handful of tool calls, and do not use subagents to verify
or double-check your own work. If one subagent can complete the task, use one
rather than several, and keep spawn counts low.
# ② 硬闸层(.claude/settings.json 的 env;默认 深度 3 / 并发 20)
"env": { "CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH": "1",
"CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS": "5" }
# SDK 里还有第三道:maxBudgetUsd / max_budget_usd,到顶返回 error_max_budget_usd
同一份文档还有一条反直觉的:Opus 5 会自己验证自己的工作,所以 prompt 里「用一个 subagent 复核」这类老指令要删掉——留着只会过度验证、白烧 token。注意上面这两个环境变量要 Claude Code 2.1.217 以上。
AskUserQuestion 在 subagent 里不可用(EnterPlanMode / ScheduleWakeup / Workflow 也一样)。它卡住了只能自己猜,猜错了你在报告里才看见。后台运行的 subagent 工具池还要再砍一刀。/subtask 要隔离不要失忆,代价是继承全部历史 token。tools 收窄、worktree 隔离、报告只当数据读,这三件是配套的,不是可选项。先读这三份:① Claude Code · Subagents——字段全表、三个内置 agent、fork 一节、可用工具的两道过滤,本期一半内容的出处。② superpowers · subagent-driven-development——一条真实的 subagent 流水线长什么样,包括 5 轮修复上限和升级模型这种细节。③ Anthropic · 多 agent 研究系统(2025-06)——15 倍 token、90.2%,以及「大多数编码任务不适合」。
按需再看:dispatching-parallel-agents(一条回复发多个调用 = 并行;四条不该并行的条件)· Agent SDK · Subagents(AgentDefinition 全字段、深度/并发/预算三道闸、resume 的写法)· Claude Code · Skills(context: fork + agent:,把 skill 就地隔离)· Prompting Claude Opus 5(delegation 指令片段;删掉「用 subagent 复核」那类老指令)· wshobson/agents(现成 agent 库,拿来读 description 写法)· Dynamic workflows(规模超出 subagent 之后)。
明确别做:派 subagent 去问一行答案 · 指望它记得你刚说过的话(路径和报错要写进 prompt)· 让多个 subagent 在同一棵工作树上写文件 · 把 subagent 的报告当指令执行 · 在 Opus 5 上留着「用 subagent 复核」这类旧指令 · 不设深度/并发/预算就放它跑。
.claude/agents/*.md 或 SDK 的 agents 参数。/subtask)skills: 预载[harness: ...]。它不判断恶意,也不替代 tools 与权限限制。skills: 预载 skill,skill 又可以 context: fork 变隔离,那这两个概念还有区别吗?skills / isolation / omitClaudeMd / maxTurns / memory…)、三个内置 agent(Explore 三档 thoroughness、Plan、general-purpose)、继承与不继承的对照表、fork 一节、subagent 不可用工具清单与后台再砍一刀、输出扫描、description 合计 15,000 token 的启动警告、claude plugin validate .claude/agents(2026-09 访问)AgentDefinition 全字段表;「唯一传给 subagent 的内容是 Agent 工具的 prompt 字符串」;深度 / 并发 / maxBudgetUsd 三道闸与默认值;resume subagent 的完整示例;检测要同时匹配 "Agent" 与 "Task"(2026-09 访问)context: fork / agent: / background: 三项是本期用到的;官方自己的 Skills vs. Subagents vs. CLAUDE.md 三方对照(2026-09 访问)max_budget_usd 需要 Claude Code 2.1.217+;「删掉 use a subagent to verify 这类指令」(2026-09 访问)/plugin marketplace add wshobson/agents