Claude Code Subagents
Specialized Claude configurations for every stack. Security reviewers, framework experts, DBAs, DevOps engineers, and 100+ more — each with its own system prompt, restricted tools, and separate context window.
What are Claude Code subagents?
Subagents are specialized Claude configurations that live as Markdown files in your project. Each one has its own system prompt, its own restricted tool set, and — crucially — its own separate context window. When Claude Code needs to do specialized work (security review, database migration, framework-specific refactor), it can either be told to use a specific subagent or it can automatically route work to one whose description matches the task.
Think of subagents as spawning a purpose-built specialist. Your main Claude Code conversation delegates a chunk of work to a subagent, the subagent does the work in isolation, and only the result comes back — not the intermediate context. This keeps your main context window clean and lets each specialist have exactly the system prompt it needs.
.claude/agents/<name>.md (project) or ~/.claude/agents/<name>.md (user) that defines a specialized Claude with its own system prompt, tool restrictions, and context window.
Anatomy of a subagent
Every subagent is a single Markdown file with YAML frontmatter and a system-prompt body:
Three things worth calling out:
- The
descriptionis critical. When you type> use the security-reviewer agent…Claude Code looks for a subagent whose description matches. Include trigger keywords like "Use PROACTIVELY" to encourage automatic routing. toolsis a hard boundary. This subagent literally cannot write files, rungit push, or do anything outside its allowed list. That's the security guarantee — a reviewer role that can't accidentally modify code.- The body is the system prompt. Everything after the frontmatter becomes the subagent's system prompt. Be specific about role, checklist, and output format.
Frontmatter fields you'll actually use
name— unique identifier used when explicitly invoking the agent. Kebab-case.description— when the agent should be used. Write this from Claude's perspective: "Use when X". Add PROACTIVELY to encourage auto-invocation.tools— comma-separated list of allowed tool patterns. Narrow is safer.model—haiku,sonnet, oropus. Match model to task complexity to control cost.
Why subagents change how you use Claude Code
- Context isolation. A subagent's work — reading 40 files, running 20 tool calls, iterating on a diff — happens in its own window. Only the final result returns to your main conversation. Your main context stays lean.
- Specialized system prompts. Every subagent is essentially a mini-Claude with a domain expert's brief. A
next-js-15agent knows App Router patterns cold. Apostgres-dbaagent thinks in indexes and query plans. - Tool-level guardrails. Give your
test-writeragent write access only totests/**. Give yourcode-reviewerread-only access. Enforce these boundaries at the config layer, not in the prompt. - Cost matching. Route cheap tasks (formatting, renaming) to Haiku subagents. Reserve Opus for architecture, security, and complex refactors. Each subagent picks its own model.
- Automatic delegation. If descriptions are well-written, Claude routes to the right subagent without being told. This is where PROACTIVELY and specific trigger phrasing pay off.
- Team standardization. Commit
.claude/agents/to git. Every dev gets your team's security reviewer, your team's test writer, your team's DBA — with the same standards baked in.
Subagents vs slash commands vs hooks — the decision framework
All three shape Claude Code behavior. Here's how to pick:
- Subagent when you need a specialized role with its own context: security reviewer, framework expert, DB migration specialist. Runs on demand or via auto-routing.
- Slash command when you need a repeatable prompt template:
/commit,/review,/deploy. Runs in the main conversation, expands to a prompt. - Hook when you need automatic enforcement at lifecycle events: block
git push --force, auto-format on save, log every tool call. Runs without being invoked. See our hooks hub.
Real projects use all three. A /security-review slash command delegates to a security-reviewer subagent, whose file writes are further gated by a PreToolUse hook.
9 categories, every serious specialty covered
From code reviewers to framework experts, from DBAs to prompt engineers. Each sub-category page has the complete listing with real YAML configs and usage notes.
Purpose-built reviewers for security, performance, accessibility, and language-specific concerns.
- security-reviewer
- performance-reviewer
- typescript-reviewer
- python-reviewer
- a11y-reviewer
Framework-aware test writers: Jest, Vitest, Playwright, Cypress, Pytest, RSpec, and more.
- unit-test-writer
- e2e-test-writer
- playwright-agent
- pytest-agent
- test-coverage-analyst
Deep experts in specific frameworks: Next.js, Remix, Django, FastAPI, Rails, Spring, NestJS.
- nextjs-15-expert
- remix-expert
- django-expert
- fastapi-expert
- rails-expert
Docker, Kubernetes, Terraform, cloud provider specialists (AWS, GCP, Azure), CI/CD experts.
- docker-agent
- k8s-agent
- terraform-agent
- aws-agent
- github-actions-agent
Postgres, MySQL, MongoDB, Redis specialists. Schema, migrations, query tuning, indexing.
- postgres-dba
- mysql-dba
- mongodb-agent
- redis-agent
- prisma-agent
RAG builders, prompt engineers, embedding specialists, evaluation harness designers.
- rag-architect
- prompt-engineer
- embedding-specialist
- llm-evaluator
- fine-tuning-agent
Tailwind, shadcn/ui, Radix, Framer Motion, Three.js, D3.js, charting library experts.
- tailwind-designer
- shadcn-composer
- framer-motion-agent
- threejs-agent
- d3-agent
Auth, payments, email, webhooks, queues, search, analytics, feature flags, A/B testing, and more.
- auth-agent
- stripe-agent
- webhook-designer
- queue-architect
- search-agent
API reference writers, tutorial authors, ADR authors, changelog and migration-guide specialists.
- api-doc-writer
- tutorial-author
- adr-author
- changelog-writer
- migration-guide-writer
40 most-invoked subagents right now
The specialists devs reach for first, based on newsletter downloads and community submissions. Click any to see the full config, system prompt, and tool restrictions.
How to build your own subagent in 5 steps
From an idea to a working, auto-routing, team-shared subagent.
Choose the file location
Subagents live in one of two places:
.claude/agents/<name>.md— project-scoped. Commit to git so your team gets it.~/.claude/agents/<name>.md— user-scoped. Personal, across all projects.
Team standards belong in project scope. Personal preferences belong in user scope.
Write a routing-friendly description
The description field is how Claude routes work to the subagent. Write it from Claude's perspective: "Reviews code for security vulnerabilities. Use PROACTIVELY after auth changes." The word PROACTIVELY encourages automatic invocation. Include the trigger keywords a real user would type.
Restrict the tools
Set tools to the minimum needed. A reviewer needs Read, Grep, Glob — not Write. A test writer needs Write, but only for the tests directory. Narrow tools = safer subagents.
Write the system prompt
The body of the file becomes the subagent's system prompt. Be specific about role, checklist, and output format. Use headers, bullets, and examples. The clearer the prompt, the more consistent the subagent's output.
Invoke and iterate
Invoke explicitly with > use the security-reviewer agent to check the auth changes, or let Claude route automatically when the description matches. Iterate on the system prompt as you find edge cases — subagents are just Markdown files.
Related long-form guides
In-depth reference material for when you need more than a snippet.
Subagents Explained — When to Use, When to Skip
The decision framework for when a subagent adds value over a slash command. 8 production patterns.
SetupThe Complete Claude Code Setup Guide
From npm install to a production-ready environment. Where subagents fit in the setup order.
CostCut Claude Code Costs 60% with Per-Agent Model Routing
How disciplined Haiku/Sonnet/Opus routing across subagents cuts token spend on real projects.
EnterpriseEnterprise Claude Code Rollout — Subagent Governance
How to govern subagent standards across 100+ developers. Approval workflow, audit trail, versioning.
Free tools for subagents
Generators, builders, and analyzers — no signup, no account needed.
Agent Config Wizard
Step-by-step wizard: system prompt, tool restrictions, examples. Exports a working .md file.
Free ToolSubagent Router Designer
Design multi-agent routing logic visually. Exports Claude Code-ready descriptions.
Free ToolModel Selector (Sonnet vs Opus)
Answer 5 questions per agent, get a model recommendation calibrated for cost and quality.
Free ToolClaude Code Setup Score
Grade your Claude Code setup on best practices, including subagent coverage and routing.
🐛 Hit an error while using subagents?
Our sister site AI Error Hub covers Claude Code errors, MCP connection failures, and stack traces — cross-referenced with everything on this site.
Frequently asked questions
The questions developers ask most about subagents.
A Claude Code subagent is a Markdown file (with YAML frontmatter) at .claude/agents/<name>.md that defines a specialized Claude with its own system prompt, restricted tool set, and separate context window. Invoke it explicitly (> use the security-reviewer agent) or let Claude route work to it automatically when its description matches the task.
Every subagent gets a fresh, isolated context window. When you delegate work, the subagent does its reading, tool calls, and reasoning in its own window, then returns only the final result to your main conversation.
This keeps your main context lean and means a long specialized workflow (reading 40 files, running 20 tool calls) doesn't burn through your main window's tokens. It's the closest thing Claude Code has to spawning a specialist process.
Write a clear, trigger-word-rich description. Include the phrase Use PROACTIVELY and specific keywords describing when the agent should be used.
Example: "Reviews code for security vulnerabilities. Use PROACTIVELY after any change touching auth, input handling, or database queries."
Claude Code reads all subagent descriptions on session start and matches them to your prompts. Vague descriptions = no auto-routing.
Yes. A subagent can invoke another subagent the same way your main conversation can. This lets you compose specialized workflows — for example, an architect agent that delegates to a security-reviewer for the security portion of a design review.
Be mindful of cost: each nested agent uses its own tokens. Nesting more than 2-3 levels rarely pays off.
The minimum required. Examples:
- Code reviewer →
Read, Grep, Glob. NotWrite. - Test writer →
Write, but scoped:Write(tests/**). - Migration agent →
Bash(pnpm prisma migrate:*), not full Bash.
Narrow tools are the primary security guarantee that team-shared subagents behave safely.
Rule of thumb:
- Slash command for a repeatable prompt template that runs in your main conversation. Quick to write, easy to compose.
- Subagent for a specialized role that needs its own context window, system prompt, and tool restrictions.
Simple test: if you'd write more than 50 lines of system prompt, want context isolation, or need strict tool boundaries — use a subagent. Otherwise, a slash command is enough.
Yes. Add model: haiku, model: sonnet, or model: opus to the frontmatter.
This is huge for cost control:
- Route formatting and renaming agents to Haiku.
- Use Sonnet as the default.
- Reserve Opus for security reviewers, architects, and complex refactor agents.
Cost per project can drop 30-50% with disciplined per-agent model routing. See our cost guides for real numbers.
Hooks fire on tool-use events regardless of who invoked the tool. When a subagent calls a tool, the same PreToolUse and PostToolUse hooks fire as if your main conversation had called it.
Result: security gates, cost trackers, and auto-formatters apply uniformly across subagents and the main conversation. See our hooks hub for the full lifecycle.
Commit .claude/agents/ to git. That's it.
When teammates pull, they get every subagent immediately — no install step, no plugin, no config file to update. This is exactly the same workflow as slash commands and is the standard for team-wide Claude Code standardization.
For most projects, five agents cover 80% of the value:
- A code reviewer (general or security-focused).
- A test writer matched to your test framework.
- A framework specialist for your main stack (Next.js, Django, etc.).
- A DB agent for your database (Postgres, MongoDB).
- A docs writer for API references.
Add specialists as you find yourself repeating the same specialized prompts. Browse the 40 most-used agents on this page for ideas.
Get the weekly Claude Code digest
Every Tuesday: new subagents, Anthropic release recap, and the best community submission of the week. 13,000+ developers read it.