TDD In Vertical Slices: Agent Skill (SKILL.md) for Claude Code, Codex and Cursor

Implements a feature test-first, one small user-visible behavior at a time: write a failing test, confirm it fails for the right reason, write the least code to pass, refactor while green, checkpoint, and log each cycle.

Prompt

Installs to .agents/skills/tdd-in-vertical-slices-agent-skill-skill-md-for-claude-code-code/

mkdir -p .agents/skills/tdd-in-vertical-slices-agent-skill-skill-md-for-claude-code-code && curl -sL "https://prompts-gpt.com/prompts/tdd-in-vertical-slices-agent-skill-skill-md-for-claude-code-codex-and-cursor/raw" -o .agents/skills/tdd-in-vertical-slices-agent-skill-skill-md-for-claude-code-code/SKILL.md
SKILL.md
Preview
---
name: tdd-in-vertical-slices-agent-skill-skill-md-for-claude-code-code
description: "Implements a feature test-first, one small user-visible behavior at a time: write a failing test, confirm it fails for the right reason, write the least code to pass, refactor while green, checkpoint, and log each cycle."
---

# TDD In Vertical Slices: Agent Skill (SKILL.md) for Claude Code, Codex and Cursor

Implements a feature test-first, one small user-visible behavior at a time: write a failing test, confirm it fails for the right reason, write the least code to pass, refactor while green, checkpoint, and log each cycle.

## Prompt

```
---
name: tdd-vertical-slices
description: "Implements a feature test-first, one small user-visible behavior at a time: write a failing test, confirm it fails for the right reason, write the least code to pass, refactor while green, checkpoint, and log each cycle. Use when asked to do TDD, write tests first, red-green-refactor, or build a feature in small tested steps."
---

# TDD in vertical slices

## Steps

1. Find the test command and framework the repo already uses (package scripts, Makefile, CI config). Use them; don't add a new framework.
2. List the behaviors the feature needs as short user-visible statements ("rejects an expired coupon"). Order them smallest and most central first. Show the list before starting.
3. Pick the next behavior. Write one test for it at the highest seam that is still fast: a module's public API, an HTTP handler, a component as the user sees it.
4. Run the test. Confirm it fails, and that it fails for the right reason: an assertion about the behavior, not a typo, import error or missing fixture. If it passes, the test is wrong or the behavior already exists; fix the test or move on.
5. Write the least production code that makes it pass. Hard-coding is fine if a later test will force the general case.
6. Run the test and the related test files. Everything is green.
7. Refactor while green: names, duplication, structure. Run the tests after each change.
8. Checkpoint: commit with a message naming the behavior if the user wants a commit per cycle; otherwise note the cycle as a checkpoint and leave committing to them.
9. Add a row to the cycle log and go back to step 3.

## Rules

- No production code without a failing test that needs it.
- One behavior per cycle. If a test needs two things to change, split it.
- Never change a test and the code in the same step to get to green.
- Test through public interfaces. Don't mock your own internals; mock only at system edges (network, clock, randomness, paid APIs).
- Don't use snapshot tests for logic; keep them for stable output formats.
- Assert outcomes, not implementation details such as which function was called or in what order.
- If two attempts don't get the test green, undo the production changes since the last green checkpoint and split the behavior into a smaller one.
- Don't skip the run where you watch it fail, even when you're sure.

## Example output

| # | Behavior | Test | Failed because | Change | Result |
|---|---|---|---|---|---|
| 1 | Applies a 10% coupon | `cart.test.ts: applies percent coupon` | total was 100, expected 90 | added `applyCoupon` | green, committed |
| 2 | Rejects an expired coupon | `cart.test.ts: rejects expired` | no error thrown | date check in `applyCoupon` | green, extracted date helper, committed |
```

## Usage Notes

