PromptTesting and qualityClaude Code, Codex, Cursor and other coding agents

Refactor-under-tests loop

Small refactors that keep behaviour identical, reverting any step that turns a test red.

How each pass goes
  1. Confirm the tests pass.
  2. Make one small refactor.
  3. Run tests; keep it if green, revert if red.
Stops when
The refactor is complete with the suite green throughout.
Starter prompt
Refactor this code in small, behaviour-preserving steps. Before each step, confirm tests pass; after each step, run them. Keep the step if green, revert it if red. Commit after each kept step.
Paste into Claude Code, Codex or Cursor. To keep it running unattended, wrap it in /goal or the Ralph loop.