Learning CenterClaude CodeUsing Agents in Claude Code
Intermediate8 min read

Using Agents in Claude Code

Spawn subagents for parallel work, keep main context clean, and coordinate complex tasks.

What Are Subagents?

Claude Code can spawn subagents — separate Claude instances that run a focused task and return a result. This keeps your main session context clean and enables parallel work.

Subagents are launched via the Task tool internally, or you can orchestrate them explicitly by asking Claude to "spawn a subagent to handle X."

Why Use Subagents?

Long sessions accumulate context. As your conversation grows, Claude's reasoning quality can degrade. Subagents reset the context for each task, giving you full capability on every job.

Use subagents for:

  • Independent tasks that don't need the main session's history
  • Parallel work (multiple subagents running simultaneously)
  • Tasks requiring a different model (e.g., Haiku for bulk ops, Opus for deep reasoning)

Spawning a Subagent

You can direct Claude to spawn a subagent with a structured instruction:

"Spawn a subagent to audit all API routes for missing authentication. It should read each file in src/app/api/, check for auth middleware, and return a list of unprotected routes."

The subagent completes its task and returns the output to your main session.

Parallel Subagents

For truly independent tasks, spawn multiple subagents simultaneously:

"Spawn three subagents in parallel:

  1. Review src/lib/auth/ for security issues
  2. Check src/app/api/ for missing input validation
  3. Audit src/lib/db/ for N+1 query patterns"

All three run concurrently and return results for you to review.

Context Boundaries

Subagents don't automatically inherit main session context. Provide them with explicit file paths and instructions. The more precise your subagent brief, the better the output.

Think of subagents like a PM delegating to engineers: clear scope, defined deliverable, no ambiguity.

Loading…