Skip to content

Agents4 min readBy Startpacks

Claude Code Subagents: 4 Examples to Copy

Four Claude Code subagent files with real frontmatter: a read-only PR reviewer, a cheap test runner, a test-first implementer and a researcher.

A Claude Code subagent is a Markdown file with YAML frontmatter that defines a specialised helper: its own system prompt, its own tools and its own context window. Claude delegates to it when a task matches its description, and only the summary comes back to your main conversation. This guide gives you four subagent files you can copy, built from the roles in our free starter agents, plus the frontmatter fields that actually change behaviour. For more ready-made roles, see the Claude Code subagents hub.

Where subagent files live

According to Claude Code's docs, the location sets the scope:

LocationScope
.claude/agents/The current project. Check it into git so your team shares it
~/.claude/agents/All your projects on this machine
--agents '{...}' CLI flagOne session only, not saved to disk
A plugin's agents/ folderWherever the plugin is enabled

If two subagents share a name, the higher-priority location wins (project beats user). Only name and description are required.

The fields that matter

  • description: Claude uses it to decide when to delegate. Add "use proactively" if you want Claude to reach for it without being asked.
  • tools: an allowlist such as Read, Grep, Glob. Leave it out and the subagent inherits every tool available to subagents. disallowedTools works the other way round.
  • model: sonnet, opus, haiku, a full model ID or inherit.
  • permissionMode, skills (preloads full skill content at startup), memory (a persistent notes directory), isolation: worktree (a temporary git worktree), maxTurns.

The Markdown body becomes the subagent's system prompt. It doesn't get Claude Code's own system prompt, so the body has to carry the instructions.

Example 1: a read-only PR reviewer

This is adapted from the workflow and rules in our free Pull Request Reviewer starter agent. It can read and run commands but has no Edit or Write tool, so it can't "fix" your code while reviewing it.

---
name: pr-reviewer
description: Reviews the current branch's diff for correctness, tests and security. Use after a feature is finished and before opening a PR.
tools: Read, Grep, Glob, Bash
model: inherit
---
You review one change at a time and produce a draft review for a human.

Workflow:
1. Run `git diff main...HEAD` and restate the intent in two sentences.
2. Rank changed files by risk: auth, money, data, migrations, concurrency first.
3. Check that tests cover the new behaviour and failure paths. Run them.
4. Review in passes: correctness, security, data, performance, maintainability.

Rules:
- Every blocker cites evidence: file:line and why it fails, or a failing command.
- Mark uncertainty ("couldn't verify"). Max ~10 comments; skip what linters catch.
- Never post, approve, push or merge. Output a draft only.

Output: Summary, Verdict (advice only), Blockers, Should-fix, Nits (max 3),
Verified / not verified, Questions for the author.

Note that Bash still lets it run any command your permission settings allow. If you want a hard stop on, say, git push, add a deny rule to your settings. The docs point out that a disallowedTools entry like Bash(git push *) removes the whole Bash tool rather than one command.

Example 2: a cheap test runner that keeps logs out of your chat

The docs name this as one of the most effective uses: run something noisy in a separate context and return only what matters.

---
name: test-runner
description: Runs the test suite and reports only failing tests with their error messages. Use proactively after code changes.
tools: Bash, Read, Grep
model: haiku
---
Run the project's test command from AGENTS.md (or `npm test` if none is listed).
Report:
- the exact command and the summary line (e.g. "12 passed, 2 failed");
- for each failure: test name, file:line, the assertion message, max 10 lines of trace.
Do not attempt fixes. Do not paste passing output.

Routing a mechanical job like this to a smaller model is a cost lever the docs call out directly.

Example 3: a test-first implementer in its own worktree

Based on our free Test-First Engineer agent. It can edit, so we isolate it in a temporary git worktree and preload the loop it must follow as a skill.

---
name: test-first-engineer
description: Implements one small, well-defined task test-first and returns the red run, green run and diff.
tools: Read, Edit, Write, Bash, Grep, Glob
isolation: worktree
skills:
  - red-green-refactor-loop
maxTurns: 40
---
Implement exactly one task per run.
1. Restate the task as one behaviour sentence. If it's ambiguous, stop and say what's unclear.
2. Run the suite once for a baseline. If it's already red, report that and stop.
3. Write ONE failing test and run it; it must fail on the assertion, not a typo.
4. Make the smallest change that passes. Refactor only while green.
5. Never weaken or delete a test to get green. Never claim "tests pass" without a run.
Return: task, red command + summary, green command + summary, files changed, risks.

For the skills field to work, the skill must exist as .claude/skills/red-green-refactor-loop/SKILL.md. The pack ships it under skills/, so copy that folder in. The docs say an isolation: worktree worktree is cleaned up automatically if the subagent makes no changes.

Example 4: a researcher with project memory

---
name: codebase-researcher
description: Answers "where is X handled?" and "how does Y work?" questions about this repo without changing files.
tools: Read, Grep, Glob
model: sonnet
memory: project
---
Answer with file paths and line numbers, then a short explanation.
Before searching, check your memory for notes on this area.
After answering, save one or two concise notes about where things live.

With memory: project, notes go to .claude/agent-memory/<name>/ and can be shared through git. The docs recommend project scope as the default.

How to call a subagent

  • Natural language: "Use the test-runner subagent to check my changes." Claude decides whether to delegate.
  • @-mention: type @ and pick it, for example @"pr-reviewer (agent)" look at the auth changes. This guarantees that subagent runs.
  • Whole session: claude --agent pr-reviewer runs the main thread with that agent's prompt, tools and model.

Edits to files in .claude/agents/ are picked up within a few seconds. The docs note one exception: if the agents folder didn't exist when the session started, restart once.

Best practices

  1. One job per subagent. A focused description routes better than a "general helper".
  2. Least privilege. Reviewers and researchers don't need Edit or Write.
  3. Keep descriptions short. They sit in context all the time; detail belongs in the body.
  4. Restate critical rules. Subagents load your CLAUDE.md by default, but they don't see your conversation history.
  5. Version them. Project subagents in git improve with every PR.

FAQ

What's the difference between a subagent and a skill? A skill adds instructions to the current conversation. A subagent works in its own context and returns a summary. Our next guide compares them in detail.

Can a subagent start other subagents? Yes, up to a depth limit the docs describe. Leave Agent out of its tools list to stop it.

Do subagents read CLAUDE.md? Custom subagents do by default. Set omitClaudeMd: true to start one without it. The built-in Explore and Plan agents skip it.

Which model should a subagent use? inherit for judgement-heavy work like review, haiku for mechanical jobs like running tests.

Try it

Download the free Pull Request Reviewer or Test-First Engineer pack, turn its AGENTS.md into a file in .claude/agents/ using the shapes above, and give it one real task. If you need a role that writes test plans and bug reports, the QA Tester agent follows the same structure. Browse all roles in starter agents.

  • #claude code
  • #subagents
  • #claude code subagents examples
  • #frontmatter
  • #code review

Sources

The packs, agents and prompts used in this guide.

Pack

QA Tester

A testing agent that turns a feature or bug report into a test plan, runs it, and returns reproducible findings — it reports bugs, it doesn't hide them.

 

Browse all packs

More guides