Save as .claude/skills/tdd-vertical-slices/SKILL.md in one project (or ~/.claude/skills/tdd-vertical-slices/ for all of them); Codex reads .agents/skills/tdd-vertical-slices/SKILL.md. Then ask for the job in plain words and the agent loads it. Or install with: npx skills add prompts-gpt/skills --skill tdd-vertical-slices.

Example output

At a glanceSix TDD cycles for login rate limitingFinal run: 47 passed, 0 failed (6 new, 41 existing)
  1. Allows attempt under the limitCycle 1Passed immediately; kept test as a guard
  2. 429 after 5 failuresCycle 2Added loginLimiter middleware, limit 5
  3. Retry-After headerCycle 3Set Retry-After: 900 on 429
  4. Window resets after 15 minCycle 4Injected now() clock, faked with vi.useFakeTimers
  5. Per-IP trackingCycle 5Fixed test typo, keyed map by req.ip
  6. Success clears countCycle 6Reset on success; extracted RateLimitStore

Example for: adding rate limiting to the POST /api/login endpoint in a TypeScript Express app using Vitest + Supertest, one commit per cycle.

Test command found: npm run test → vitest run (from package.json; CI runs the same in .github/workflows/ci.yml). Using Vitest + Supertest already in devDependencies.

Behaviors (in order):

  1. Allows a login attempt under the limit
  2. Returns 429 after 5 failed attempts from the same IP within 15 minutes
  3. Includes a Retry-After header on a 429
  4. Resets the count after the 15-minute window passes
  5. Tracks limits per IP, not globally
  6. A successful login clears the failure count for that IP

Cycle log

#BehaviorTestFailed becauseChangeResult
1Allows attempt under the limitlogin.test.ts: allows first attemptpassed immediately, since behavior already existsnone; kept test as a guardgreen, moved on
2429 after 5 failureslogin.test.ts: blocks 6th failed attemptexpected 429, got 401added loginLimiter middleware with in-memory Map<ip, count>, hard-coded limit 5green, committed
3Retry-After headerlogin.test.ts: sets Retry-After on 429header was undefinedset Retry-After: 900 in limiter's block branchgreen, committed
4Window resets after 15 minlogin.test.ts: allows again after windowstill 429 after advancing clockstored firstFailureAt; injected now() clock (system edge, faked with vi.useFakeTimers)green; refactored Retry-After to compute remaining seconds, committed
5Per-IP trackinglogin.test.ts: other IP unaffectedfirst attempt was a test typo (X-Forwarded-For misspelled), so it failed for the wrong reason; fixed test and reran, then got 429 for second IP, expected 401keyed map by req.ip; enabled trust proxy in test app setupgreen, committed
6Success clears countlogin.test.ts: success resets failures6th attempt after a success returned 429loginLimiter.reset(ip) called on successful authgreen; extracted RateLimitStore class, committed

Notes

  • Cycle 4: the first attempt mixed window logic with header math and stayed red after two tries. I reverted to the cycle 3 checkpoint and split it, so the header refactor happened only after the reset behavior was green.
  • No internals mocked. Only the clock is faked. All tests go through Supertest against the real Express app.
  • Final run: vitest run gave 47 passed, 0 failed (6 new, 41 existing).

Commits:

feat(login): block after 5 failed attempts per window
feat(login): send Retry-After on rate-limited response
feat(login): reset failure window after 15 minutes
feat(login): track login failures per client IP
feat(login): clear failure count on successful login
Written by AI from this prompt. Your results will vary.

Save as .claude/skills/tdd-vertical-slices/SKILL.md in one project (or ~/.claude/skills/tdd-vertical-slices/ for all of them); Codex reads .agents/skills/tdd-vertical-slices/SKILL.md. Then ask for the job in plain words and the agent loads it. Or install with: npx skills add prompts-gpt/skills --skill tdd-vertical-slices.

Make it repeatable

Keep using this prompt without pasting it in every time.

Prompt details

By
Prompts-GPT editors
Published
How prompts are written and checked

Did this prompt work?

Keep exploring

More in AI Coding Agents