Guide · Agent skill
How to use the Test-Driven Development agent skill
Updated · written with AI from the project's own documentation and checked against our catalogue data
The test-driven-development skill is a set of instructions that teaches an AI coding agent to write a failing test before it writes any production code. It is written for developers who want AI-written changes to come with meaningful automated tests. After reading this guide you will know what the skill changes about the agent's behaviour, how to install it, how to ask for work in a way that triggers it, and what your project needs before it is useful.
Quick start
- 1Download the ZIP. Download the test-driven-development skill as a ZIP file from this page.
- 2Unzip the folder. Unzip it so that SKILL.md and writing-good-tests.md sit together in one skill folder.
- 3Place the skill. Move the folder into ~/.claude/skills/ for personal use or into a project's .claude/skills/ folder for one project.
- 4Or upload it in the apps. In the Claude apps, go to Settings → Capabilities → Skills and upload the skill there.
- 5Confirm your test command. Make sure the project has a working test command, such as npm test, pytest or cargo test.
- 6Ask for a change naturally. Describe a feature, bugfix or refactor in plain language and mention that you want it test-first.
- 7Review the red and green output. Check that the new test failed for the expected reason before the code was written, and that the full suite passes at the end.
What does the skill make the agent do?
When the skill is installed, the agent follows a strict red-green-refactor cycle whenever it implements a feature, fixes a bug, refactors, or changes behaviour. It writes one minimal test, runs it, and confirms that it fails because the feature is missing, not because of a typo or setup error. Only then does it write the least code needed to make the test pass. Finally it tidies the code while keeping the tests green.
The skill is built on one rule: no production code without a failing test first. If the agent wrote code before the test, the skill tells it to delete that code and start over. It also pushes back on shortcuts such as skipping tests or writing them after the code, and it points to a companion file, writing-good-tests.md, with rules for writing honest tests.
- Red: write one failing test and watch it fail for the right reason.
- Green: write the minimum code that makes that test pass, then run the project's test command.
- Refactor: remove duplication and improve names, without adding behaviour and with tests still green.
Install the skill from the ZIP download
Download the skill as a ZIP file from this page and unzip it. The skill is made of two files, SKILL.md and writing-good-tests.md. Put the unzipped folder in one of two places depending on how you want to use it.
For a personal setup available across your projects, place it in ~/.claude/skills/. For a single project, place it in that project's .claude/skills/ folder so it applies only there and can be shared with a team through the repository.
If you use the Claude apps instead of files on disk, you can upload the skill under Settings → Capabilities → Skills.
- Personal: ~/.claude/skills/
- Single project: .claude/skills/ inside the project folder
- Claude apps: Settings → Capabilities → Skills
Trigger the skill with natural requests
You do not need a special command. The skill's description tells the agent to use it when implementing any feature or bugfix, before writing implementation code. So ordinary requests are enough, for example asking the agent to add a feature, fix a reported bug, or refactor a module.
To make the trigger reliable, name the behaviour you want and the test command the project uses. If you are unsure whether the agent is following the workflow, ask it to show the failing test output before the implementation.
- Add a feature: "Add a function that rejects empty email addresses, using test-first."
- Fix a bug: "Users can submit a form with an empty email. Write a reproducing test first, then fix it."
- Refactor: "Refactor the retry logic, keeping the tests green at every step."
Walk through a bug fix example
The skill includes a bug-fix example: empty email accepted. In the RED step the agent writes a test named 'rejects empty email' that submits an empty email and expects the form to reject it. It runs the test and expects a failure that shows the validation is missing.
In the GREEN step the agent adds only the validation needed to make that test pass. In the REFACTOR step it cleans up names and duplication, then re-runs the project's test suite. The skill also asks the agent to report any failing test it sees, including ones it did not cause.
npm test path/to/test.test.tsCheck what your project needs
The skill itself needs no API keys or accounts. It does need a working project test runner, such as npm test, pytest or cargo test, because the workflow assumes tests can be run. The skill will not set up a test framework for you.
The skill is not suited to every task. It lists throwaway prototypes, generated code and configuration files as exceptions, and says the agent should ask you first before skipping TDD for them. The skill runs no scripts and makes no network requests.
- A project test runner that the agent can call.
- Existing tests are not required, but the workflow will not create a test setup for you.
- Scripts: none. Network use: none.
Tips for getting the most from it
Keep requests small. The skill asks for one behaviour per test, so a large request is split into several red-green cycles, which is easier to review.
Read the failing output. The skill treats a test that passes immediately as a warning that it tests existing behaviour, so ask the agent to fix the test if this happens.
Use the companion guide when you review tests. writing-good-tests.md asks that each test name the production change that would make it fail, and that tests use real behaviour rather than mock behaviour.
- Keep each request to one behaviour.
- If a new test passes right away, ask the agent to fix the test.
- Review tests against writing-good-tests.md.
What people use it for
- Adding a new feature to an existing codebase with a test written before the implementation.
- Fixing a reported bug by first writing a test that reproduces it.
- Refactoring a module while keeping the test suite green at each step.
- Reviewing AI-written tests against the rules in writing-good-tests.md.
Frequently asked questions
How do I install the test-driven-development skill?
Download the ZIP from this page and unzip it. Place the folder in ~/.claude/skills/ for personal use or in a project's .claude/skills/ folder for one project. In the Claude apps you can instead upload it under Settings → Capabilities → Skills.
What does the test-driven-development skill require?
It requires a project test runner such as npm test, pytest or cargo test. It needs no API keys or accounts, runs no scripts and makes no network requests.
Is the test-driven-development skill free?
The skill is published under the MIT licence, as listed on this page. Check the licence file in the source repository for the full terms.
Does the skill work for bug fixes?
Yes. The skill is meant to apply to bug fixes as well as features, and it asks the agent to write a test that reproduces the bug and watch it fail before fixing the code.
When should I not use this skill?
Skip it for throwaway prototypes, generated code and configuration changes, which the skill lists as exceptions. It is also a poor fit for projects with no test setup, since the workflow assumes tests can be run, and for non-developers, since it assumes familiarity with test runners and mocks.
Why does the agent keep asking me before it writes code?
The skill tells the agent to ask you first for exceptions such as throwaway prototypes, generated code or configuration files. This can slow quick experiments down, so you can state up front when a change is an exception.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
This skill suits developers and teams who want AI-written features and bug fixes to come with meaningful automated tests, and who already have a working test command. It is a poor choice for quick throwaway experiments, generated code, configuration changes, projects without tests, or people who are not comfortable with test runners and mocks.
Download the skill