agentleFS
rlajousrlajous/claude-code-commands/skills/tdd/SKILL.md

tdd

Skill30 starsChanged 3 months agoMITView on GitHub

Implement a ticket using Test-Driven Development (RED-GREEN-REFACTOR)

194 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use capture-learning-tools, design-frontend-dev and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • The-Vibe-CompanySkill

    capture-learning-tools

    Turn technical conversations, bugs, CI failures, review comments,

    Also in 5 projects that use this

  • The-Vibe-CompanySkill

    design-frontend-dev

    Clean Impeccable frontend design skill. Use when the user wants to

    Also in 5 projects that use this

  • tristanphvnSkill

    ketchup-video

    Catch the user up like /keel:ketchup, with a short silent video of slides for what happened and the waiting calls as text under it. Use for /keel:ketchup-video.

    Also in 14 projects that use this

  • jaydubya818Skill

    figure-it-out

    Use when novel or multi-phase work needs an auditable workflow and no narrower playbook fits.

    Also in 54 projects that use this

  • jaydubya818Skill

    principle-laziness-protocol

    Apply when a refactor is adding wrappers or abstractions instead of simplifying.

    Also in 45 projects that use this

  • +2 more from The-Vibe-Company
  • +5 more from jaydubya818

The file

Show its rules and text

We split this skill into the rules it gives an agent

23 rules. 0 are common, 21 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 186 edited versions we read keep these.

  • 21

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Check for configuration and context:

    line 16
  2. Distinctive:

    If not provided, prompt the user for it

    line 93
  3. Distinctive:

    If Linear ticket format is detected, use the Linear MCP server:

    line 107
  4. Distinctive:

    If Jira is configured, use the Jira MCP server:

    line 121
  5. Distinctive:

    If GitHub format detected:

    line 135
  6. Distinctive:

    Search for files related to the ticket:

    line 157
  7. Very specific:

    Test file naming convention (*.test.ts, *.spec.ts, *_test.py, etc.)

    line 184
  8. Distinctive:

    Test framework (Jest, Vitest, pytest, go test, etc.)

    line 185
  9. Distinctive:

    Test structure (describe/it, test(), etc.)

    line 186
  10. Distinctive:

    Ask the user to confirm the bug reproduction:

    line 214
  11. Distinctive:

    If test file doesn't exist, create it following project conventions:

    line 241
  12. Distinctive:

    Add more tests before implementing

    line 307
  13. Distinctive:

    Write the minimum code necessary to make tests pass:

    line 311
  14. Distinctive:

    Don't add extra functionality

    line 315
  15. Distinctive:

    Don't optimize yet

    line 316
  16. Distinctive:

    Don't refactor yet

    line 317
  17. Distinctive:

    If tests still fail:

    line 332
  18. Distinctive:

    Ensure no regressions were introduced.

    line 357
  19. Distinctive:

    Add more tests first

    line 370
  20. Distinctive:

    After each refactoring change:

    line 391
  21. Distinctive:

    Ensure tests remain GREEN throughout refactoring.

    line 399
  22. Very specific:

    Update .git-workflow/pr-context.json with TDD information:

    line 451
  23. Distinctive:

    Always write the canonical path.

    line 457

“Common” is measured: kept by at least 6 in 10 of the 186 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Cross-runtime: follow runtime compatibility for invocation, delegation, configuration precedence, state paths, and permissions.

You are helping implement a ticket using Test-Driven Development (TDD). Your task is to guide the user through the RED-GREEN-REFACTOR cycle: write failing tests first, implement code to pass tests, then refactor while keeping tests green.

Step 1: Load Configuration

Check for configuration and context:

# Check for config and context files
if [ -f ".git-workflow/config.yaml" ]; then
  CONFIG_PATH=".git-workflow/config.yaml"
elif [ -f ".claude/config.yaml" ]; then
  CONFIG_PATH=".claude/config.yaml" # legacy read-only fallback
else
  CONFIG_PATH=""
fi
if [ -f ".git-workflow/pr-context.json" ]; then
  CONTEXT_PATH=".git-workflow/pr-context.json"
elif [ -f ".claude/.pr-context.json" ]; then
  CONTEXT_PATH=".claude/.pr-context.json" # legacy read-only fallback
else
  CONTEXT_PATH=""
fi

Load from the resolved CONFIG_PATH (if one exists):

qa:
  tdd:
    confirmBeforeGreen: true
    confirmBeforeRefactor: true
    maxRedAttempts: 3
    runFullSuiteEachPhase: false
    autoStartServer: false
testing:
  unit: auto
  lint: auto
  typeCheck: auto
issueTracker:
  type: auto

Default Values (when no config):

