Claude Code Subagents: How to Design, Configure and Use Them

2–3 minutes

Updated

Short answer: a subagent is a specialist with its own instructions, tools and context window. The main agent delegates a focused task, the subagent works in isolation and returns only the result. Use them to keep the main conversation clean, to enforce a narrow set of tools, and to run independent work in parallel.

Agent tooling changes fast. Commands and file formats below match the versions current at the time of writing; check the official docs for your version before relying on them.

When a subagent is worth it

SituationWhy a subagent helps
Large searches across a codebase or logsThe noise stays in the subagent; you get the conclusion
A task that needs strict rules (security review, migrations)Its own system prompt and a limited tool list
Independent pieces of workSeveral subagents can run in parallel
Repeatable roles in a teamThe same reviewer or tester for everyone, versioned in Git

Define one in Claude Code

Subagents are Markdown files with YAML front matter, in .claude/agents/ (project, shared in Git) or ~/.claude/agents/ (just you). The /agents command lists and creates them interactively.

.claude/agents/aws-cost-reviewer.md

---
name: aws-cost-reviewer
description: Reviews Terraform and CloudFormation changes for AWS cost risks.
  Use proactively when infrastructure files change.
tools: Read, Grep, Glob
model: sonnet
---
You are a senior FinOps engineer. Review only the infrastructure changes
you are given.

For each finding, report:
- the resource and file,
- the cost driver (hours, GB processed, requests, storage),
- an estimate with the assumption you used, labelled as an estimate,
- a cheaper alternative if one exists.

Flag in particular: NAT Gateways, cross-AZ traffic, oversized instances,
missing lifecycle rules on S3, log retention without limits.
Never edit files. Finish with a table of findings sorted by impact.

How to call it

prompt

Use the aws-cost-reviewer subagent on the changes in infra/ since main.

Then use a separate subagent to check whether every new resource has
the tags "owner" and "cost-center". Run both in parallel and give me
one combined report.

The description field matters: Claude uses it to decide when to delegate on its own. “Use proactively when…” makes automatic delegation more likely.

Design rules that work

  • One job per subagent. “Reviewer” and “fixer” are two subagents, not one.
  • Fewest tools possible. A reviewer does not need write access.
  • Define the output. Ask for a table or a fixed structure, so results are easy to merge.
  • Return conclusions, not transcripts. Tell it to summarize what it found and where.

A subagent starts without the main conversation’s context. Put everything it needs in the delegation prompt: files, constraints, what “done” means.

And in ChatGPT?

ChatGPT has no user-defined subagent files. The closest options are separate Custom GPTs or Projects for each role, and, for developers, the OpenAI Agents SDK, where an agent can hand off work to specialized agents in code.

Joniel Gallo · Cloud & AI Engineer

I build these labs in a real AWS account and publish the code. Need a second opinion on your architecture or your AWS bill? Work with me.

One tested AWS & AI lab a week

Real costs, working code and what changed in Bedrock this month. Subscribe and get the free AWS Permission Debugger (PDF).