Test-Driven Development (TDD) Agent Loop Prompt
Force AI coding agents to follow the Red-Green-Refactor cycle: write failing tests first, then write minimal code to pass.
Interactive Prompt Playground
{{FEATURE_REQUIREMENT}}{{TEST_COMMAND}}You are an Autonomous AI Engineer operating strictly under Test-Driven Development (TDD) principles. Implement this feature using the strict RED-GREEN-REFACTOR cycle: Feature Requirement: ``` Create a TokenBucketRateLimiter class that supports configurable capacity, refill rates, and atomic tryConsume(tokens) operations. ``` Test Runner Command: `npx vitest run tests/rate-limiter.test.ts` Execute this task in atomic phases without skipping steps: ### Phase 1: RED (Write Failing Tests First) 1. Write comprehensive unit/integration test cases covering happy path, edge cases, and error scenarios. 2. Run `npx vitest run tests/rate-limiter.test.ts` and verify that the tests fail for the EXPECTED reason (missing implementation). 3. Do NOT write any implementation code until the failing test run is confirmed. ### Phase 2: GREEN (Minimal Implementation) 1. Write the simplest, cleanest implementation code necessary to make the tests pass. 2. Run `npx vitest run tests/rate-limiter.test.ts` and verify that 100% of tests are passing. ### Phase 3: REFACTOR (Clean Code & Types) 1. Refactor the code for readability, type safety, and clean architecture without breaking any tests. 2. Re-run `npx vitest run tests/rate-limiter.test.ts` to ensure zero regressions. Summarize the results of each phase in your final response.
How to Use This Prompt
- Paste your target feature requirements and test execution command.
- Send to Claude Code, Cursor Agent, or Cline.
- Watch the agent execute clean Red -> Green -> Refactor milestones.
Engineering Tips & Best Practices
- Specify exact test file paths in the test command to keep feedback loops lightning fast.
What This Prompt Inspects
Key failure modes, design principles, and quality standards evaluated during execution.
Strict Red Phase
Prevents AI from writing implementation code before verifying failing tests.
Minimal Green Implementation
Stops AI from over-engineering features beyond test specifications.
Refactor Safety
Guarantees tests remain green through cleanup phases.
SprintKit Workflow Integrations
Complementary interactive tools and workflows across SprintKit to accelerate your engineering process.
Related Prompts
Explore related developer prompts in this workflow domain.
Unit Test Suite Generator with Edge Cases
Generate comprehensive, mutation-tested unit tests with AAA pattern, boundary cases, and proper mock boundaries.
Autonomous Coding Agent Implementation Plan Generator
Instruct coding agents (Cursor, Claude Code, Cline) to generate actionable multi-step implementation plans before touching code.
Cursor & Windsurf Rules Generator (.cursorrules / .windsurfrules)
Generate a custom, context-rich project rules file that stops AI coding agents from making recurring mistakes.