Pre-Commit Guard
FeaturedEvent-drivenAbout 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
- 01Event trigger, so no manual start is needed
- 02Uses the npm test exit code as the gate
- 03Blocks commits while tests are failing
- 04Supports Cursor
Use cases
- 01Keeping failing tests out of the commit history
- 02Having the agent verify changes automatically before each commit
- 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 test02
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