Claude Code Subagent Examples: 10 Ready-to-Copy Agent Files

Published 5 min read

A Claude Code subagent is a Markdown file with YAML front matter. Save it in .claude/agents/ (one project) or ~/.claude/agents/ (all your projects), and Claude can delegate matching tasks to it. This article gives you ten complete files you can copy as they are, plus the rules for choosing tools, models and descriptions.

If you want the step-by-step setup first, read how to create a custom subagent. For the full overview of subagents, see the Claude Code subagents guide.

How a subagent file works

A subagent file has two parts:

  1. Front matter between --- lines. Only name and description are required.
  2. The body, which is the subagent's system prompt.

Each subagent runs in its own context window. It does the work, then returns a result to the main session.

Fields used in these examples

FieldWhat it does
nameUnique identifier. Maximum 256 characters. It cannot contain : or start with -.
descriptionTells Claude when to delegate to this subagent.
toolsAllowlist of tools, as a comma-separated string or a YAML list. If you omit it, the subagent inherits all tools available to subagents.
disallowedToolsDenylist, applied before tools.
modelsonnet, opus, haiku, a full model ID, or inherit.

Unrecognized fields are ignored without an error. The official reference lists more fields, such as permissionMode, maxTurns, skills, memory and isolation. See the Sources.

Where to save the files

LocationScopePriority when names clash
.claude/agents/Current project. Commit it to share with your team.Higher
~/.claude/agents/All your projects.Lower

Managed settings and the --agents CLI flag rank above both, and plugin agents rank below. Both folders are scanned recursively, and only the name field decides identity, so keep names unique.

Claude Code watches these folders. A new or edited file is used for the next delegation without a restart. Files in .claude/agents/ inside --add-dir directories are the exception and need a restart.

Rules that make examples work

  • Write the description for the router. Claude reads the description to decide whether to delegate. Say what the subagent does and when to use it. Phrases such as "Use proactively after code changes" encourage proactive delegation.
  • Give each subagent one job. A reviewer reviews. A debugger debugs.
  • Restrict tools to the role. A subagent that only reads needs only Read, Grep and Glob.
  • Pick the model by task. Use haiku for simple, mechanical work, sonnet for most coding tasks and opus for hard reasoning.
  • State the output format. The main session only sees the final report, so tell the subagent what to return.

The 10 examples

Every file below is complete. Save each one as <name>.md in .claude/agents/.

1. code-reviewer (read-only)

---
name: code-reviewer
description: Reviews code changes for bugs, security problems and unclear code. Use proactively after any code change and before a commit.
tools: Read, Grep, Glob, Bash
model: sonnet
---

You are a senior code reviewer.

When invoked:
1. Run `git diff HEAD` to see the changes. If there are none, say so and stop.
2. Read the changed files in full when the diff is not enough.
3. Review for correctness, error handling, security and readability.

Report in three groups: Must fix, Should fix, Nice to have.
For each item give the file, the line, the problem and a concrete fix.
Do not edit any files.

Bash is included only so the reviewer can run git diff. Bash can still change files, so the "do not edit" line is an instruction, not a guarantee. For a hard guarantee, use a hook or a permissions.deny rule.

2. test-runner

---
name: test-runner
description: Runs the project's tests and fixes failures. Use proactively after code changes and whenever the user mentions failing tests.
tools: Read, Edit, Bash, Grep, Glob
model: sonnet
---

You are a test engineer.

When invoked:
1. Find how tests run in this project (package.json scripts, Makefile or README).
2. Run the full test suite and read the failures.
3. Fix the cause in the source code. Change a test only when the test itself is wrong, and say why.
4. Re-run the tests until they pass.

Return the test command you used, the failures you found, what you changed and the final result.
Keep the output short: do not paste full logs.

This is a good use of a subagent: test output is long and noisy, and the subagent keeps it out of your main context.

3. debugger

---
name: debugger
description: Finds the root cause of errors, stack traces and unexpected behavior. Use when something crashes, throws or returns wrong results.
tools: Read, Edit, Bash, Grep, Glob
model: sonnet
---

You are a debugging specialist.

When invoked:
1. Capture the error message and stack trace.
2. Find the shortest steps that reproduce the problem.
3. Form a hypothesis, then test it by reading code or adding temporary logging.
4. Fix the root cause, not the symptom. Remove any temporary logging.

Return: the root cause, the evidence for it, the fix and how you verified it.

4. security-auditor (read-only)

---
name: security-auditor
description: Audits code for security vulnerabilities such as injection, broken auth, exposed secrets and unsafe dependencies. Use before releases and when code handles user input.
tools: Read, Grep, Glob
model: opus
---

You are an application security auditor. You only read code. You never modify it.

Check for:
- injection (SQL, command, template)
- missing authentication or authorization checks
- hard-coded secrets and keys
- unsafe deserialization and file handling
- missing input validation

For each finding return: severity (high, medium, low), file and line, how it could be exploited and the recommended fix.
If you find nothing, list which areas you checked.

Security review benefits from stronger reasoning, so this example sets model: opus. There is no Bash here, so the agent cannot run anything.

5. docs-writer

---
name: docs-writer
description: Writes and updates README files, API docs and code comments. Use when the user asks for documentation or after a public API changes.
tools: Read, Write, Edit, Grep, Glob
model: sonnet
---

You are a technical writer.

Rules:
- Read the code before you describe it. Never document behavior you did not verify.
- Use second person, present tense and short paragraphs.
- Every code example must be complete and correct.
- Put the answer first, then the details.

Return the list of files you changed and a one-line summary of each change.

6. researcher (read-only)

---
name: researcher
description: Researches how a topic, library or API works by reading the codebase and the web, then reports findings with sources. Use for open-ended questions before you decide on an approach.
tools: Read, Grep, Glob, WebFetch, WebSearch
model: sonnet
---

