- Sub-agents are specialized AI assistants within Claude Code that handle specific tasks independently, isolating their work from the main conversation.
- Their primary benefit is efficient context window management, as they perform complex explorations or actions in a separate environment.
- Sub-agents return only a concise summary of their findings to the main thread, ensuring the main context remains clean and focused.
What are subagents?
- Sub-agents operate in their own isolated conversation context window with a custom system prompt that you define.
- They receive a custom system prompt and a task description from the parent agent, then work autonomously, including reading/editing files or using tools.
- A main advantage of sub-agents is managing context window usage by keeping intermediate steps and detailed explorations out of the main conversation.
- Only a summary of the sub-agent's work is returned to the main thread; the entire sub-agent conversation is then discarded.
- The main conversation loses visibility into how the sub-agent reached its conclusions and what it discovered along the way.
- Claude Code offers built-in sub-agents such as
general purpose(for multi-step tasks),explore(for fast searching), andplan(for research and analysis). - You can create custom sub-agents with your own system prompts and control their tool access.
Sub-agent — A specialized AI assistant that runs independently within a larger AI system, handling specific tasks in its own isolated context.
Context window — The limited amount of previous conversation or information an AI model can process and remember at any given time.
System prompt — Initial instructions or parameters given to an AI model to define its role, behavior, or constraints for a task.
Main thread — The primary conversation or workflow within an AI system, often where tasks are initiated and summaries from sub-agents are received.
Autonomous — Operating independently without direct, continuous human or parent agent intervention.
Codebase — The entire collection of source code for a software project or application.
Sub agents are specialized assistants that Claude Code can delegate tasks to 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 aents is that they help manage context window usage. When you chat with clot code, you're adding context to the main context window. 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. 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 aent conversation then gets completely discarded. Consider a task like investigating how the payment system works in an unfamiliar codebase. Maybe you're trying to use claw code to figure out which service handles refunds. Well, without a sub agent, Claude might read 15 files, run several searches, and trace through multiple function calls, 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 focus 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 aents that you can use immediately like the general purpose sub agent used for multi-step tasks that require both exploration and action. The explore sub aent used for fast searching of code bases. The plan sub agent use during plan mode for research and analysis of your codebase before presenting a plan. And you can also create your own sub aents with custom system prompts and tool access. Sub aents let clock 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, they're a practical way to get more out of longer clawed code sessions.
TL;DR
- Sub-agents are specialized AI assistants within Claude Code that handle specific tasks independently, isolating their work from the main conversation.
- Their primary benefit is efficient context window management, as they perform complex explorations or actions in a separate environment.
- Sub-agents return only a concise summary of their findings to the main thread, ensuring the main context remains clean and focused.
Takeaways
- Sub-agents operate in their own isolated conversation context window with a custom system prompt that you define.
- They receive a custom system prompt and a task description from the parent agent, then work autonomously, including reading/editing files or using tools.
- A main advantage of sub-agents is managing context window usage by keeping intermediate steps and detailed explorations out of the main conversation.
- Only a summary of the sub-agent's work is returned to the main thread; the entire sub-agent conversation is then discarded.
- The main conversation loses visibility into how the sub-agent reached its conclusions and what it discovered along the way.
- Claude Code offers built-in sub-agents such as
general purpose(for multi-step tasks),explore(for fast searching), andplan(for research and analysis). - You can create custom sub-agents with your own system prompts and control their tool access.
Vocabulary
Sub-agent — A specialized AI assistant that runs independently within a larger AI system, handling specific tasks in its own isolated context.
Context window — The limited amount of previous conversation or information an AI model can process and remember at any given time.
System prompt — Initial instructions or parameters given to an AI model to define its role, behavior, or constraints for a task.
Main thread — The primary conversation or workflow within an AI system, often where tasks are initiated and summaries from sub-agents are received.
Autonomous — Operating independently without direct, continuous human or parent agent intervention.
Codebase — The entire collection of source code for a software project or application.
Transcript
Sub agents are specialized assistants that Claude Code can delegate tasks to 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 aents is that they help manage context window usage. When you chat with clot code, you're adding context to the main context window. 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. 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 aent conversation then gets completely discarded. Consider a task like investigating how the payment system works in an unfamiliar codebase. Maybe you're trying to use claw code to figure out which service handles refunds. Well, without a sub agent, Claude might read 15 files, run several searches, and trace through multiple function calls, 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 focus 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 aents that you can use immediately like the general purpose sub agent used for multi-step tasks that require both exploration and action. The explore sub aent used for fast searching of code bases. The plan sub agent use during plan mode for research and analysis of your codebase before presenting a plan. And you can also create your own sub aents with custom system prompts and tool access. Sub aents let clock 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, they're a practical way to get more out of longer clawed code sessions.