Claude Code Subagents Best Practices (With Good and Bad Examples)

Scope Each Subagent

Scope each subagent to one question with a stated return shape. Give it the context you’d give a contractor who has never seen your codebase. Don’t delegate anything you’d want to watch happen. Most bad subagent runs violate one of those three.

A subagent takes about six lines of frontmatter to set up, which is part of why so many of them get used badly. The failure mode is quiet: the subagent returns something plausible, you act on it, and the cost shows up an hour later when the thing it told you turns out to have been half true. Here’s what actually holds up in practice.

Good Task Example:

List every file under src/auth/ that reads a session token directly instead of going through getSession(). Return file:line and the calling function. No fixes, no commentary.

Bad Task Example:

Look at the auth system and tell me what's wrong with it.

State the Shape Explicitly

State the shape explicitly, every time. “Return a markdown table with columns X, Y, Z.” “Return at most five findings, ranked.” “Return the failing test names and their error messages, nothing else.” Anthropic’s own subagent docs use exactly this framing for the canonical case.

The Context You Don’t Pass Is the Context It Doesn’t Have

A non-fork subagent starts with a fresh, isolated context window. It does not see your conversation history, the files Claude already read for you, or the skills you already invoked. What it does get is its own system prompt, the CLAUDE.md hierarchy your session loads, a git status snapshot, and a delegation message that Claude composed by summarizing your request.

Practical consequences:

Don’t Delegate Work You Need to Watch

A subagent returns a summary. That’s the contract. Every intermediate step, every file it read, every command it ran, gone unless the summary mentions it.

Parallel Fan-out Is Where They Actually Pay Off

One subagent saves you context. Several at once save you time, and that’s the bigger number.

Three Cheap Subagents Often Beat One Expensive One

model accepts sonnet, opus, haiku, fable, a full model ID, or inherit, and it defaults to inherit. That default is worth overriding more often than people do.

Restrict the Tools, Especially for Reviewers

tools sets what a subagent can use and inherits everything if you leave it off. disallowedTools subtracts from whatever it would otherwise have.

Verify Before You Act

A subagent’s summary is a claim, not a result. It’s a claim made by a process whose reasoning you can’t inspect, about files you haven’t opened.

Good Tasks, Bad Tasks

Good subagent task Why Bad subagent task Why
“Run the test suite, return failing test names and error messages only” Huge output, tiny useful answer “Fix the failing tests” You’d want to see each fix
“List every component importing useAuth, with file:line” Bounded, checkable, mechanical “Improve the auth code” No return shape, no way to verify
“Read these four RFC pages and summarize what changed in v3” Fetching is verbose, summary is small “Design our v3 migration” Judgment work you should be in
“For each of these three modules, list external service calls” Genuinely independent, parallel-safe “Refactor these three modules consistently” They need to see each other
“Find the commit that introduced this behavior” One question, one answer “Clean up the repo” Unbounded, invisible, unreviewable

Write Descriptions as Routing Rules

For subagents you define as files, description isn’t documentation. It’s the text Claude reads to decide whether to delegate at all. Write the trigger, not the title.

Where Subagents Stop Being the Answer

Subagents solve one problem well: keeping work out of your context window. They solve nothing about visibility, and past a certain size that becomes the problem you actually have.

Related reading: Claude Code subagents explained for the full mechanics, skills vs subagents if you’re choosing between the two formats, Claude Code agents for the four different things people mean by “agent,” and git worktrees with Claude Code for keeping parallel work from colliding.