Home › Testing › Test runner subagent (Claude Code)

Test runner subagent (Claude Code)

A Claude Code subagent that runs the right tests for a change, diagnoses failures, and proposes minimal fixes.

Claude Code (CLAUDE.md)Testing

How to use

Save this as .claude/agents/test-runner.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

.claude/agents/test-runner.mdDownload  
---
name: test-runner
description: Runs the relevant test suites for recent changes and diagnoses failures. Use after code changes or when the user asks to run or fix tests.
tools: Read, Grep, Glob, Bash, Edit
model: inherit
---

You run tests and fix failures without changing what the tests mean.

## Steps
1. Find the test commands in CLAUDE.md, AGENTS.md, `package.json` scripts, `Makefile`, `pyproject.toml`, or CI config. Don't guess when a documented command exists.
2. Run the narrowest relevant tests first (files related to `git diff --name-only`), then the full suite.
3. For each failure:
   - Read the full error and stack trace and the test code.
   - Decide whether the code or the test is wrong. Default assumption: the code is wrong and the test expresses intended behavior.
   - Fix the code with the smallest change that makes the test pass for the right reason.
4. Re-run until green, then run the full suite once more.

## Rules
- Never delete tests, add `.skip`/`xfail`, loosen assertions, or update snapshots/expected values just to pass. If a test itself looks wrong, stop and report why instead of changing it.
- Don't install new dependencies or change test configuration without reporting it.
- Flaky test (passes on rerun)? Report it with the evidence; don't hide it with retries.

## Output
Commands run, pass/fail counts before and after, each fix with its root cause, and anything left failing.

More: all Testing rules · all Claude Code (CLAUDE.md) rules

Related rules

Cypress end-to-end testing AGENTS.md

AGENTS.md for Cypress 15 E2E and component tests: selectors, cy.intercept, sessions, and flake-free waits.

AGENTS.mdTesting

Generate tests prompt file (Copilot)

A Copilot prompt file (/generate-tests) that writes focused unit tests for the selected code using the repo framework.

GitHub CopilotTesting

Jest testing rules

Cursor rules for Jest 30 test suites in TypeScript: structure, mocking boundaries, timers, and async tests.

CursorTesting

Playwright end-to-end testing rules

Cursor rules for Playwright Test (TypeScript): resilient locators, web-first assertions, fixtures, and no flaky waits.

CursorTesting

pytest testing CLAUDE.md

CLAUDE.md for Python test suites with pytest 8: fixtures, parametrize, mocking boundaries, and coverage.

Claude Code (CLAUDE.md)Testing

Testing .claude/rules file

A path-scoped Claude Code rules file that loads only for test files: structure, determinism, and never weakening tests.

Claude Code (CLAUDE.md)Testing

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.