In short
A subagent is a specialised AI agent that a main agent delegates a focused task to, running in its own separate context window with its own system prompt and its own scoped set of tools. Instead of one agent doing everything in a single conversation, the main agent hands off a job (review this code, research this topic, run these tests) to a subagent, which does the work in isolation and returns only a clean summary. This keeps the main conversation uncluttered and lets each subagent be tuned to do one thing well.
How subagents work
When the main agent spawns a subagent, the subagent starts fresh: it sees only its own system prompt and the delegation message, not the entire history of the main session. It works with a narrow toolset and permissions, completes its task, and passes back a short result. Because its context is isolated, all the noisy intermediate work (search results, logs, file dumps) stays out of the main agent context window.
- Separate context window: the subagent does not inherit the whole main conversation.
- Custom system prompt: a short, focused brief tuned to its single job.
- Scoped tools and permissions: only what that task needs, often read-only.
Why subagents help
The big win is context hygiene. A side task that would flood your main session with output (reading dozens of files, scanning logs) instead happens in the subagent and returns just the summary, so the main agent stays focused and the context window does not fill up. A focused brief also makes the subagent more reliable on its specialised task than a single agent juggling everything.
A concrete example
In Claude Code you can define a "code reviewer" subagent with a read-only toolset and a short review brief. After the main agent writes a feature, it delegates the review to that subagent, which inspects the diff in its own context and returns a concise list of issues. The main agent then fixes them, never having loaded the full review reasoning into its own window.
