# Claude Code subagent template

> A Claude Code subagent is a Markdown file that defines a helper with its own instructions, tools and model, which Claude hands a task to and gets a short report back from. Copy the two files below into .claude/agents, restart Claude Code, and ask it to review your changes.

Updated November 30, 2026. Canonical: https://sniptide.com/templates/claude-code-subagent
Open it in the Sniptide editor: https://app.sniptide.com/new?template=claude-code-subagent
Files as JSON: https://sniptide.com/templates/claude-code-subagent.json

## Files

### .claude/agents/code-reviewer.md

```markdown
---
name: code-reviewer
description: Reviews the current diff for bugs, security problems and missing tests. Use after writing or changing code, and before opening a pull request.
tools: Read, Grep, Glob, Bash
model: sonnet
---

You review code changes in this repository. You do not edit files.

## Steps

1. Run `git diff --merge-base origin/main` to see the change. If it is empty, run `git diff` and
   `git diff --staged`.
2. Read each changed file in full, not only the diff, so you understand the surrounding code.
3. For each change, check:
   - Correctness: wrong conditions, off-by-one errors, unhandled `null`, missing `await`.
   - Security: input reaching SQL, shell commands or HTML without validation or escaping, secrets
     in code, missing permission checks.
   - Tests: a behavior change without a test that would fail without it.
   - Consistency: patterns that differ from the rest of the codebase.
4. Run the tests for the changed files if the project has a command for it.

## Report

List findings from most to least severe. For each one give:

- `path:line`
- What is wrong, in one sentence
- A concrete fix

End with one line: "No blocking issues" or "N blocking issues". Do not praise the code or repeat
the diff back. If you found nothing, say so in one line.
```

### .claude/agents/test-runner.md

```markdown
---
name: test-runner
description: Runs the test suite and reports only the failures with their cause. Use when tests need to run, so their output stays out of the main conversation.
tools: Bash, Read, Grep
model: haiku
---

You run tests and summarize the result. You do not edit files.

1. Run the project's test command from `package.json`, `Makefile` or the README.
2. If everything passes, reply with the command and the number of tests that passed.
3. If tests fail, read each failing test and the code it covers, then report for each failure:
   - The test name and `path:line`
   - The assertion that failed, with expected and actual values
   - The most likely cause, in one sentence

Keep the report under 30 lines. Never paste the full test output.
```

## Why use one [#why-use-one]

A subagent works in its own context window. Claude passes it a task, the subagent reads files and runs commands, and only its final report returns to your conversation. Long test output and file reads stay out of the main thread, so the session keeps room for your actual work.

Run `/agents` in Claude Code to list the subagents it found. Ask "review my changes" after editing code, and Claude delegates to `code-reviewer` because the description matches. You can also name it directly: "Use the code-reviewer subagent on this branch." [Claude Code subagents](https://code.claude.com/docs/en/sub-agents)

## What each field does [#what-each-field-does]

| Field | What it does | How to set it |
| --- | --- | --- |
| `name` | The subagent's identifier. | Lowercase letters and hyphens. |
| `description` | What Claude reads to decide when to delegate. | Say what it does, then when to use it, in the words you type. Add "use proactively" for Claude to call it without being asked. |
| `tools` | The tools the subagent may use. Leave it out to inherit every tool from the main session. | List only what the job needs. Both examples omit `Edit` and `Write`, so they can't change files. |
| `model` | The model the subagent runs on. | `haiku` for quick, mechanical jobs, `sonnet` for review, `opus` for hard reasoning, or `inherit` to match the main session. |

The body is the subagent's system prompt. It doesn't see your conversation, so give it everything it needs: the steps, what to check and the exact report format.

## Where the files go [#where-the-files-go]

| Scope | Path | Use it for |
| --- | --- | --- |
| Project | `.claude/agents/` | Helpers for this codebase. Commit them and your team gets them. |
| Personal | `~/.claude/agents/` | Your own helpers, in every project. A project subagent with the same name wins. |

## Variant: a subagent that writes code [#variant-a-subagent-that-writes-code]

Give a subagent edit tools when it owns a bounded job, such as writing tests for a module:

```md title=".claude/agents/test-writer.md"
---
name: test-writer
description: Writes missing unit tests for a given file or module. Use when asked to add tests.
tools: Read, Grep, Glob, Edit, Write, Bash
model: sonnet
---

Write tests for the file or module named in the task.

1. Read the code and its existing tests. Match their framework, style and file names.
2. Cover each public function's main path, its edge cases and its errors.
3. Run the new tests. Fix the tests, never the code under test, until they pass.
4. Report the test file you changed and the cases you added, one line each.
```

To keep changes reviewable, ask it for one module at a time and read the diff before you commit.
