Format Until Clean
FeaturedOn demandAbout Format Until Clean
This manually triggered loop repeats npm run format in Cursor until formatting stops modifying files. Each round runs the formatter, then checks with git diff that the working tree has no differences, for up to 5 rounds.
Key features
- 01Manual trigger, so the user decides when it starts
- 02Capped at 5 rounds to avoid endless repetition
- 03Checks both the command's exit status and an empty git diff
- 04Supports Cursor
Use cases
- 01Normalizing code style after a large refactor
- 02Confirming nothing is left to reformat before a commit or PR
- 03Settling stray formatting differences that keep reappearing
- Goal
- The formatter runs without errors and produces no remaining file differences.
- Exit when
- Stop when npm run format succeeds and git diff is empty, or after 5 rounds if that is not reached.
- Between iterations run
- npm run format
Launch prompt
Paste into Cursor. The agent repeats the steps below until the exit condition is met.
Start the "Format Until Clean" loop. Goal: The formatter runs without errors and produces no remaining file differences. Max iterations: 5. Step 1: Run the formatter — Execute npm run format so the formatter rewrites files that do not match the rules. If the command errors, note the message first. `npm run format` Step 2: Confirm it is clean — Run the formatter again and check the working tree with git diff --quiet. A successful command with no differences counts as clean; otherwise changes remain. `npm run format && git diff --quiet` Step 3: Decide whether to repeat — If the check failed and fewer than 5 rounds have run, start another round using the latest result. If the tree is clean or the limit is reached, end the loop. Between iterations run: `npm run format` Exit when: Stop when npm run format succeeds and git diff is empty, or after 5 rounds if that is not reached.
Steps
Each round runs in order; if the exit condition isn’t met, another round starts, up to 5.
Execute npm run format so the formatter rewrites files that do not match the rules. If the command errors, note the message first.
npm run formatRun the formatter again and check the working tree with git diff --quiet. A successful command with no differences counts as clean; otherwise changes remain.
npm run format && git diff --quietIf the check failed and fewer than 5 rounds have run, start another round using the latest result. If the tree is clean or the limit is reached, end the loop.
Supported agents
Coding agents that can run this loop directly.