loops!
BrowseSign in
Back to loops
Testing
event
CursorClaude Code

Pre-Commit Guard

Hook that runs tests before git commit commands to block commits when the suite is red.

13 copies · 1 installs · 74 views

by loops!

Use loop copies the kickoff. Share copies the loop link. Open in Cursor / Claude Code only pre-fill that prompt — they do not install hook files. Click Install files, extract the zip into your repo, then restart your agent. Full install guide

Sign in to save
Guardrails
Hardened
Anti-gaming rules
Rules the agent must follow so it cannot cheat the exit condition.
  • Do not modify the check command or exit criteria to force success
  • Do not skip, disable, or bypass checks to pass the exit condition
  • If stuck after several iterations, stop and report blockers instead of gaming metrics
  • Do not weaken, delete, or skip tests to make the suite pass
  • Do not replace real assertions with trivial always-pass tests
  • Prefer fixing production code over patching tests to go green
How to run this loop
Includes install files
Run “Pre-Commit Guard” in your agent
Deeplinks and “Open in Cursor” only paste the kickoff prompt. They do not install hook files — your agent cannot tell whether files are on disk until you add them yourself.

Two separate pieces

  • Kickoff prompt — tells the agent the goal, check command, exit condition, and how to self-pace between passes.
  • Install files — optional hooks under .cursor/ or .claude/ that fire on events (save, commit, etc.). You must download and extract these into your repo.
  1. 1

    Download and extract install files

    Click Install files on this loop, unzip, and merge into your project root so paths like .cursor/hooks.json exist on disk.

    Restart Cursor or reload the Claude Code session so hooks are picked up. Until then, nothing is “installed” — the browser cannot write into your repo.

  2. 2

    Copy or open the kickoff prompt

    Use Use loop to copy the kickoff, or Open in Cursor / Open in Claude Code to pre-fill the prompt in that app. Those links only carry text, not hook files.

  3. 3

    Let hooks trigger, or start manually

    After hooks are on disk, Pre-Commit Guard can run when the configured event fires. For the first pass, paste the kickoff so the agent knows the loop rules.

Full guide with Cursor /loop notes: How to install loops

event trigger
Testing
On file_edit
Detect commit intent
Run tests
Block or allow
Tests pass before each git commit
Rendering diagram…
Steps
What the agent does on each pass.

1. Detect commit intent

When a git commit command is about to run, pause and run the test suite first.

2. Run tests

Run the full test suite before allowing the commit to proceed.

npm test

3. Block or allow

If tests fail, fix failures and re-run. Only allow the commit when tests pass.

Kickoff prompt
Copy this into your coding agent to start the loop.
Install and run the "Pre-Commit Guard" loop.

Goal: block git commits when tests are failing.
Between iterations run: npm test
Exit when: tests exit 0 before each commit.

Step 1: Before any git commit, run tests. Fix failures before committing.

Related loops

Testing
manual
Hardened
32 copies
Add focused tests until coverage meets your threshold (e.g. 80%), without changing production behavior unnecessarily.

Start the "Coverage Until Threshold" loop. Goal: coverage meets the target threshold (default 80%) with all tests passing Max iterations: 12 Between iterations run: npm test -- --coverage Exit when: coverage threshold is met and tests exit 0 Step 1: Run coverage. Add focused tests for the biggest uncovered gaps, then repeat. Self-pace this loop. After each iteration, run the check command, read the output, and only continue if the exit condition is not met. Stop when the exit condition passes or max iterations is reached. Give a short status update each pass.

Claude CodeCursor
coverage
testing
quality
by loops!
View
Testing
manual
Hardened
28 copies
Run the production build, fix compile and bundling errors, and loop until the build succeeds.

Start the "Build Until Green" loop. Goal: production build succeeds Max iterations: 10 Between iterations run: npm run build Exit when: npm run build exits 0 Step 1: Run the build. If it fails, fix the first error, then repeat until green. Self-pace this loop. After each iteration, run the check command, read the output, and only continue if the exit condition is not met. Stop when the exit condition passes or max iterations is reached. Give a short status update each pass.

CursorClaude Code
build
compile
ci
by loops!
View
Testing
manual
Hardened
15 copies
Run end-to-end tests, fix UI and integration failures, and loop until the E2E suite passes.

Start the "E2E Until Green" loop. Goal: E2E suite passes Max iterations: 10 Between iterations run: npm run test:e2e Exit when: E2E command exits 0 Step 1: Run E2E tests. Fix the first failing spec, then repeat. Self-pace this loop. After each iteration, run the check command, read the output, and only continue if the exit condition is not met. Stop when the exit condition passes or max iterations is reached. Give a short status update each pass.

CursorClaude Code
e2e
playwright
testing
by loops!
View