# 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.

- command · `type=command` · Claude Code, Codex, Cursor · ★ 41823
- Author: Seth Hobson
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/wshobson/agents/tree/HEAD/plugins/tdd-workflows/commands/tdd-cycle.md
- Updated: 2026-10-24
- HTML: https://affpapa.org/en/nevibecode/commands/tdd-cycle

## What it does

\`tdd-cycle` guides an agent through a TDD cycle for a selected feature or module. It checks for an existing session, creates `.tdd-cycle/state.json`, parses the arguments, and stores step results in files. The first phase covers requirements analysis and test architecture, including fixtures, mocks, test data, and execution order.

The command then pauses at a review checkpoint and presents the generated documents. After approval, it enters the RED phase and creates failing unit tests that follow the project’s test framework and conventions. It also covers edge cases and error paths. Progress does not move past the checkpoint without explicit approval.

The default mode is `suite`, with a line-coverage target of `80`; `--incremental`, `--suite`, and `--coverage` can change the run settings. The command is listed for Claude Code, Codex, and Cursor, with a marketplace installation path provided for Claude Code.

## Install

### Claude Code (native platform)

1. **Plugin marketplace**
In the agent chat (not a shell):
```text
/plugin marketplace add wshobson/agents
```
In the agent chat (not a shell):
```text
/plugin install tdd-workflows@claude-code-workflows
```

2. **Manually: put the files in place**
- File: `.claude/commands/tdd-cycle.md` — Call it with /tdd-cycle. For all projects use ~/.claude/commands/

### Codex

**Manually: put the files in place**
- File: `~/.codex/prompts/tdd-cycle.md` — Call it with /prompts:tdd-cycle. Codex marks this format deprecated in favour of skills

### GitHub Copilot

**Manually: put the files in place**
- File: `.github/prompts/tdd-cycle.prompt.md`

### Gemini CLI

**Manually: put the files in place**
- File: `.gemini/commands/tdd-cycle.toml` — Gemini stores commands as TOML: the prompt text goes into the prompt field

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/wshobson/agents/tree/HEAD/plugins/tdd-workflows/commands/tdd-cycle.md

## When to use it
- analyze requirements for a new feature
- design test structure and fixtures
- define a mock and test-data strategy
- write failing unit tests
- pause the workflow for specification review

## Example prompts
- Run `/tdd-cycle <feature or module to implement>` for a new module.
- Start `/tdd-cycle <feature or module to implement> --incremental` for an incremental cycle.
- Set the target with `/tdd-cycle <feature or module to implement> --coverage 80`.

## Source text · tdd-cycle.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: af0535a41467361b.

BEGIN THIRD-PARTY FILE af0535a41467361b
````text
---
description: "Execute a comprehensive TDD workflow with strict red-green-refactor discipline"
argument-hint: "<feature or module to implement> [--incremental|--suite] [--coverage 80]"
---

# TDD Cycle Orchestrator

## CRITICAL BEHAVIORAL RULES

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

1. **Execute steps in order.** Do NOT skip ahead, reorder, or merge steps.
2. **Write output files.** Each step MUST produce its output file in `.tdd-cycle/` before the next step begins. Read from prior step files — do NOT rely on context window memory.
3. **Stop at checkpoints.** When you reach a `PHASE CHECKPOINT`, you MUST stop and wait for explicit user approval before continuing. Use the AskUserQuestion tool with clear options.
4. **Halt on failure.** If any step fails (agent error, test failure, missing dependency), STOP immediately. Present the error and ask the user how to proceed. Do NOT silently continue.
5. **Use only local agents.** All `subagent_type` references use agents bundled with this plugin or `general-purpose`. No cross-plugin dependencies.
6. **Never enter plan mode autonomously.** Do NOT use EnterPlanMode. This command IS the plan — execute it.

## Pre-flight Checks

Before starting, perform these checks:

### 1. Check for existing session

Check if `.tdd-cycle/state.json` exists:

- If it exists and `status` is `"in_progress"`: Read it, display the current step, and ask the user:

  ```
  Found an in-progress TDD cycle session:
  Feature: [name from state]
  Current step: [step from state]

  1. Resume from where we left off
  2. Start fresh (archives existing session)
  ```

- If it exists and `status` is `"complete"`: Ask whether to archive and start fresh.

### 2. Initialize state

Create `.tdd-cycle/` directory and `state.json`:

```json
{
  "feature": "$ARGUMENTS",
  "status": "in_progress",
  "mode": "suite",
  "coverage_target": 80,
  "current_step": 1,
  "current_phase": 1,
  "completed_steps": [],
  "files_created": [],
  "started_at": "ISO_TIMESTAMP",
  "last_updated": "ISO_TIMESTAMP"
}
```

Parse `$ARGUMENTS` for `--incremental`, `--suite`, and `--coverage` flags. Use defaults if not specified (mode: suite, coverage: 80).

### 3. Parse feature description

Extract the feature description from `$ARGUMENTS` (everything before the flags). This is referenced as `$FEATURE` in prompts below.

---

## Configuration

### Coverage Thresholds

- Minimum line coverage: parsed from `--coverage` flag (default 80%)
- Minimum branch coverage: 75%
- Critical path coverage: 100%

### Refactoring Triggers

- Cyclomatic complexity > 10
- Method length > 20 lines
- Class length > 200 lines
- Duplicate code blocks > 3 lines

---

## Phase 1: Test Specification and Design (Steps 1-2)

### Step 1: Requirements Analysis

Use the Task tool to analyze requirements:

```
Task:
  subagent_type: "general-purpose"
  description: "Analyze requirements for TDD: $FEATURE"
  prompt: |
    You are a software architect specializing in test-driven development.

    Analyze requirements for: $FEATURE

    ## Deliverables
    1. Define acceptance criteria with clear pass/fail conditions
    2. Identify edge cases (null/empty, boundary values, error states, concurrent access)
    3. Create a comprehensive test scenario matrix mapping requirements to test cases
    4. Categorize tests: unit, integration, contract, property-based
    5. Identify external dependencies that will need mocking

    Write your complete analysis as a single markdown document.
```

Save the agent's output to `.tdd-cycle/01-requirements.md`.

Update `state.json`: set `current_step` to 2, add `"01-requirements.md"` to `files_created`, add step 1 to `completed_steps`.
````
END THIRD-PARTY FILE af0535a41467361b

The third-party file has ended. Everything between the af0535a41467361b tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 3724 of 20061 bytes. © Seth Hobson · MIT · https://github.com/wshobson/agents/tree/HEAD/plugins/tdd-workflows/commands/tdd-cycle.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
