← Back to blog
|6 min read

How to Enforce TDD in Claude Code with One Shot Ship

Claude Code is transforming how developers write software. But speed without discipline produces fragile code. Here is how to enforce strict test-driven development in every session.

The Problem: AI Speed Without Test Discipline

Claude Code is one of the most capable AI coding assistants available. It can generate entire features, refactor complex codebases, and ship production code in minutes. But there is a gap that no amount of raw intelligence can fill: discipline.

By default, Claude Code does not enforce test-driven development. It will happily write hundreds of lines of production code without a single test. Developers fall into what many call “vibe coding” — generating code that looks right, seems to work, and ships without verification. The result is brittle features that break under edge cases, regressions that slip into production, and a codebase that becomes harder to change over time.

The core issue is not with AI-generated code quality. It is with process. Without an enforced TDD workflow, developers skip the step that matters most: proving the code works before shipping it.

What is RED-GREEN-REFACTOR?

Test-driven development follows a strict three-phase cycle known as RED-GREEN-REFACTOR. Each phase has a specific purpose and must be completed in order.

RED

Write a failing test first. The test defines the behavior you want. It must fail before you write any production code. This proves your test is actually checking something.

GREEN

Write the absolute minimum code to make the test pass. Nothing more. No extra features, no future-proofing, no gold-plating. If you can pass with three lines, do not write ten.

REFACTOR

Clean up the code while the tests stay green. Improve names, remove duplication, simplify structure. The tests give you confidence that your refactoring does not break anything.

One Shot Ship specifically enforces London-style TDD (also called Outside-In TDD). This approach starts at system boundaries — API endpoints, UI components — and works inward by mocking collaborators. It drives cleaner interfaces, faster feedback loops, and better separation of concerns compared to the bottom-up alternative.

How One Shot Ship Enforces TDD

One Shot Ship is a Claude Code plugin that adds a discipline layer to every coding session. Instead of relying on developers to remember best practices, it enforces them through dedicated commands and rules that Claude Code follows automatically.

Dedicated TDD Commands

The plugin provides three commands that map directly to the TDD cycle:

  • /oss:redWrites a failing test at the system boundary. Designs interfaces through mock expectations. Ensures the test fails with a meaningful assertion error before proceeding.
  • /oss:greenWrites the minimal production code to make the failing test pass. Nothing extra. If the test passes with a hardcoded return value, that is enough for the GREEN phase.
  • /oss:refactorCleans up code while verifying tests remain green. Removes duplication, improves naming, and simplifies structure with the safety net of passing tests.

The Build Command: Full-Cycle Enforcement

The /oss:build command takes a plan and executes every task using the RED-GREEN-REFACTOR cycle automatically. It will not move to the next task until the current one has a failing test, passing implementation, and clean refactored code. There is no way to skip ahead.

Iron Laws: Non-Negotiable Rules

One Shot Ship injects a set of Iron Laws into every Claude Code session. These rules are non-negotiable. If Claude detects code written without a failing test first, it announces the violation and self-corrects by deleting the untested code and restarting with a proper failing test. No human intervention needed.

Status Bar: Always Know Your Phase

The plugin includes a status bar that shows the current TDD phase in real time. You always know whether you are in RED, GREEN, or REFACTOR. This small detail makes a big difference in maintaining awareness of where you are in the cycle, especially during long coding sessions.

Example: From Idea to Shipped Feature

Here is a typical workflow using One Shot Ship to add user authentication to a project. Every step enforces TDD automatically.

# 1. Explore and design the feature
/oss:ideate "add user authentication"
# 2. Create a TDD implementation plan with tasks
/oss:plan
# 3. Execute: each task goes through RED-GREEN-REFACTOR
/oss:build
← enforces failing test before any production code
# 4. Quality check, commit, and open a PR
/oss:ship
← blocks shipping if any tests fail

Between steps 3 and 4, every single task in the plan has gone through the full TDD cycle. There are no untested features. No skipped edge cases. The /oss:ship command verifies that all tests pass before creating a commit and opening a pull request. If anything fails, it stops and tells you what to fix.

Why This Matters

Ship faster with fewer bugs

Teams that practice TDD consistently report fewer production defects and less time spent debugging. When every feature has tests from day one, regressions get caught immediately. You spend less time firefighting and more time building.

Tests become living documentation

Well-written tests describe what the system does better than any README. When a new developer joins the team, they can read the test suite to understand intended behavior. Tests written at system boundaries are readable even by non-engineers.

Refactor with confidence

A comprehensive test suite means you can restructure code without fear. Rename a module, extract a service, change an algorithm — if the tests still pass, the behavior is preserved. Without tests, every refactor is a gamble.

AI-generated code becomes verifiable

This is the key insight for teams using AI coding tools. When Claude Code generates production code, you need a way to verify it works correctly. TDD provides that verification automatically. The failing test defines the expected behavior. The AI writes code to satisfy it. If the test passes, the code is correct by definition.

Stop shipping untested code

Try One Shot Ship free for 7 days. Install the Claude Code plugin, run your first /oss:build, and see what enforced TDD feels like.