mcpField

Pre-Commit Guard

FeaturedEvent-driven

About Pre-Commit Guard

This event-triggered loop runs npm test in Cursor before a commit. The commit may proceed only when the tests exit with code 0; otherwise it stays blocked.

Key features

  1. 01Event trigger, so no manual start is needed
  2. 02Uses the npm test exit code as the gate
  3. 03Blocks commits while tests are failing
  4. 04Supports Cursor

Use cases

  1. 01Keeping failing tests out of the commit history
  2. 02Having the agent verify changes automatically before each commit
  3. 03Holding the main branch to passing tests across many iterations
Goal
npm test exits with code 0 before every git commit.
Exit when
Allow the commit once npm test exits with code 0 before it.
Between iterations run
npm test

Launch prompt

Paste into Cursor. The agent repeats the steps below until the exit condition is met.

prompt.md
Start the "Pre-Commit Guard" loop.
Goal: npm test exits with code 0 before every git commit.
Step 1: Run the tests — Execute npm test before the commit and read its exit code and output. `npm test`
Step 2: Decide whether to allow — An exit code of 0 lets the commit proceed. Any other code keeps it blocked, so the failures are fixed and verified again.
Between iterations run: `npm test`
Exit when: Allow the commit once npm test exits with code 0 before it.

Steps

Each round runs in order; if the exit condition isn’t met, another round starts, up to 1.

01
Run the tests

Execute npm test before the commit and read its exit code and output.

$npm test
02
Decide whether to allow

An exit code of 0 lets the commit proceed. Any other code keeps it blocked, so the failures are fixed and verified again.

Not met → next roundExits when met

Supported agents

Coding agents that can run this loop directly.

Cursor
Claude Code

Comments

Markdown supported