Cursor "Iterate Until Tests Pass, Never Touch the Tests"

First-party Cursor guidance for the iterate-until-green loop, with the key anti-reward-hacking clause: the agent may never modify the tests it is trying to satisfy. Works in Cursor, Claude Code /goal, and Codex.

prompt
→ Claude
"Write code that makes these tests pass. Do NOT modify the tests. Keep iterating — run the suite, fix failures, run again — until all tests pass." (paraphrase of Cursor's official agent best-practices guidance)
claude-code

Implementation note

When to use: any test-driven agent session where the tests define done — you have a failing suite (TDD-style or a regression pile) and want the agent iterating until green without the classic cheat. How it works: the instruction is a plain contract: write code that makes these tests pass, do NOT modify the tests, and keep iterating — run the suite, fix failures, run again — until all tests pass. This is first-party Cursor guidance from their agent best-practices, and the pattern translates directly to Claude Code /goal and to Codex. Safety: the never-touch-the-tests clause is the entire anti-reward-hacking rail — without it, the cheapest path to green is editing an assertion, and agents find cheap paths. State it explicitly every time. The residual check is yours: confirm at the end that the test files are untouched (a quick git diff on the test paths) and that the implementing code is honest.

Source: Cursor blog

More testing loops

Watch tests while you work

/loopnew

A passive watchdog loop that reruns your test suite every 15 minutes and surfaces failing tests with their error output.

prompt
→ Claude
/loop 15m run the test suite, and if anything fails, show me the failing tests and the error output
testinglow risk

Kill flaky tests

/loopnew

Run your test suite repeatedly, collect every intermittent failure, and fix or quarantine flaky tests until you get five consecutive green runs.

prompt
→ Claude
/loop run my test suite 20 times, collect every intermittent failure, fix or quarantine the flaky ones, and don't stop until you get 5 consecutive fully-green runs
testinghigh risk

Make all tests pass

/goalnew

Implement remaining code and run tests repeatedly until the full suite passes.

prompt
→ Claude
/goal finish the implementation and make all tests pass
testingmedium risk