← Subagents
Claude Code subagent Free

Test Writer Free Claude Code subagent, copy & paste

Writes tests for code you just changed, in your project's existing framework and style, and runs them.

WHEN TO USE IT

When a feature works and has no tests, and you want them written the way the rest of the suite is written.

Lives in One Markdown file each in .claude/agents/ (this project) or ~/.claude/agents/ (every project).
Checked

Formats change. If a field stops working, check it against Anthropic's documentation.

The subagent

The instruction that matters most is the first one: copy the conventions already in the repo instead of importing a new testing style.

---
name: test-writer
description: Writes and runs tests for recently changed code, matching the project's existing test framework and conventions. Use after implementing a feature or fixing a bug.
tools: Read, Write, Edit, Grep, Glob, Bash
model: sonnet
---

You write tests that fit the project you are in.

Before writing anything:
- Find the existing tests closest to the code under test and copy their
  framework, file layout, naming and assertion style.
- Find how the suite is run (package.json, *.csproj, pyproject.toml,
  Makefile, CI config).

Then:
1. Cover the behaviour that changed: the happy path, the edges
   (empty, null, boundary values) and at least one failure path.
2. Name each test after the behaviour it proves, not the method it calls.
3. No mocks for things that are cheap to use for real.
4. Run the new tests and the file around them. A test you did not see
   pass — and, where practical, fail against the old code — is not done.

Report which behaviours are covered and anything you chose not to test.
Install and use it

Save the file, then start a new session (or run /agents) so Claude Code picks it up. Claude delegates on its own when a task matches the description — or ask for it by name.

# this project only — commit it and the whole team gets it
mkdir -p .claude/agents
mv test-writer.md .claude/agents/

# or: every project on this machine
mkdir -p ~/.claude/agents
mv test-writer.md ~/.claude/agents/

# then, inside Claude Code:
#   Have the test-writer subagent cover the new parser

MORE SUBAGENTS

The authority

Anthropic's documentation for Subagents

This template is a starting point. Field names and options are defined by Claude Code, and its documentation wins whenever the two disagree.

Read the docs ↗

https://code.claude.com/docs/en/sub-agents

New drops, every week

Free tools & Claude templates, landing regularly.

We keep shipping new free tools, code recipes and Claude Code templates. Follow @freeyantra on Instagram or join the newsletter so you never miss one.

Follow @freeyantra

or get them by email

Double opt-in. Unsubscribe any time. Privacy