Let Claude Code Run the Tests and Close the Loop
What it is
A Claude Code practice where you let the agent run the project's tests, type checker, or build itself after making a change, and require it to iterate until they pass before reporting the work done.
Why it works
An agent that can't run anything is writing code blind — it hands you plausible changes you then have to verify by hand. Giving Claude Code the actual feedback signal turns it into a closed loop: it sees the real failure, fixes the real cause, and reruns until green. The verification happens where the information is freshest, and you review a change that already builds.
When to use it
Any project with a fast, reliable test or type-check command. The tighter and faster the feedback, the more the loop is worth — unit tests and type checks are ideal.
When not to use it
When the check is slow, flaky, or has real side effects (hitting production, sending emails, spending money). Don't hand the loop a command that's dangerous to run repeatedly, and never let a flaky suite train the agent to 'fix' tests by loosening them.
Prompt
Make <change>. After editing, run <the test/typecheck command> yourself and read the output. If anything fails, fix the root cause and run it again. Keep iterating until it passes cleanly. Don't tell me it's done until the command is green — and show me the final passing output.Example
You ask Claude Code to add a validation rule. It edits the code, runs npm test, sees two failures, realises one is a legitimately outdated expectation and the other a real bug in its change, fixes both, reruns, and reports back with a green suite — no round-trip through you.
Advanced version
Give the agent a single command that runs typecheck, lint, and tests together as its definition of done, and tell it that command is the gate. A one-shot 'green means done' check removes ambiguity about when the task is finished and keeps the loop honest.
Common mistakes
- Letting the agent 'fix' a failing test by deleting it or weakening the assertion instead of fixing the code — forbid that explicitly.
- Pointing the loop at a flaky suite, which teaches the agent that red is normal and to be worked around.
- Accepting 'the tests should pass now' without the actual green output — require proof, not a prediction.