chapter 01

What are subagents

objectives

  • Define a subagent as a child session with its own fresh context window
  • Explain why the parent, not the user, composes the dispatch
  • Describe context isolation and what it protects in the main conversation
  • Distinguish foreground from background dispatch, and name the built-in agents of both tools

Ask an AI coding agent to survey a large codebase, and something predictable happens: by the time it finishes exploring, your conversation is drowning in grep output, file listings, and half-read implementations. The answer arrives, but the context that produced it now sits permanently in your window, degrading everything that comes after.

Subagents exist to break exactly that trade-off. This chapter defines what one is, why the design works, and what both OpenCode and Claude Code give you out of the box.

A child session with a fresh context

A subagent is a child session: an agent run that the parent spawns to complete one task. Three properties define it:

  1. It starts with a fresh context. The child does not inherit your conversation history, your earlier dead ends, or the files you happened to open. Its context begins empty and receives only what the dispatch puts there.
  2. It works autonomously. The child selects and runs its own tools — searching, reading files, running commands as permitted — without round-tripping every step through the main conversation.
  3. It returns a result. When it finishes, a compact final report travels back to the parent. Everything it did along the way stays inside the child.

That's the whole model. Not a second assistant you chat with, not a daemon running in your repo — a focused worker for one dispatch.

parentfileshistorynotestaskchildstarted empty — only the task came inresult

1. Parent holds full context

1/4

Why the parent composes the dispatch

Here is the part people miss on first use: you rarely talk to the subagent directly — the parent does. When you ask your main agent to "find every place we validate JWTs," the parent itself writes the dispatch: it composes the task description, includes the context the child will need (paths to start from, naming conventions, what the result is for), adds constraints (read-only, time budget, output format), and only then spawns the child.

This has a consequence worth internalizing: the subagent knows exactly what the dispatch says — and nothing else. It cannot see your conversation, your open editor, or your intentions. If the parent writes a vague dispatch, the child does vague work. Dispatch quality is the parent's responsibility, and it's a skill — Chapter 5 is devoted to it. For now, remember the division of labor: the parent holds the goal and the plan; the child holds only its task.

Flat illustration of an orchestrator dispatching three subagents and collecting only their results

Context isolation: the main conversation is the asset

Why go to all this trouble? Because the main conversation is the most valuable resource in the system, and it is consumed by everything that enters it.

Three mechanisms are at work:

Diagram loading…

Notice what the diagram does not show: any path from the child's intermediate work back into the parent. That absence is the feature.

Foreground and background

A dispatch runs in one of two modes:

The mechanics of starting and collecting background work differ between OpenCode and Claude Code — the dedicated chapters cover each tool's specifics. The concept, though, is stable: foreground trades parallelism for simplicity; background trades bookkeeping for parallelism.

Built-in agents exist — start there

You do not need to write any configuration to use subagents today. Both tools ship useful ones:

Chapter 3 and Chapter 4 cover each tool's built-ins and the custom agent files that go beyond them. For this chapter, the takeaway is smaller and more useful: dispatching is available right now, before you configure anything.

Subagents in 4 minutes — owner screencast

Screencast coming soon

What a subagent is not

Worth pinning down now, because misconceptions here cause real mistakes:

What you should now be able to say

If a colleague asked "why dispatch a subagent instead of just doing it in the chat?", your answer should be about isolation: the child burns its own tokens, on its own fresh context, and only the conclusion comes back — so the main conversation stays small, focused, and trustworthy. The next chapter makes you dangerous with the follow-up question: when should you actually do it?

Check yourself

Submit each question for instant feedback. Score 60% or higher and this chapter counts as done.

A subagent continues the parent's conversation history, just rendered in a separate window.
When your main agent dispatches a subagent, what does the parent contribute?
Which of these ship as built-in agents (no configuration required)?
A FOREGROUND dispatch means...
When a subagent finishes, all of its intermediate work — tool calls, file reads, raw search output — flows back into the parent's context.

Flashcards

Flip each card, then mark it honestly — marks are saved per card.

0/90 again0 got it

click to flip (Enter/Space works too)