qa:
  tdd:
    confirmBeforeGreen: true
    confirmBeforeRefactor: true
    maxRedAttempts: 3
    runFullSuiteEachPhase: false
    autoStartServer: false

Step 2: Parse Arguments

Extract from $ARGUMENTS:

$ARGUMENTS

Patterns to Extract:

PatternExampleMeaning
Ticket IDPROJ-123, ENG-456Issue tracker ticket
GitHub Issue#789GitHub issue number
Linear URLhttps://linear.app/.../ENG-456/...Extract ticket ID
Jira URLhttps://....atlassian.net/browse/PROJ-123Extract ticket ID

Parsing Logic:

  • Extract ticket ID from URL if provided
  • Linear: Pattern /issue/([A-Z]+-\d+)/
  • Jira: Pattern /browse/([A-Z]+-\d+)
  • GitHub: Pattern issues/(\d+) or #(\d+)

Validation:

  • Ticket ID is required for TDD workflow
  • If not provided, prompt the user for it

Step 3: Fetch Ticket Details

Auto-Detect Issue Tracker Type

Based on ticket format and available MCP servers:

  • ^[A-Z]+-\d+$ with Linear MCP available -> Linear
  • ^[A-Z]+-\d+$ with Jira config/MCP available -> Jira
  • ^#?\d+$ or GitHub URL -> GitHub Issues (via gh CLI)

Linear Integration

If Linear ticket format is detected, use the Linear MCP server:

mcp__linear__get_issue(id: ticketId)

Extract:

  • Title
  • Description
  • Acceptance criteria
  • Labels (to determine bug vs feature)

Jira Integration

If Jira is configured, use the Jira MCP server:

mcp__jira__get_issue(issueKey: ticketId)

Extract:

  • Summary (title)
  • Description
  • Acceptance criteria
  • Issue type (Bug/Story/Task)

GitHub Issues

If GitHub format detected:

gh issue view {issue_number} --repo {owner}/{repo} --json title,body,labels

Determine Ticket Type

From ticket labels/type, determine:

Label/TypeClassificationTDD Behavior
bug, Bug, defectBugInclude reproduction step
feature, Story, enhancementFeatureSkip reproduction
refactor, tech-debtRefactorFocus on existing tests first

Step 4: Explore Codebase

Gather context about the codebase:

Find Related Files

Search for files related to the ticket:

# Search for keywords from ticket title/description
# Look for existing implementations
# Find related test files

Look for:

  • Files matching keywords from ticket
  • Existing test files in same area
  • Related service/controller files
  • Configuration files

Analyze Test Patterns

Identify existing test patterns:

# Find test files
find . -name "*.test.ts" -o -name "*.spec.ts" -o -name "*_test.py" -o -name "*_test.go" | head -20

# Check test framework imports
grep -r "describe\|it\|test\|expect" --include="*.test.*" -l | head -5

Extract:

  • Test file naming convention (*.test.ts, *.spec.ts, *_test.py, etc.)
  • Test framework (Jest, Vitest, pytest, go test, etc.)
  • Test structure (describe/it, test(), etc.)
  • Mock patterns used

Detect Test Framework

Full per-language detection commands, tables, and the detection-results JSON shape: see references/test-frameworks.md.

Step 5: Reproduce Issue (Bugs Only)

Skip this step for features and refactors.

For bugs, attempt to reproduce the issue:

Optional: Start Development Server

If qa.tdd.autoStartServer: true:

# Detect and start dev server (background)
npm run dev &
# or
pnpm dev &
# Wait for server to be ready
sleep 5

Manual Reproduction

Ask the user to confirm the bug reproduction:

Question: "Can you reproduce the bug? Describe the steps and current behavior."

Options:

  1. Yes, I can reproduce it
  2. No, let me try first
  3. Skip reproduction (proceed to tests)

Document Expected vs Actual

If user reproduces:

{
  "reproduction": {
    "steps": ["Step 1", "Step 2"],
    "currentBehavior": "What happens now",
    "expectedBehavior": "What should happen"
  }
}

Step 6: TDD RED Phase - Write Failing Tests

Create Test File

If test file doesn't exist, create it following project conventions:

# Determine test file location
# Based on source file: src/services/auth.ts -> tests/services/auth.test.ts
# Or co-located: src/services/auth.ts -> src/services/auth.test.ts

Generate Test Cases

Based on ticket acceptance criteria, generate failing tests:

Sample generated test code for bugs and features: see references/examples.md.

Run Tests - Verify RED

# Run the specific test target (varies by framework)
{TEST_COMMAND} {TEST_FILE}

Per-language run commands (Go, Rust, etc.) and examples: see references/test-frameworks.md.

Expected: Tests should FAIL (RED phase)

Handle Unexpected Results

