Agent Test-Driven Red-Green-Refactor Loop
Force Claude to design an interface, confirm behaviors to test, then loop red, green, refactor one test at a time.
Before & after
Same prompt, same agent — the only difference is the skill.
Test-driven development is a solid approach for ensuring code quality. You'd write a failing test first, then write the minimal code to make it pass, and finally refactor for clarity. The key is to do one test at a time. You should think about edge cases like empty input, malformed data, and normal cases. I could help you plan which tests to write and in what order. It might be useful to mock some dependencies. What testing framework are you using?
FAILING TEST 1: parseDoc handles valid input
test('parses single paragraph into tokens', () => {
const doc = 'Hello world';
const result = parseDoc(doc);
expect(result.first().type).toBe('token');
});
MINIMAL PASS: Split input by space, return array of objects with type equal to token
REFACTOR CANDIDATE: Extract tokenizer into separate function
FAILING TEST 2: parseDoc handles empty input
test('returns empty array for blank document', () => {
expect(parseDoc('')).toEqual(emptyArray);
});
MINIMAL PASS: Add guard clause
REFACTOR CANDIDATES
• Move whitespace handling to tokenizer
• Add token position tracking
• Extract boundary detection logic
COVERAGE DELTA: 41% to 64%
MOCK INVENTORY: None yet; next loop consider faking file I/OAbout this skill
name: agent-tdd-red-green-refactor description: Force Claude to design an interface, confirm behaviors to test, then loop red, green, refactor one test at a time. Use when working on agent test-driven red-green-refactor loop.
Agent Test-Driven Red-Green-Refactor Loop
A meaty skill that folds in guidance on interfaces vs implementations, deep modules, and mocking. Claude confirms interface changes with you, designs for testability, writes a failing test, makes it pass, then evaluates refactor candidates. Best used to power autonomous Ralph loops so code quality stays high without human hand-holding. Use on any real production code where quality matters more than raw speed.
What you get
- Test list
- Running red-green-refactor log
- Refactor candidates surfaced at loop end
- Interface change summary
- Mock inventory
- Coverage delta
Customize your output
- Test framework: Jest, Vitest, Pytest, XCTest, JUnit, other
- Language: TypeScript, Python, Swift, Java, Go
- Mocking rules: prefer stubs, prefer fakes, no mocks
- Interface style: deep modules, wide flat
- Tests per loop: 1, 3, 5
- Coverage floor: 60, 80, 90 percent
Example output
'Failing test for parseDoc(). Minimal implementation. Second failing test for empty input. Refactor to extract tokenizer.'
Best for
Devs using Claude Code on real production repos where quality matters.
Note: Requires a codebase with clean module boundaries to shine. High confidence.
SKILL.md preview
---
name: agent-tdd-red-green-refactor
description: Use this skill on real production code where quality matters more than raw speed, to force a disciplined interface-first, one-test-at-a-time TDD loop.
version: 1.0.0
category: Engineering
author: AgentVolt
license: proprietary
tags:
- engineering
- p4
---
# Agent Test-Driven Red-Green-Refactor Loop
Forces a disciplined TDD loop: design the interface, confirm behaviors with the user, then cycle red, green, refactor one test at a time.
## When to use
… (sign up to view the full skill)