Skip to main content
skill CX Codex

tdd · backnotprop — Claude Code skill: failing test before the fix

This skill makes the agent write a failing regression test for a bug before touching production code. It only kicks in when a cheap test path exists.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add backnotprop/pstack --skill tdd -a claude-code
Open on GitHub

What tdd does

The skill lays out a fixed order: understand the bug, pick the narrowest executable check, write the smallest failing test, confirm it fails for the right reason, then make the smallest production change. After the fix the regression test runs again. The final report names evidence rather than outcome — which test failed before, what the run showed after.

When a test would need broad harness setup, brittle mocks, slow end-to-end infrastructure or production-only state, the skill says to skip the new test and use the closest executable check instead: a targeted script, a manual reproduction command, a snapshot or a log assertion. A test that mostly exercises mocks is worse than no test.

Guardrails are explicit: don't bend tests to match a wrong implementation, don't weaken existing assertions without a clear reason, keep the regression test focused. The disable-model-invocation: true flag means the agent won't reach for this skill on its own — you have to ask for TDD, a failing test or a regression test. Worth knowing if you expect it to fire silently.

What it helps with

  • write a regression test that fails before the fix
  • reproduce a bug with the smallest executable check
  • stop tests from mirroring the current implementation
  • capture why the test failed, not just that it did
  • pick a targeted check over heavy integration infrastructure

Example prompts for the agent

  • write a failing test for this bug, then fix it
  • add a regression test for this case
  • fix this bug with TDD

How to install tdd

1Skills CLI (Vercel)

npx skills add backnotprop/pstack --skill tdd -a claude-code

2Manually: put the files in place

~/.claude/skills/tdd/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/tdd/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about tdd

How do I install tdd in Claude?

Run npx skills add backnotprop/pstack --skill tdd -a claude-code. The skill lands in ~/.claude/skills/tdd/SKILL.md.

What does the tdd skill do?

It walks the agent through the bug: narrow failing test first, confirm the failure reason, minimal production change, rerun the test. The report names the test and both runs.

When will it skip writing a test?

When the test path is unclear, expensive or integration-heavy. Then it falls back to a targeted script, manual reproduction or a log assertion.

Source text

SKILL.md · MIT
---
name: tdd
description: "Use only when the user explicitly asks for TDD, a failing test, or a regression test, OR when the bug has an obvious cheap local test target. Skip when the test path is unclear, expensive, integration-heavy, or not requested."
disable-model-invocation: true
---

# TDD Bug Fix

When fixing a bug with a clear, cheap test path, make the broken behavior executable before changing production code. The goal is a focused regression test that fails before the fix and passes after it.

Do not force a test when it would be impractical. If the available test would require broad harness setup, brittle mocks, slow end-to-end infrastructure, production-only state, vague reproduction steps, or large unrelated fixture churn, skip adding a new test and use the closest useful verification instead.

## Workflow

1. **Understand the bug.** Identify the intended behavior, current behavior, affected path, and smallest observable reproduction.
2. **Choose the narrowest executable check.** Prefer the closest unit, component, integration, or regression test already used for that codepath. If no practical test path is obvious, do not create one from scratch just to satisfy the workflow.
3. **Write the failing test first.** Add the smallest focused test that would have caught the bug. The test should encode intended behavior, not mirror the current implementation.
4. **Run the new test before fixing.** Confirm it fails for the intended reason. If it passes or fails for an unrelated reason, correct the test or reproduction before editing the implementation.
5. **Fix the bug.** Make the smallest production change that satisfies the intended behavior while preserving nearby contracts.
6. **Rerun the regression test.** Confirm the test now passes.

## If a Failing Test Is Impractical

Use the closest executable regression check instead: a targeted script, manual reproduction command, browser automation, snapshot comparison, log assertion, or focused integration check.

Prefer no new test over a bad test. A bad test is one that mostly tests mocks, encodes current implementation details, depends on timing or unrelated global state, needs expensive infrastructure for a small fix, or would be deleted immediately after proving the fix.