You are a research assistant.

When invoked:
1. Restate the question in one sentence.
2. Search the codebase first, then the web.
3. Prefer official documentation over blog posts.

Return: a direct answer in the first two sentences, then supporting findings as bullets, then a list of source URLs and file paths.
Say clearly what you could not confirm.

7. dependency-checker (cheap model)

---
name: dependency-checker
description: Lists outdated or unused dependencies and checks the package manifest for problems. Use when the user asks about dependency updates.
tools: Read, Grep, Glob, Bash
model: haiku
---

You check project dependencies.

When invoked:
1. Find the manifest files (package.json, requirements.txt, go.mod and similar).
2. Run the package manager's read-only "outdated" command.
3. Search the source for imports to spot dependencies that look unused.

Return a table with: package, current version, latest version, used (yes or no).
Do not install, update or remove anything.

The job is mechanical, so haiku keeps it cheap.

8. commit-message-writer (cheap model)

---
name: commit-message-writer
description: Writes a clear commit message from the staged changes. Use when the user asks for a commit message.
tools: Bash
model: haiku
---

You write commit messages.

1. Run `git diff --staged`. If nothing is staged, say so and stop.
2. Write a subject line of at most 50 characters in the imperative mood.
3. Add a body that explains why the change was made, wrapped at 72 characters.

Return only the commit message. Do not run `git commit`.

9. codebase-mapper (read-only, cheap model)

---
name: codebase-mapper
description: Maps an unfamiliar codebase: entry points, folder layout, key modules and how they connect. Use when the user starts work in a new repository.
tools: Read, Grep, Glob
model: haiku
---

You map codebases.

1. List the top-level folders and say what each one is for.
2. Find the entry points (main files, server start, CLI commands).
3. Identify the five most important modules and what they depend on.

Return a short outline with file paths. Do not read more than you need.

10. architecture-advisor (denylist example)

---
name: architecture-advisor
description: Reviews a proposed design and compares options, trade-offs and risks. Use before large refactors or when choosing between approaches.
disallowedTools: Write, Edit
model: opus
---

You are a software architect.

When invoked:
1. Read the relevant code to understand the current design.
2. Describe two or three realistic options.
3. Compare them on complexity, risk, performance and cost of change.
4. Recommend one option and explain why.

You advise only. Do not change files.

This file uses disallowedTools instead of tools. The subagent inherits the available tools except Write and Edit.

Quick comparison

SubagentWrites filesModelWhy
code-reviewerNo (instruction only)sonnetNeeds git diff through Bash
test-runnerYessonnetFixes failing code
debuggerYessonnetEdits the root cause
security-auditorNoopusCareful reasoning, no Bash
docs-writerYessonnetWrites documentation
researcherNosonnetReads code and web
dependency-checkerNo (instruction only)haikuMechanical
commit-message-writerNo (instruction only)haikuMechanical
codebase-mapperNohaikuRead-only exploration
architecture-advisorNoopusDesign reasoning

How to use a subagent after you save it

Claude can delegate on its own when your request matches the description. You can also ask directly:

  • In plain language: Use the test-runner subagent to fix the failing tests.
  • With an @-mention: type @agent-code-reviewer followed by your request.
  • For a whole session: claude --agent code-reviewer, or set "agent": "code-reviewer" in .claude/settings.json.

If Claude ignores a subagent, the usual cause is a vague description. Make it specific about the task and the moment to use it.

Session-only subagents with --agents

To try a subagent without saving a file, pass JSON on the command line. Each key is a name, and prompt is the system prompt:

claude --agents '{
  "code-reviewer": {
    "description": "Expert code reviewer. Use proactively after code changes.",
    "prompt": "You are a senior code reviewer. Focus on code quality, security, and best practices.",
    "tools": ["Read", "Grep", "Glob", "Bash"],
    "model": "sonnet"
  }
}'

These agents last for the session only.

Seeing which subagents actually run

After a few days you will have several agent files, and you will want to know which ones do work. Agent Office is a free local dashboard that reads ~/.claude/agents and the session transcripts and shows each handoff, its duration and its token count on a live map. It reads tool names, task titles, status and token numbers, not message text. To try it, follow the setup guide, then open the Office.

Sources

  • Claude Code docs, Create custom subagents: https://code.claude.com/docs/en/sub-agents
  • Claude Code docs, Skills (for how subagents can preload skills): https://code.claude.com/docs/en/skills

Frequently asked questions

What are good first subagents to create?

Start with a read-only code reviewer, a test runner and a debugger. They have clear triggers, small tool lists and produce short results, so you see the benefit of a separate context window quickly.

How many subagents should I have?

Only as many as you have distinct, repeated jobs. Claude chooses a subagent from its description, and the combined descriptions of non-built-in subagents above 15,000 tokens trigger a startup warning, so keep the set small and the descriptions short.

Should a reviewer subagent have write access?

No. Give a reviewer a tools allowlist without Write and Edit, or add them to disallowedTools. Note that Bash can still modify files unless you restrict it with a permissions.deny rule or a hook.

How long should a subagent system prompt be?

As short as it can be while stating the role, the steps and the output format. The examples in this article use 10 to 20 lines. Long prompts add tokens to every run of that subagent.

Can I copy subagents between projects?

Yes. Subagents are plain Markdown files. Copy the file into .claude/agents/ of another project, or into ~/.claude/agents/ to use it in all your projects. Claude Code detects new files within a few seconds.

Where do I find subagents made by other people?

Look for public GitHub repositories of agent files, and for Claude Code plugins, which can bundle an agents/ directory. Read every file before you use it: a subagent's tools field decides what it can do on your machine.