返回播客Claude
Claude Code subagents
什么是子智能体?
Sub-agents are specialized assistants that Claude can delegate tasks to.
子智能体是 Claude 可以委派任务的专用助手。
Each sub-agent runs in its own conversation contacts window with a custom system prompt that you define.
每个子智能体都在独立的上下文窗口中运行,使用你定义的自定义系统提示词。
When finished, it returns a summary to the main thread while all the intermediate work stays isolated.
完成后,它将摘要返回主线程,所有中间工作保持隔离。
One of the main advantages of sub-agents is that they help manage context window usage.
子智能体的主要优势之一,是帮助管理上下文窗口的使用量。
When you chat with Claude Code, you're adding context to the main context window.
与 Claude Code 对话时,你会持续向主上下文窗口中添加内容。
Every tool call and its results get stored in this main context window.
每次工具调用及其结果都会存储在主上下文窗口中。
And so, when Claude uses a sub-agent, a separate window starts.
当 Claude 使用子智能体时,会开启一个独立窗口。
The sub-agent receives two inputs, a custom system prompt from your configuration file, and a task description written by the parent or parent agent based on what you ask for.
子智能体接收两个输入:一是来自配置文件的自定义系统提示词,二是父智能体根据你的需求生成的任务描述。
The sub-agent then works autonomously.
子智能体随后自主运行。
When it reads files, edits files, or uses tools, none of these will appear in the main conversation.
读取文件、编辑文件或使用工具时,这些操作都不会出现在主对话中。
Just a summary is returned back.
只返回摘要。
The entire sub-agent conversation then gets completely discarded.
子智能体的整个对话随后被完全丢弃。
Consider a task like investigating how the payment system works in an unfamiliar code base.
比如研究陌生代码库中支付系统的工作原理。
Maybe you're trying to use Claude Code to figure out which service handles refunds.
也许你正在用 Claude Code 查找哪个服务负责处理退款。
Well, without a sub-agent, Claude might read 15 files, run several searches, and trace through multiple function calls.
没有子智能体时,Claude 可能需要读取 15 个文件、执行多次搜索,并追踪多个函数调用。
All of that context fills your context window, even if you only needed one single fact, which service handles refunds.
所有这些上下文都会填满你的上下文窗口,即便你只需要一个答案:哪个服务负责退款。
With a sub-agent, you get the answer without the journey.
使用子智能体,你直接获得答案,无需经历整个探索过程。
The sub-agent explores, discovers the answer, and returns a focused summary, keeping your main context clean.
子智能体自主探索,找到答案后返回精简摘要,让主上下文保持整洁。
But, the main window loses visibility into how the sub-agent reaches its conclusions and what it discovered along the way.
但主窗口无法看到子智能体的推理过程,以及它在探索中发现的信息。
Claude Code includes several built-in sub-agents that you can use immediately, like the general-purpose sub-agent, used for multi-step tasks that require both exploration and action.
Claude Code 内置了多个子智能体,可直接使用,例如通用子智能体,适用于需要探索和执行的多步骤任务。
The explore sub-agent, used for fast searching of code bases.
探索子智能体,用于快速搜索代码库。
The plan sub-agent, used during plan mode for research and analysis of your code base before presenting a plan.
规划子智能体,在规划模式下用于研究和分析代码库,随后呈现计划。
And you can also create your own sub-agents with custom system prompts and tool access.
你也可以创建自己的子智能体,配置自定义系统提示词和工具权限。
Sub-agents like Claude Code break work into focused pieces, keep your main context window clean, and bring back just what you need, whether you're using the built-in ones or creating your own.
Claude Code 中的子智能体将工作拆分为聚焦的小块,保持主上下文窗口整洁,只返回你需要的内容,无论使用内置还是自定义的子智能体。
They're a practical way to get more out of longer Claude Code sessions.
子智能体能让较长的 Claude Code 会话更高效。