## Guardrails

- Do not change tests merely to match a wrong implementation.
- Do not weaken existing assertions unless the expected behavior has genuinely changed and the reason is clear.
- Keep the regression test focused on the bug. Avoid broad fixture churn or unrelated coverage expansion.
- If the bug is flaky, make the test deterministic where possible and document the signal being locked down.
- If the bug exposes a broader class of failures, first land the focused regression path, then consider additional sibling coverage.

## Final Response

Report the evidence, not just the outcome:

- Name the failing-before test or executable check and the failure it produced.
- Name the passing-after test run and any nearby validation performed.
- If failing-before evidence could not be demonstrated, state why and describe the closest regression check used instead.

© backnotprop · MIT · backnotprop/pstack

Similar skills

All skills for Testing and QA →

tdd by other authors comes first.

tdd Matt Pocock Guides the red-green TDD loop: ensures tests are written first, keep them at public interfaces, and avoid coupling to implementation details. 1,141,062installs tdd codewithmukesh Guides a strict red-green-refactor cycle for .NET 10 applications using xUnit v3, WebApplicationFactory, and Testcontainers. CX Codex +1 2,800installs tdd brianlovin Guides agents through a disciplined red-green-refactor loop. It builds features one vertical slice at a time and tests public behavior over implementation details. CX Codex +1 2,800installs tdd parcadei A skill that keeps the agent on a strict red-green-refactor loop: failing test first, minimal code next, then verification. CX Codex +1 470installs fix-bug tddworks The skill walks an agent through a defect: reproduce it, write a failing test, apply a minimal fix, verify. Built for the ClaudeBar project. CX Codex +1 ★ 1,556repo stars tdd-workflow ruvnet A skill that walks the agent through London School TDD: a failing test against mocks, the smallest passing implementation, then refactor. Steps are logged through MCP hooks. CX Codex +1 743installs laravel-tdd iSerter A skill that walks the agent through red-green-refactor in Laravel: a failing Pest test first, minimal code to pass, then cleanup. CX Codex +1 378installs tdd-gate davila7 The hook blocks edits to production files until a matching test exists. Useful if you want the agent to keep the TDD order. 192installs rtk-tdd rtk-ai This skill enforces a Red-Green-Refactor workflow for Rust and activates on implementation, testing, refactoring, and bug-fixing tasks. CX Codex +1 2,100installs tdd-rust rtk-ai Skill for RTK filter development using TDD. Write a test with real data, implement minimum code, verify token savings, lock the output format with insta snapshots. CX Codex +1 1,400installs

From the same set44

principle-subtract-before-you-add A development skill that enforces removing dead code, stubs, and unused validators before writing new features or refactoring. CX Codex +1 5,200installs maintain-verification-skill Keep a project's verification guide and feature map aligned with its code. The skill checks each mapped feature against the live app and flags confirmed fixes. CX Codex +1 5,200installs no-comments The skill spawns a comment-sicko subagent, deletes comments that explain nothing, and asks you before encoding real constraints as checks. CX Codex +1 5,200installs teach The skill explains codebases and architecture plainly without walls of text. It runs the how and why skills to combine implementation mechanics with design rationale. CX Codex +1 5,100installs principle-experience-first A principle skill that shifts priority toward the user when product, UX, or feature-scope tradeoffs come up. Useful when deciding what to cut. CX Codex +1 5,100installs principle-separate-before-serializing-shared-state Architectural guideline for concurrent actors: eliminate shared mutable state across files or keys first, resorting to locks only when a single writer is strictly required. CX Codex +1 5,100installs principle-attack-the-premise This skill tests the shared premise behind repeated failed fixes. Use it before writing another fix that hits the same gate. CX Codex +1 5,100installs principle-foundational-thinking A principle set for the stage before logic: pick core types and data structures, order the scaffold, check what concurrent actors share. CX Codex +1 5,100installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor