Apply when asked to enforce TDD, practice test-driven development, write test first, or follow Red-Green-Refactor. Enforces the Iron Law — no production code without a failing test first. Covers the full Red-Green-Refactor cycle, when TDD applies, and valid exceptions.
Resources
1Install
npx skillscat add pmco23/claude-developer-toolbox/tdd Install via the SkillsCat registry.
TDD — Test-Driven Development
Role
You are enforcing Test-Driven Development. Every unit of behaviour must have a failing test before production code is written. The Red-Green-Refactor cycle is not optional.
Hard Rules
- Iron Law. Write the test. Watch it fail. Write minimal code to pass. Never write production code for a behaviour until a failing test for that behaviour exists and you have run it and seen it fail.
- Minimal GREEN code. Write only the code needed to make the failing test pass. No pre-emptive abstractions, no extra logic.
- Refactor only on GREEN. Structural improvements happen after tests pass — never while tests are failing.
- One cycle at a time. Complete the full RED → GREEN → REFACTOR cycle for one named test case before starting the next.
- Failing test required, not just written. A test that passes immediately is not a RED test — it means the test is wrong or the behaviour already exists. Rewrite or investigate before continuing.
Process
RED — Write the failing test
- Identify the next named test case from the task group.
- Write the test. Reference only the public interface; do not peek at implementation.
- Run the test:
bash <test-command>scoped to the new test file or test name. - Confirm it FAILS. If it passes immediately — stop. The test is wrong. Rewrite it before continuing.
GREEN — Write minimal production code
- Write the smallest production code change that makes the failing test pass.
- Do not add logic that is not required by the current test.
- Run the test again. Confirm it PASSES.
- Run the full suite scoped to your task group. All previously passing tests must still pass.
REFACTOR — Improve without breaking
- Improve naming, structure, or duplication in the code just written.
- Do not change behaviour. Run the test suite after each refactor step — all tests must remain green.
- When the code is clean, move to the next named test case and return to RED.
When TDD Applies
- New feature or behaviour (any language)
- Bug fix — write a test that reproduces the bug first, then fix it
- Refactoring — tests must exist and be green before refactoring starts
- Behaviour changes — existing tests must be updated to reflect the new expected behaviour before the code changes
Valid Exceptions
TDD is not appropriate for:
- Throwaway prototypes — code that will not be merged or shipped; document this explicitly
- Generated code — output from code generators or scaffolding tools that is not maintained by hand
- Configuration files — JSON, YAML, TOML, environment files with no executable logic
- Pure UI layout — pixel-level visual composition with no state logic; cover the state separately
- Per-project opt-out — add
tdd: disabledto the project'sCLAUDE.md. The pipeline
respects this setting:/planswitches to implementation-first task ordering and writesTDD: disabledin the plan header;task-builderskips the Red-Green-Refactor cycle.
Use for projects where no test harness exists yet, or where TDD is not feasible given
current constraints. Document the reason in CLAUDE.md alongside the flag.
When an exception applies, document it inline: # TDD exception: [reason] at the top of the file. Do not use exceptions to avoid writing difficult tests.
Anti-Patterns Reference
See references/testing-anti-patterns.md for the five patterns that defeat TDD benefits even when tests are present.