ResultAction
Tests fail (expected)Proceed to GREEN phase
Tests passWarning: "Tests pass but shouldn't. Is the issue already fixed?"
Syntax errorsFix test syntax, retry
Import errorsFix imports, retry

If tests pass unexpectedly:

Question: "The tests pass, but we expected them to fail. What should we do?"

Options:

  1. Issue is already fixed - verify and close
  2. Tests are incorrect - adjust test assertions
  3. Different test needed - rewrite tests
  4. Proceed anyway

Max Attempts:

Track attempts (default: maxRedAttempts: 3). If max reached:

Question: "Failed to achieve RED phase after {N} attempts. How should we proceed?"

Options:

  1. Continue trying with guidance
  2. Skip to implementation
  3. Abort TDD workflow

Step 7: TDD GREEN Phase - Implement Code

Confirmation (If Configured)

If qa.tdd.confirmBeforeGreen: true:

Question: "RED phase complete. Tests are failing as expected. Proceed to GREEN phase?"

Options:

  1. Yes, implement the fix/feature
  2. Review tests first
  3. Add more tests before implementing

Implement Minimum Code

Write the minimum code necessary to make tests pass:

Guidelines:

  • Focus only on passing the tests
  • Don't add extra functionality
  • Don't optimize yet
  • Don't refactor yet

Run Tests - Verify GREEN

# Run tests again (use the same target as RED phase)
{TEST_COMMAND} {TEST_FILE}

Per-language run commands: see references/test-frameworks.md.

Expected: Tests should PASS (GREEN phase)

Handle Failures

If tests still fail:

  1. Analyze error messages
  2. Fix implementation
  3. Re-run tests
  4. Repeat until green

Track attempts. If struggling:

Question: "Tests are still failing. Need help troubleshooting?"

Options:

  1. Show me the errors - I'll help debug
  2. I'll fix it manually
  3. Skip to refactor phase anyway

Optional: Run Full Suite

If qa.tdd.runFullSuiteEachPhase: true:

# Run full test suite
{TEST_COMMAND}

Ensure no regressions were introduced.

Step 8: TDD REFACTOR Phase - Clean Up

Confirmation (If Configured)

If qa.tdd.confirmBeforeRefactor: true:

Question: "GREEN phase complete. All tests pass. Proceed to REFACTOR phase?"

Options:

  1. Yes, clean up the code
  2. Skip refactoring - code is good enough
  3. Add more tests first

Refactoring Guidelines

Review and improve the implementation:

Check for:

  • Code duplication
  • Long methods/functions
  • Poor naming
  • Missing error handling
  • Performance issues
  • Type safety

Do NOT:

  • Add new functionality
  • Change behavior
  • Break existing tests

Run Tests After Each Change

After each refactoring change:

{TEST_COMMAND} {TEST_FILE}

Per-language run commands: see references/test-frameworks.md.

Ensure tests remain GREEN throughout refactoring.

Step 9: Final Verification

Run Full Test Suite

# Run all tests
{FULL_TEST_COMMAND}

# Examples:
# npm test
# pnpm test
# pytest
# cargo test
# go test ./...

Run Linting

# Auto-detected or from config
{LINT_COMMAND}

# Examples:
# npm run lint
# pnpm lint
# ruff check .
# cargo clippy

Run Type Check (If Applicable)

# TypeScript
npx tsc --noEmit

# Python (mypy)
mypy .

Summary of Checks

CheckStatusNotes
New testsPASS{N} tests added
Full suitePASS{M} total tests
LintingPASSNo issues
Type checkPASSNo errors

Step 10: Update Context

Update .git-workflow/pr-context.json with TDD information:

mkdir -p .git-workflow

Always write the canonical path. Never modify the legacy context fallback.

{
  "ticket_id": "PROJ-1234",
  "ticket_url": "https://...",
  "ticket_title": "Title from ticket",
  "branch": "fix/proj-1234-description",
  "type": "fix",
  "description": "Description",
  "started_at": "2025-01-17T12:00:00Z",
  "tdd": {
    "test_files": ["tests/auth/login.test.ts"],
    "implementation_files": ["src/services/auth.ts"],
    "tests_added": 2,
    "tests_modified": 0,
    "phases_completed": ["red", "green", "refactor"],
    "completed_at": "2025-01-17T14:30:00Z"
  }
}

This enables /commit to generate better commit messages and /finish to include TDD summary in PR description.

Step 11: Summary

Output a completion summary:

Sample completion summary format: see references/examples.md.

Configuration Reference

Full settings table: see references/configuration.md.

Error Handling

Full error-scenario table: see references/error-handling.md.

Examples

Full worked examples (Bug Fix Flow, Feature Flow, No Ticket Flow): see references/examples.md.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.