Claude Code subagents
Subagents let Claude Code delegate focused work to agents with their own instructions and context. They are useful when a task has separable research, review, testing, or implementation slices.
- Last verified
- Applies to
- Claude Code 2.1.x. CLI spellings were checked on local version 2.1.198; official docs may describe newer 2.1.x behavior.
- Verification method
- Subagent definitions, tool allowlists, nesting, and permission behavior were reviewed in official docs and local agent flags. No subagent or model task was launched.
- Official sources
- SubagentsPermissionsChangelog
Reproducible practice
Design a read-only reviewer subagent and prove its tool boundary
Delegate an independent review without granting edits, secret access, or unrestricted child-agent spawning.
Prerequisites
- A unique temporary repository.
- A bounded review question with expected evidence.
- No confidential fixture beyond what the reviewer must read.
Steps
Create a scoped agent definition
Allow only inspection tools and require evidence in the prompt.
Step 1 AGENT_LAB=$(mktemp -d "${TMPDIR:-/tmp}/claude-agent.XXXXXX") printf '%s\n' "$AGENT_LAB" cd "$AGENT_LAB" && git init -q mkdir -p .claude/agents printf '%s\n' '---' 'name: read-only-reviewer' 'description: Review a bounded diff and cite file evidence.' 'tools: Read, Grep, Glob' '---' '' 'Report findings by severity. Do not propose edits without cited evidence.' > .claude/agents/read-only-reviewer.mdInspect the allowlist
Confirm Edit, Write, Bash, MCP, and Agent are absent before launch.
Step 2 sed -n '1,12p' .claude/agents/read-only-reviewer.mdRun against a harmless fixture
Ask the main session to use the named agent on one text file; model execution was not performed in this audit.
Challenge the result independently
Verify cited lines yourself and reject conclusions unsupported by the file.
Expected result
The reviewer returns file-grounded findings without editing, running commands, calling MCP, or spawning another agent.
Validation
- Inspect tool usage rather than trusting the final prose.
- Confirm `git status --short` is unchanged.
- Run a negative prompt that requests an edit and verify the boundary holds.
Failure handling
Agent cannot launch
Check tool names and definition scope; unresolved tool entries now fail explicitly.
Review lacks evidence
Narrow the task and require file and line citations before acting.
Cleanup or rollback
- Return to the original directory and remove only the printed AGENT_LAB path.
- Disable a real project agent through reviewed version control rather than editing user-level agents.
Boundaries and when not to use it
- Subagents inherit available tools unless restricted; least privilege must be explicit.
- Delegation separates context, not responsibility: the main reviewer must verify findings and data exposure.
Why isolate work
Isolation reduces context clutter. A review agent can focus on bugs, a research agent can inspect documentation, and an implementation agent can work inside a narrower file set.
Parallel work
Parallel agents help when subtasks are independent. They are less useful when every next action depends on the same file or the same unresolved design decision.
Instruction design
A subagent needs a concrete scope, expected output, and boundaries. For code changes, assign ownership of files or modules so multiple agents do not overwrite each other.
Reviewing results
Treat subagent output as input, not final truth. Merge results only after checking evidence, conflicts, tests, and whether the result still matches the user goal.
| Command | Description |
|---|---|
/tasks | Inspect running and completed background subagents. |
/background | Detach the main session while work continues. |
/branch | Try an alternate approach without losing the current thread. |
claude agents --json | Script against active background sessions. |
Subagent design patterns
Well-scoped subagents reduce coordination cost and make parallel work safer.
Research agent
Read docs, search the codebase, and return evidence without editing files.
Read guideReview agent
Inspect diffs or PRs for bugs, regressions, and missing tests.
Read guideImplementation agent
Own a narrow file set and implement one bounded change with verification.
Read guideTest agent
Focus on reproducing failures, adding coverage, and reporting command output.
Read guideSubagent checklist
Split independent work
Delegate only tasks that can progress without blocking the main next step.
Read guideAssign ownership
For code work, give each agent a clear file or module boundary to reduce conflicts.
Read guideReview evidence
Check the subagent's facts, commands, and changed files before integrating its result.
Read guideMonitor with /tasks
Use task and agent views to see which background work finished or stalled.
Read guide