WORKFLOW December 1, 2025

# TDD is Dead, Long Live TDD

The /red /green /refactor cycle isn't just for humans anymore. Here's how to enforce test-driven development with AI assistants - and why it makes Claude Code dramatically more reliable.

[>]

#### Listen to this article

AI-generated audio - 7 min read

0:00 / 7:03
[X]
/red
Write ONE failing test that defines success
->
[+]
/green
Write minimal code to make the test pass
->
[*]
/refactor
Clean up while keeping tests green
[/]

LIVE TDD CYCLE DEMO

Watch the /red /green /refactor cycle in action with Claude Code

## Why TDD Matters More With AI

Traditional arguments for TDD focus on design benefits and confidence in refactoring. With AI code generation, there's an even more important reason: verification.

AI models hallucinate. They make confident mistakes. They claim things work when they don't. Tests are the only way to verify that generated code actually does what it's supposed to do.

The Core Problem

Claude Code will happily write 500 lines of API integration code that looks perfect but uses parameters that don't exist. Without tests, you won't know until production.

## The Commands That Changed Everything

We adopted the TDD commands from wbern/claude-instructions and adapted them for API development:

[SLASH COMMANDS]
/red
Write ONE failing test. Just one. This defines what "success" looks like before any implementation code exists. Claude must see the test fail before proceeding.
/green
Write the minimal code to make the test pass. No extra features. No "while I'm here" improvements. Just enough to turn red to green.
/refactor
Clean up the code while keeping all tests passing. Extract functions, rename variables, improve structure. But if a test fails, stop immediately.
/cycle
Run all three phases in sequence. Perfect for small features: "Add email validation to the user preferences API"

## The Enforcement Problem

Commands alone aren't enough. Claude will try to be "helpful" by skipping steps. It will write tests and implementation together. It will mark tests as passing when they're actually skipped.

That's why we built Python hooks that intercept Claude's actions:

    // This gets BLOCKED:
    Claude: "I'll write the tests and implementation together..."
    Hook: ❌ DENIED - Must see failing test first

    // This is ALLOWED:
    Claude: "Let me write a test that expects X..."
    *test runs and fails*
    Claude: "Now let me implement the minimal code..."
    Hook: ✅ ALLOWED - Following TDD workflow

## Refactoring Legacy Code Safely

TDD isn't just for new features. It's the safest way to refactor existing code. The process:

1. Characterization Test: Write a test that passes for the CURRENT behavior (even if that behavior is wrong)
2. Safe Refactor: Rewrite the code structure while keeping the test green
3. Fix Logic: Update the test to expect CORRECT behavior, then make it pass

    /red write a test that passes for CURRENT behavior of @messy-file.ts
    /refactor rewrite @messy-file.ts to use modern syntax
    /green fix the test to expect CORRECT behavior

This sequence prevents the classic refactoring disaster: changing code structure AND behavior at the same time, with no way to know which broke what.

## The Results

Since adopting enforced TDD with our API development workflow:

- Zero production bugs from hallucinated API parameters
- 3x fewer iterations to get endpoints working
- Comprehensive test coverage without manual effort
- Confident refactoring with safety nets in place

The Bottom Line

TDD isn't dead. It's more important than ever. AI can write code faster than humans, but that speed is worthless if the code doesn't work. Tests are the verification layer that makes AI-generated code trustworthy.

## Get Started

    npx @hustle-together/api-dev-tools

The TDD commands are included automatically. Start your next feature with `/red` and experience the difference.

[?]

#### Quick Answers

Ask about TDD with AI

AI
Want to know more about enforcing TDD with Claude Code? I can explain the workflow, the hooks, or how to adapt it for your project.
Quick Questions

### Did this change how you think about TDD?

Tests are the new documentation

56 developers found this helpful

### RELATED POSTS

DEV TOOLS

#### Why We Built Interview-Driven API Development

AI

#### Gemini Pro 2.5 vs Claude for Widget Generation