Summary
Highlights
Sub-agents are specialized assistants that Claude can delegate tasks to. Each sub-agent operates in its own conversation context window with a custom system prompt. Upon completion, it returns a summary to the main thread while its intermediate work remains isolated.
A primary advantage of sub-agents is their ability to manage context window usage. In Claude Code, every chat interaction, tool call, and result typically fills the main context window. Sub-agents mitigate this by starting a separate window, receiving a custom system prompt and a task description. They work autonomously, and only a summary of their findings is returned to the main conversation, keeping the main context clean by discarding the entire sub-agent conversation afterward.
Consider investigating a payment system in an unfamiliar codebase, like finding which service handles refunds. Without a sub-agent, Claude might read numerous files and run multiple searches, filling the context window with extraneous details. With a sub-agent, you get the specific answer without the journey, as the sub-agent explores and returns only a focused summary, preserving the main context.
While efficient, the main window loses visibility into how the sub-agent reaches its conclusions. Claude Code offers several built-in sub-agents, such as the general-purpose sub-agent for multi-step tasks, the explore sub-agent for fast code base searching, and the plan sub-agent for research and analysis before creating a plan. Users can also create their own sub-agents with custom system prompts and tool access.
Sub-agents in Claude Code are an effective way to break down complex work into focused pieces, maintain a clean main context window, and retrieve only necessary information. Whether using built-in or custom sub-agents, they significantly enhance longer Claude Code sessions.