Intermediate 1 concept to know first · leads to 1

Subagents

Helpers Claude hands a side task to. Each works in its own fresh context window with its own prompt and tools, and only its summary comes back.

The animation needs JavaScript; every step is described below.

0:16

Know these first

1 concept · basics first
  1. Context

    The context window is everything Claude can see in a session: your messages, the files it reads, tool output and auto-loaded instructions. It fills as you work, and Claude Code compacts it when it gets full.

  2. Subagents · you are here

Some work is noisy. Searching a codebase, reading logs, opening ten files to find the one that matters: in a single conversation, all of it lands in the context window you need for the actual task. A subagent is how Claude Code sends that side task somewhere else.

A subagent is a separate AI assistant that runs inside your session with its own context window, its own system prompt, its own tools and its own permissions. It does the work there and returns only its result. Your conversation gets the answer, not every tool call behind it. (Context explains why that space is worth protecting.)

How delegation works

Claude decides when to delegate by matching the task against each subagent’s description. A few come built in: Explore, a read-only agent for searching and understanding a codebase; Plan, which gathers context while you’re in plan mode; and general-purpose, for multi-step work that has to both read and change things. You can also name a subagent in your prompt, or @-mention it to guarantee it runs.

A subagent starts fresh. It doesn’t see your conversation history or the files Claude has already read. Claude writes it a task message, and it works from that, plus your CLAUDE.md files and a git status snapshot (Explore and Plan skip both). The exception is a fork, started with /subtask, which inherits the whole conversation so far. In an interactive session, subagents run in the background by default while you keep working.

Where they live

A custom subagent is a Markdown file with YAML frontmatter, and the body becomes its system prompt:

---
name: code-reviewer
description: Reviews code for quality and best practices
tools: Read, Glob, Grep
model: sonnet
---
You are a code reviewer. ...

Only name and description are required. Put the file in .claude/agents/ to share it with a project’s team, or in ~/.claude/agents/ to use it in every project; plugins can ship subagents too. The tools field is where you enforce limits, such as a reviewer that can read but never edit. You can also just ask Claude to write the file.

The catch

A subagent that isn’t a fork starts with none of your context, so it may take time to gather it, and anything it must know has to be in its prompt or the task message. It also sends its own requests, which count toward the same usage limits as your main conversation. Keep tight back-and-forth in the main conversation; delegate work that is self-contained and noisy. And checkpoints usually can’t rewind a subagent’s edits, so use git for those. The subagents docs cover the rest, from model choice to nesting.

Where it sits

Before this

Context
Subagents

The ideas underneath · Field Guide

Sources

  1. Create custom subagents . Claude Code docs: built-in subagents, scopes, frontmatter, context, forks
  2. Checkpointing . Claude Code docs: why rewinding usually doesn't restore a subagent's edits

Verified against the official Claude Code docs on October 1, 2026 · next review by January 1, 2027. Claude Code changes quickly; the docs are the source of truth.