A Claude Code skill that writes tests
One complete SKILL.md for writing tests. The read-only tools are pre-approved; writing a test file and running the suite are not, so both follow your normal permission rules.
Checked against Anthropic's documentation on November 25, 2026. By the Omniscio team. Updated .
When this skill fires
The description names tests, unit tests and coverage, which are the words people use, so the automatic route has something to match.
- On its own when you ask "write tests for this", "add unit tests to the parser", or "cover this function".
- Directly with
/write-tests src/price.tsor/write-tests calculateTotal. - With read access pre-approved:
allowed-tools: Read Grep Glob Bash(git status *)lets Claude inspect the code and the existing tests without a prompt during that turn, where those tools are available. The grant clears on your next message, and it does not grant a write.
The whole skill, ready to copy
Save this as SKILL.md inside a folder named write-tests, with the frontmatter as the file's first line.
---
name: write-tests
description: Adds tests for the code the user names, following the test framework and file layout already in the repository, and runs them. Use when the user asks for tests, unit tests, or coverage of a function or file.
argument-hint: [file-or-symbol]
allowed-tools: Read Grep Glob Bash(git status *)
---
## What has changed
!`git status --short`
## Instructions
1. Find the test framework and the test layout from the repository itself: a test script in package.json, the framework's config file, or existing tests beside the code. If the repository has none, use the standard runner for the language (go test, pytest, cargo test) or ask which to use.
2. Read the code named in the request or arguments. If neither names any, use the files in the status list above; if that is empty too, ask which file to cover.
3. Write tests in the existing style and location. Cover, in this order:
- the normal case,
- each boundary the code handles,
- each error the code can raise or return.
4. Name each test for the behaviour it proves, not the function it calls.
5. Do not re-test what the type system guarantees at compile time; do test runtime input and external data.
6. Run the new test alone first, then the repository's own suite with its non-watch invocation, and show both results.
7. If a new test fails, re-derive the expected value from the code before calling it a bug, and separate a pre-existing failure from this one. If it is a real bug, stop and report it with the failing output. Do not weaken the test to make it pass.What each part does
| Field | What it does here |
|---|---|
name: write-tests | The command in the / menu; the folder name would otherwise supply it |
description | What the skill does and when to use it, in the words a request would use |
argument-hint: [file-or-symbol] | The autocomplete hint for the thing to cover. Square brackets display as typed |
allowed-tools: Read Grep Glob Bash(git status *) | Pre-approves the read-only tools and the skill's own git status command for the turn that invokes the skill, so the injected context is not aborted by a permission check. It grants no write and restricts nothing else |
git status --shortis the injected starting point: the files you have touched. It is exactly the commandBash(git status *)pre-approves, so the injection is not aborted by a permission check. A slash argument such as/write-tests src/price.tsarrives as the arguments the body reads.- "Find the framework from the repository" is the instruction that stops a new Jest config appearing in a Vitest repository. The repository is the source of truth, not the skill.
- The three cases are the minimum honest coverage: the path that works, the edges, and the failures. Anything beyond them is a judgement call you can add.
- "Do not weaken the test" is the rule that makes the skill useful. A test that fails because the code is wrong is the finding, not an obstacle.
About twenty-five lines. The body stays in the conversation once loaded, so keeping it short also keeps the recurring cost small.
Where to put it: personal or project
| Choose | Path | Who gets it |
|---|---|---|
| Personal | ~/.claude/skills/write-tests/SKILL.md | You, in every project on this machine, but not Cowork or cloud sessions |
| Project | .claude/skills/write-tests/SKILL.md | Everyone in this repository once committed. Better here if the team has test conventions the body should name |
When two of the enterprise, personal and project locations share a name, personal beats project, so a home copy can override the repository's version without anyone noticing.
Changes are picked up within the session, except in bare mode, the fast launch that skips optional startup work. If a new skill does not appear, run /reload-skills. Only the SKILL.md text is watched live.
How to confirm it loads
- Find the command. Type
/and look forwrite-tests, or open/skills. - Ask the listing question.
What skills are available?should name it. - Run it on a small file.
/write-tests <small-file>should produce tests in the existing framework and then run them. - Check the automatic route. On a clean tree, say "add tests for the price parser". If it does not fire, check that the YAML parses, any
pathslimit, and the listing before rewriting the description.
/skill-doctor reports each skill's cost and how often it is used, useful when a shelf of skills grows.
Common failures
The usual failure is a second test framework. A skill that does not read the repository first will happily write Jest tests into a Vitest project, or Python tests beside a Go package, and the suite you already run never sees them.
- Fix it in the body, not the description. Step 1 exists for this: read the test script, the config file and a neighbouring test, then follow them. If your repository has an unusual layout, name it in the skill so the first run cannot guess.
- A test command that exits 1 is not a broken skill. Failing tests are the job. This applies only if you move the test run into an injected
!`...`line; the shipped skill runs it as a normal tool call, where|| truewould hide real failures. - If it never fires, the shipped description already names tests, unit tests and coverage. Check that the YAML parses, any
pathslimit and the skill listing, then add the exact phrase you type if it is still missing.
And if the frontmatter is not the file's first line, the skill still runs by name but has no description to match, so the automatic route silently never works.
Where this fits
If the tests should be written away from your main conversation, that is a subagent, which has its own context window and returns a summary. If you want the change reviewed before it ships, the review checklist skill is the pair to this one.
More complete examples are in the skills examples library, and the mechanism behind every field is in the skills guide.
Where these answers come from
- Extend Claude with skills, read November 25, 2026: the frontmatter reference, allowed-tools, dynamic context, where skills load, live change detection and the troubleshooting order.
- When an injected command fails: the whole-invocation abort and the
|| trueadvice for a command expected to exit non-zero. - The changelog: release 2.1.332, dated November 25, 2026.
Common questions
Does it replace my test framework?
No. The body tells Claude to find the framework and layout from the repository first and to follow them, so the tests it writes are picked up by the command you already run.
Why does it only pre-approve Read, Grep and Glob?
Because those are enough to understand the code and the existing tests. Writing a test file is not pre-approved, so it follows your permission settings. The grant clears when you send your next message.
What does it do when a test fails?
It stops and reports the bug with the failing output, by design. Weakening or deleting the test to get a green run would hide the finding the skill was asked to produce.
Can it cover a whole repository?
It can, but the skill is written for one named file or symbol at a time. For a larger sweep, point it at the files in the status list or add your own scope to the body.