
tdd
Test-driven development for features, bug fixes, regressions, and safe refactors using a failing-test-first workflow. Use when Codex needs to add or change behavior with proof, reproduce a bug in a test, write regression or characterization tests, make a refactor safer, or respond to prompts like "use TDD", "red-green-refactor", "write the test first", "add a regression test", "reproduce this in a test", "prove the fix", "cover this change with tests", or "make this safe to refactor". Prefer this skill when confidence should come from executable evidence instead of reasoning alone.
- Installs
- 55
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/petekp/claude-code-setup --skill tdd- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads tdd automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Test-Driven Development
Treat executable evidence as the source of truth. Use this workflow to prevent five common agent failures:
- guessing instead of proving
- writing many tests before learning anything
- testing shapes or internals instead of behavior
- over-mocking code under your control
- letting the feedback loop get so slow that TDD stops working
Start the Session
Before editing code:
- Read repo-local instructions such as
AGENTS.md,CLAUDE.md, and package or test scripts. - Inspect nearby production code and nearby tests to infer naming, seams, fixtures, and the fastest targeted command.
- Identify two commands up front:
- the fastest command that runs the single target test
- the broader command that validates the changed boundary before finishing
- Choose the smallest public or near-public seam that can prove the behavior. See seams.md.
- Ask the user only when the public contract, intended behavior, or required coverage scope is materially ambiguous.
Follow repo-local instructions if they are stricter than this skill.
Work Vertically
Do not batch all tests first and all implementation later.
Wrong:
RED: test1, test2, test3
GREEN: impl1, impl2, impl3
Right:
RED -> GREEN -> REFACTOR: test1 -> impl1
RED -> GREEN -> REFACTOR: test2 -> impl2
RED -> GREEN -> REFACTOR: test3 -> impl3
Write one failing test. Make it pass with the smallest sensible change. Refactor only on green. Repeat.
Choose the Entry Path
New feature
- Start with the smallest user-visible or caller-visible behavior worth shipping.
- Write one tracer-bullet test at the chosen seam.
- Make it fail for the right reason.
- Implement the thinnest slice that turns the test green.
- Add the next behavior only after the current one is proven.
Bug fix or regression
- List 2-3 plausible hypotheses before changing code.
- Reproduce the bug with the smallest failing regression test that would have caught it.
- Narrow the reproduction with logs, assertions, or a lower seam if the first repro is noisy.
- Fix the code under that failing test.
- Add one neighboring test only if it proves the fix is specific rather than accidental.
See bugfixes.md for the detailed mini-loop.
Legacy code or refactor
- Freeze current behavior with a characterization test before reshaping internals.
- Refactor behind that safety rail until the design exposes a better seam.
- Replace overly broad characterization coverage with tighter behavioral tests when the seam improves.
- Use the green state to deepen modules and simplify interfaces.
See seams.md, deep-modules.md, and refactoring.md.
Run the Core Loop
For each cycle:
RED: Write or tighten one test that proves one behavior. Confirm it fails.GREEN: Write the minimum production change that makes only that behavior pass.REFACTOR: Clean up duplication, naming, and structure while staying green.- Re-run the smallest relevant command first, then widen verification as confidence grows.
If the test cannot fail, the loop is invalid. Break it on purpose, lower the seam, or add the missing observability before trusting it.
Keep Feedback Fast
Use this ladder:
- Run the single target test while iterating.
- Run the surrounding file, package, or focused suite after a small cluster of green cycles.
- Run broader verification before finishing: the relevant integration suite, typecheck, lint, or full tests for the touched boundary.
- Call out any verification gap explicitly if time, tooling, or environment prevents broader checks.
If the loop feels slow, the seam is probably too high. Move down a level unless the behavior truly lives in the browser or across system boundaries.
Choose Assertions That Survive Refactors
- Assert observable outcomes, not helper calls.
- Prefer public interfaces over internal collaborators.
- Mock only system boundaries you do not control. See mocking.md.
- Treat tests as specifications for behavior, not snapshots of implementation shape.
- Keep each test about one behavior, even if that behavior needs more than one assertion.
See tests.md for examples and rewrites.
Use Subagents Carefully
When other agents help:
- Keep ownership of the failing test, the red/green loop, and final verification in the main thread.
- Let workers explore implementation ideas or refactors under the existing failing test.
- Reject fixes that only pass by weakening the test unless the test was proving the wrong behavior.
Avoid These Anti-Patterns
- Editing production code for the target behavior before seeing a meaningful failing test
- Writing the whole test plan up front
- Solving multiple behaviors in one red/green cycle
- Using browser or end-to-end tests for logic that could be proven faster elsewhere
- Mocking modules you own just to make the test convenient
- Leaving debug scaffolding, speculative branches, or unverified refactors behind
Finish with Proof
Consider the task done only when:
- the changed behavior is covered by a test that failed before the change
- the targeted tests pass
- the relevant broader verification command has run, or the gap is documented clearly
- refactors happened only while green
- the final summary states what behavior is now proven and what still relies on manual verification
Read More Only As Needed
- tests.md for durable behavior-level assertions and bad-to-better rewrites
- mocking.md for boundary-only mocking rules
- seams.md for seam selection, test levels, and fast feedback
- bugfixes.md for regression-test-first debugging
- interface-design.md for testable interfaces
- deep-modules.md for hiding complexity behind small APIs
- refactoring.md for green-only cleanup targets
FAQ
What does the tdd skill do?
Test-driven development for features, bug fixes, regressions, and safe refactors using a failing-test-first workflow. Use when Codex needs to add or change behavior with proof, reproduce a bug in a test, write regression or characterization tests, make a refactor safer, or respond to prompts like "use TDD", "red-green-refactor", "write the test first", "add a regression test", "reproduce this in a test", "prove the fix", "cover this change with tests", or "make this safe to refactor". Prefer this skill when confidence should come from executable evidence instead of reasoning alone.
How do I install tdd?
Run npx skills add https://github.com/petekp/claude-code-setup --skill tdd in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/tdd/ (personal) or .claude/skills/tdd/ (project).
Which AI agents can use tdd?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is tdd safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains tdd?
It is published by petekp in petekp/claude-code-setup. It has 55 recorded installs.
More from petekp/claude-code-setup
code-comments
petekp/claude-code-setup
Write, review, or remove code comments. Use when adding comments or doc comments, reviewing the comments in a diff, or cleaning up or removing comments.
deep-research
petekp/claude-code-setup
Investigate a question that requires sustained research across sources and produce cited findings. Use for deep research requests; skip ordinary lookups and single-document reviews.
exhaustive-systems-analysis
petekp/claude-code-setup
Open the skill to read its SKILL.md instructions.
typography
petekp/claude-code-setup
Apply professional typography principles to create readable, hierarchical, and aesthetically refined interfaces. Use when setting type scales, choosing fonts, adjusting spacing, designing text-heavy layouts, implementing dark mode typography, or when asked about readability, font pairing, line height, measure, typographic hierarchy, variable fonts, font loading, or OpenType features.
claude-code-audit
petekp/claude-code-setup
Forensic audit of the user's recent Claude Code sessions to surface step-change workflow improvements — not marginal ones. Use when the user asks to "audit my Claude Code sessions", "analyze how I use Claude Code", "find patterns in my usage", "improve my Claude Code workflow", "review my sessions", "find leverage in my setup", or wants to understand where their Claude Code setup is leaking time. Samples dozens of real transcripts, extracts quantitative signal via scripts, uses parallel subagents for deep reads, then synthesizes into a short prioritized report with drafted implementations (new skills, CLAUDE.md rules, hooks, settings diffs) that the user can install directly. Trigger even when the user doesn't say the word "audit" — if they're asking about improving or reviewing their Claude Code habits at scale, use this skill.
literate-guide
petekp/claude-code-setup
Create a narrative guide to a codebase or feature in the style of Knuth's Literate Programming — code and prose interwoven as a single essay, ordered for human understanding rather than compiler needs. Use when the user asks to 'explain this codebase as a story', 'write a literate guide', 'create a narrative walkthrough', 'tell the story of this code', 'Knuth-style documentation', 'weave a guide for this feature', or when they want deep, readable documentation that treats the program as literature. Also trigger when someone wants a document that a thoughtful reader could follow from start to finish and come away understanding both WHAT the code does and WHY every design choice was made.
Popular testing & qa skills
tdd
mattpocock/skills
Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.
grilling
mattpocock/skills
Grill the user relentlessly about a plan, decision, or idea. Use when the user wants to stress-test their thinking, or uses any 'grill' trigger phrases.
migrate-to-shoehorn
mattpocock/skills
Migrate test files from as type assertions to @total-typescript/shoehorn. Use when user mentions shoehorn, wants to replace as in tests, or needs partial test data.
run-train
lllllllama/rigorpilot-skills
Rigor Train skill for deep learning research repositories. Use when a documented or selected training command should be run conservatively for startup verification, short-run verification, full kickoff, or resume, with command, config, seed, log, checkpoint, status, and metric evidence written to standardized trainoutputs/. Do not use for environment setup, exploratory sweeps, speculative idea implementation, or end-to-end orchestration.
test-driven-development
obra/superpowers
Use when implementing any feature or bugfix, before writing implementation code
finishing-a-development-branch
obra/superpowers
Use when implementation is complete, all tests pass, and you need to decide how to integrate the work