返回播客Claude
Claude Code subagents
高效使用子智能体
You know how to create sub agents and design them well.
你已经知道如何创建 sub agent 并将其设计好。
Now, let's cover when they actually help and when they get in the way.
现在,我们来讲它们真正有用的场景,以及何时会起反作用。
Simply put, the difference comes down to whether the intermediate work matters to your main thread.
简而言之,关键在于中间过程的结果对主线程是否重要。
When exploration is separate from execution, sub agents shine.
当探索与执行分离时,sub agent 才能发挥最大价值。
When each step depends on what the previous step discovered, well, information gets lost in the handoff process.
当每一步都依赖上一步的发现时,信息就会在交接过程中丢失。
Sub agents excel at research tasks where you just need an answer, not the journey.
sub agent 擅长研究类任务,你只需要答案,不需要完整的探索过程。
Consider investigating how authentication works in an unfamiliar code base.
比如,调查一个陌生代码库中认证机制的工作原理。
Well, the main thread might need to know where is the JWT validated, but doesn't need to see every file that was searched.
主线程可能只需要知道 JWT 在哪里验证,不需要看遍所有被搜索过的文件。
A research sub agent can read dozens of files, trace through function calls, and explore different code paths.
研究型 sub agent 可以读取数十个文件,追踪函数调用链,探索不同的代码路径。
All that exploration stays in the sub agent's context.
所有这些探索都留在 sub agent 的上下文里。
Your main thread receives JWT validation happens in middleware/auth.js at line 42, called from the Express router and route/api.js, or something like that.
主线程收到的是:JWT 验证发生在 middleware/auth.js 第 42 行,从 Express 路由和 route/api.js 调用,大概如此。
Claude reviews work more effectively when the code is presented as being authored by someone else.
当代码被呈现为他人所写时,Claude 的代码审查效果更好。
If you build a feature over many turns with your main thread, asking the main thread to then review it often doesn't give the best feedback.
如果你在主线程中多轮构建了一个功能,再让主线程来审查,往往得不到最好的反馈。
Claude was involved in creating it, so it has trouble seeing it with fresh eyes.
Claude 参与了创建过程,很难用新鲜的眼光来审视它。
A reviewer sub agent sees the changes in a separate context.
审查型 sub agent 在独立上下文中查看变更。
It runs get diff, reads the modified files, and applies its specialized review criteria without the history of how the code was written.
它运行 git diff,读取修改后的文件,并在没有代码编写历史的情况下应用专项审查标准。
And this separation also lets you encode project-specific review standards in the sub agent system prompt, ensuring consistent review criteria across the team.
这种隔离还能让你在 sub agent 的 system prompt 中编码项目专属的审查规范,确保团队内审查标准的一致性。
Claude Code's default system prompt emphasizes concise, code-focused response.
Claude Code 的默认 system prompt 强调简洁、聚焦代码的回复。
And this works great for coding, but not for everything.
这对写代码很好,但并不适用于所有场景。
So, one is a copywriting sub-agent with instructions about tone, audience, and style.
比如,可以用一个专门做文案的 sub agent,设定关于语气、受众和风格的指令。
This will produce better marketing text than the main thread would.
这样产生的营销文案会比主线程好得多。
Claude Code's default prompt tends towards concise, technical writing, which really isn't what you want for a landing page or email campaign, unless you want to put your customers to sleep.
Claude Code 的默认提示倾向于简洁的技术写作风格,这并不适合落地页或邮件营销,除非你想让客户昏昏欲睡。
A copywriting sub-agent can have completely different instructions about voice and structure.
文案 sub agent 可以有完全不同的关于表达风格和结构的指令。
A styling sub-agent that at mentions your design system files will apply consistent CSS patterns.
一个引用了设计系统文件的样式 sub agent 会自动应用一致的 CSS 规范。
When the sub-agent runs, those files load into the context automatically, so it knows your color variables, spacing conventions, and component patterns before it even starts writing any CSS.
sub agent 运行时,这些文件会自动加载到上下文中,因此它在开始写 CSS 之前,就已经知道你的颜色变量、间距规范和组件模式。
Sub-agents that claim expertise rarely help.
声称有专业技能的 sub agent 很少有实际帮助。
Prompts like, "You are a Python expert." or "You are a Kubernetes specialist." add no value because Claude already has that knowledge.
"你是 Python 专家。"或"你是 Kubernetes 专家。"这类提示词毫无价值,因为 Claude 本来就具备这些知识。
The overhead of launching a sub-agent, losing visibility into its work, and compressing its findings into a summary only makes sense when the sub-agent does something that the main thread can't.
只有当 sub agent 能做主线程做不到的事时,启动它的开销:失去可见性、将发现压缩成摘要,才是值得的。
Like applying a custom system prompt or keeping exploratory work isolated.
比如应用自定义 system prompt,或让探索性工作保持隔离。
Sequential sub-agent pipelines create problems.
顺序执行的 sub agent 流水线会带来问题。
Consider a three-agent flow.
来看一个三级 sub agent 流程。
One to reproduce a bug, one to debug it, and one to fix it.
一个负责复现 bug,一个负责调试,一个负责修复。
Pipelines work when tasks are truly independent.
流水线在任务真正独立时才有效。
They fail when each step depends on discoveries from the previous step.
当每一步都依赖前一步的新发现时,流水线就会失败。
Test runner sub-agents tend to hide information you need.
测试运行型 sub agent 往往会隐藏你需要的信息。
When tests fail, you want the full output to diagnose issues.
测试失败时,你需要完整输出来诊断问题。
A sub-agent that returns a test failed forces you to create additional debug scripts to get details that would have been visible in direct output.
一个只返回"测试失败"的 sub agent 会迫使你额外编写调试脚本,去获取那些本可以在直接输出中看到的细节。
Testing has showed that the test runner pattern performed worse among all configurations.
测试表明,测试运行器模式在所有配置中表现最差。
Across the series, we covered how sub-agents work as isolated threads that return summaries.
在本系列中,我们介绍了 sub agent 作为独立线程返回摘要的工作方式。
How to create them with the /agents command, and how to design them with structured outputs and specific descriptions.
如何用 /agents 命令创建它们,以及如何用结构化输出和明确描述来设计它们。
Use them for research, reviews, and tasks needing custom system prompts.
将它们用于研究、审查,以及需要自定义 system prompt 的任务。
But, avoid them for expert claims, multi-step pipelines, and test runners.
但要避免将它们用于专家声明、多步流水线和测试运行器。
The key question, does the intermediate work matter?
核心问题是:中间过程的结果重要吗?
If not, then delegate it.
如果不重要,就交给 sub agent 去做。