Skip to main content
command CX Codex

tdd-green — Claude Code command: what it does, how to install

Writes the minimal code required to pass failing tests during the TDD green phase. Keeps scope tight without premature optimizations.

Install into Claude Code · Plugin marketplace All methods and platforms ↓
/plugin marketplace add wshobson/agents
/plugin install tdd-workflows@claude-code-workflows
Open on GitHub

What tdd-green does

The command directs a general-purpose subagent to resolve failing tests with minimal edits. It takes test file paths or failure descriptions as arguments. When generating code, the agent applies classic TDD strategies: returning hard-coded values or implementing the most obvious straightforward solution.

Execution adheres to strict boundaries. The subagent verifies test status after each modification and avoids speculative features. If a test remains red or breaks existing suites, the command halts and outputs the error immediately instead of attempting an uncontrolled rewrite.

What it helps with

  • pass failing tests with the smallest possible code change
  • avoid speculative features and premature optimizations
  • log technical debt ahead of the refactoring step

Example prompts for the agent

  • /tdd-green tests/auth.test.ts
  • /tdd-green "fix failing calculateTotal test on zero balance"
  • /tdd-green src/orders/order.spec.ts

How to install tdd-green

1Plugin marketplace

/plugin marketplace add wshobson/agents
/plugin install tdd-workflows@claude-code-workflows

2Manually: put the files in place

.claude/commands/tdd-green.md

Call it with /tdd-green. For all projects use ~/.claude/commands/

Questions about tdd-green

How to install tdd-green in Claude Code?

First add the marketplace repository with /plugin marketplace add wshobson/agents, then run /plugin install tdd-workflows@claude-code-workflows.

What does tdd-green do?

It implements production code strictly needed to turn red tests green. Tests run after every edit, while architectural decisions remain deferred to refactoring.

What happens if tests continue to fail?

Execution stops right away to present the error to the user rather than rebuilding the codebase from scratch.

Source text

tdd-green.md · MIT
---
description: "Implement minimal code to make failing tests pass in TDD green phase"
argument-hint: "<description of failing tests or test file paths>"
---

# TDD Green Phase

## CRITICAL BEHAVIORAL RULES

You MUST follow these rules exactly. Violating any of them is a failure.

1. **Implement only what tests require.** Do NOT add features, optimizations, or error handling beyond what failing tests demand.
2. **Run tests after each change.** Verify progress incrementally — do not batch implement and hope it works.
3. **Halt on failure.** If tests remain red after implementation or existing tests break, STOP and present the error to the user.
4. **Use only local agents.** All `subagent_type` references use agents bundled with this plugin or `general-purpose`. No cross-plugin dependencies.
5. **Never enter plan mode autonomously.** Do NOT use EnterPlanMode. Execute directly.

## Implementation Process

Use the Task tool to implement minimal passing code:

```
Task:
  subagent_type: "general-purpose"
  description: "Implement minimal code to pass failing tests"
  prompt: |
    You are a test automation expert implementing the GREEN phase of TDD.

    Implement MINIMAL code to make these failing tests pass: $ARGUMENTS

    Follow TDD green phase principles:

    1. **Pre-Implementation Analysis**
       - Review all failing tests and their error messages
       - Identify the simplest path to make tests pass
       - Map test requirements to minimal implementation needs
       - Avoid premature optimization or over-engineering
       - Focus only on making tests green, not perfect code

    2. **Implementation Strategy**
       - **Fake It**: Return hard-coded values when appropriate
       - **Obvious Implementation**: When solution is trivial and clear
       - **Triangulation**: Generalize only when multiple tests require it
       - Start with the simplest test and work incrementally
       - One test at a time — don't try to pass all at once

    3. **Code Structure Guidelines**
       - Write the minimal code that could possibly work
       - Avoid adding functionality not required by tests
       - Use simple data structures initially
       - Defer architectural decisions until refactor phase
       - Keep methods/functions small and focused
       - Don't add error handling unless tests require it

    4. **Progressive Implementation**
       - Make first test pass with simplest possible code
       - Run tests after each change to verify progress
       - Add just enough code for next failing test
       - Resist urge to implement beyond test requirements
       - Keep track of technical debt for refactor phase
       - Document assumptions and shortcuts taken

    5. **Success Criteria**
       - All tests pass (green)
       - No extra functionality beyond test requirements
       - Code is readable even if not optimal
       - No broken existing functionality
       - Clear path to refactoring identified

    Output should include:
    - Complete implementation code
    - Test execution results showing all green
    - List of shortcuts taken for later refactoring
    - Technical debt documentation
    - Readiness assessment for refactor phase
```

## Post-Implementation Checks

After implementation:

1. Run full test suite to confirm all tests pass
2. Verify no existing tests were broken
3. Document areas needing refactoring
4. Check implementation is truly minimal
5. Record implementation time for metrics

## Recovery Process

If tests still fail:

- Review test requirements carefully
- Check for misunderstood assertions
- Add minimal code to address specific failures
- Avoid the temptation to rewrite from scratch
- Consider if tests themselves need adjustment

## Integration Points

- Follows from tdd-red test creation
- Prepares for tdd-refactor improvements
- Updates test coverage metrics
- Triggers CI/CD pipeline verification
- Documents technical debt for tracking

© Seth Hobson · MIT · wshobson/agents

Similar slash commands

All slash commands for Testing and QA →
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 test-driven-development addyosmani This skill guides work through red-green-refactor: write a failing test, add the smallest passing code, then refactor. Use it for logic, bugs, and behavior changes. CX Codex +1 62,000installs 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 review-pr official Anthropic This command uses specialized agents to review PR changes, covering tests, error handling, types, comments, and general code quality. ★ 44,770repo stars modernize-uplift official Anthropic Uplifts existing code to a newer runtime version within the same stack while preserving business logic and proving behavioral equivalence through tests. ★ 44,770repo stars docs-maintenance davila7 This command audits documentation, links, structure, and style, then helps plan updates. Use it when Markdown docs need recurring checks. 1,146installs nextjs-performance-audit davila7 This command checks a Next.js project’s Lighthouse results, bundle size, and runtime performance. Use it to find performance issues and get optimization suggestions. 694installs

From the same set432

The whole set →
standup-notes Builds async standup notes from git commits, Jira tickets and Obsidian notes. Useful when the team is spread across time zones. CX Codex ★ 41,823repo stars issue Resolves GitHub issues through triage, root cause analysis, test-driven implementation, and pull requests. Keeps bug fixing structured. CX Codex ★ 41,823repo stars tdd-refactor This command refactors code through the TDD refactor phase while keeping tests green. Use it for controlled structural changes without altering behavior. CX Codex ★ 41,823repo stars tdd-red A slash command that writes only tests which must fail, and leaves production code alone. The first step of TDD, when behavior needs pinning down before implementation. CX Codex ★ 41,823repo stars tdd-cycle This command runs a red-green-refactor TDD workflow for a feature or module. It reviews the test plan at a checkpoint before writing failing tests. CX Codex ★ 41,823repo stars rust-project A slash command that lays out a Rust project skeleton: binary, library, workspace or Axum web API. Useful when you want module layout and tooling without doing it by hand. CX Codex ★ 41,823repo stars market-opportunity A slash command that walks you through market sizing: TAM, SAM and SOM, ending in a markdown report. Useful when you need numbers for a startup pitch. CX Codex ★ 41,823repo stars financial-projections Builds a startup financial model: cohort revenue, costs, headcount, cash flow and three scenarios. Useful before a raise or a board meeting. CX Codex ★ 41,823repo stars

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