In one sentence
A separate AI agent session that a main agent starts for one task, with its own context window, instructions and tools, which returns a short report when done.
A subagent is a helper agent that a main agent, often called the parent or orchestrator, starts to handle one piece of work. The subagent runs in its own session with its own context window, its own system prompt, and usually a narrower set of tools and permissions. When it finishes, it sends back a summary instead of everything it read and ran along the way.
Why subagents exist
Every model has a fixed context window, and the more that window fills with search results, logs and file contents, the harder it is for the model to keep track of what matters. Anthropic's engineering team calls this context rot. Handing noisy side work to a subagent keeps the main conversation focused on planning and decisions. Anthropic describes sub-agents that explore in depth and return condensed summaries of roughly 1,000 to 2,000 tokens.
Where you see them
Coding tools ship subagents by default. Claude Code lets you define subagents with their own prompts, tools and permissions, and suggests using one when a side task would flood the main conversation. OpenCode includes built-in General and Explore subagents and lets teams define their own. Business agents use the same pattern, for example one subagent that researches a lead while another drafts the email.
What to watch
A subagent only knows what its assignment tells it, so a vague brief produces a vague result. Default subagents are usually one-way: the child cannot ask the parent a question mid-task, and the parent cannot redirect it. Parallel subagents that write to the same files will conflict unless each one works in its own branch or git worktree. Subagents also use model tokens, so spreading work across many of them costs more than it might look.
In practice
Give each subagent a complete assignment, the narrowest permissions it needs (a reviewer should be read-only), and a clear report format. Review what comes back before acting on it. Our open-source OpenCode Smart Subagents plugin adds two-way messages, mid-run steering and worktree isolation to OpenCode's subagents; it is listed on our projects page.
Keep following the system
Multi-Agent Orchestration
Coordinating multiple specialized agents when distinct roles and handoffs improve a complex workflow.
Context Compaction
Replacing the older part of an AI agent's conversation with a written summary when its context window nears full, so a long session can keep going.
AI Agent
A system that uses a model and tools to pursue a goal across multiple steps within defined permissions and review boundaries.
Semantic Code Search
Searching a codebase by meaning rather than exact text, using embeddings, often combined with keyword search, so a question like "where do we validate refunds" finds the right functions.
API Key Rotation
Replacing or cycling the API keys an application uses, either on a schedule for security or across several keys for failover, without breaking the apps that depend on them.