mcpField

Format Until Clean

FeaturedOn demand
TestingUp to 5 rounds

About 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

  1. 01Manual trigger, so the user decides when it starts
  2. 02Capped at 5 rounds to avoid endless repetition
  3. 03Checks both the command's exit status and an empty git diff
  4. 04Supports Cursor

Use cases

  1. 01Normalizing code style after a large refactor
  2. 02Confirming nothing is left to reformat before a commit or PR
  3. 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.

prompt.md
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.

01
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
02
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
03
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.

Not met → next roundExits when met

Supported agents

Coding agents that can run this loop directly.

Cursor

Comments

Markdown supported