chore(hooks): replace test pre-commit with Claude PII guard#1329
Merged
Conversation
- Drop the `pnpm test` invocation from `.husky/pre-commit` (and the matching `test-pre-commit` script and `.env.precommit`); local commits no longer block on the full test suite. - Add `.husky/commit-msg` plus `scripts/check-commit-pii.js`, which asks Claude Sonnet to scan the commit message and staged diff for customer identifying references and refuses the commit when it finds one. Honors `DISABLE_PRECOMMIT_PII_CHECK=1` as an emergency bypass and falls open with a warning if the `claude` CLI is not on PATH. - Add a strict Customer Confidentiality section to CLAUDE.md (plus reinforcing bullets in Git Commit Guidelines and ABSOLUTE RULES) so the rule survives even when a prompt names a customer directly.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Non-OK Claude responses allow commit
- The PII guard now blocks successful Claude runs unless the first non-empty response line is exactly OK.
Or push these changes by commenting:
@cursor push 9f742df172
Preview (9f742df172)
diff --git a/scripts/check-commit-pii.js b/scripts/check-commit-pii.js
--- a/scripts/check-commit-pii.js
+++ b/scripts/check-commit-pii.js
@@ -168,6 +168,18 @@
console.error('')
return 1
}
+ if (firstLine !== 'OK') {
+ console.error('')
+ console.error('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━')
+ console.error('[pii-check] Commit blocked: invalid Claude response.')
+ console.error('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━')
+ console.error(result.output || '(empty response)')
+ console.error('')
+ console.error('Expected Claude to return exactly: OK')
+ console.error('or: BLOCK: <one short sentence describing what was found>')
+ console.error('')
+ return 1
+ }
console.log('[pii-check] No customer references detected.')
return 0
}You can send follow-ups to the cloud agent here.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 9515537. Configure here.
Previously the script only blocked when the first non-empty response line started with `BLOCK:`; any other text (a Claude refusal, an explanatory paragraph, a hallucinated answer, or empty output) fell through to the success branch and let the commit pass. Now the script also requires the first non-empty line to start with `OK` and rejects anything else, so the guard fails closed instead of fails open on malformed model output. Caught by Cursor Bugbot review on #1329.
`n/no-process-exit` is enforced by the repo's ESLint config; the script was failing the CI lint job with: error Don't use process.exit(); throw an error instead Switch to `process.exitCode = main()` so the script lets the event loop drain naturally instead of force-exiting. Behavior is identical here because `main()` is fully synchronous (spawnSync) so there are no pending handles.
Benjamin Barslev Nielsen (barslev)
approved these changes
May 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
pnpm testinvocation from.husky/pre-commit(and the matchingtest-pre-commitscript and.env.precommit); local commits no longer block on the full test suite.commit-msghook (.husky/commit-msg→scripts/check-commit-pii.js) that asks Claude Sonnet to scan the commit message and staged diff for customer-identifying references and refuses the commit when it finds one.CLAUDE.md, plus reinforcing bullets inGit Commit GuidelinesandABSOLUTE RULES, so the rule overrides anything a future prompt asks for.Why
commit-msgand notpre-commit?It is the only hook stage where both the commit message and the staged diff are accessible together. Functionally it still runs before the commit is finalized.
How the guard works
scripts/check-commit-pii.jscalls:--tools ""disables every tool, so the model can only emit text — no permission prompts, safe to run unattended from git.--max-budget-usd 0.10caps spend per call.OKlets the commit through,BLOCK: …rejects it.Escape hatches
DISABLE_PRECOMMIT_PII_CHECK=1 git commit …— bypass once. Use only for genuine false positives.claudeis not onPATH, the script falls open with a warning rather than blocking commits for developers without Claude Code installed.Test plan
BLOCK: …reason.[pii-check] No customer references detected.(visible in the commit output).pnpm installin a fresh clone wires up.husky/_/commit-msgcorrectly via thepreparescript.CLAUDE.mdCustomer Confidentiality wording covers the cases you have in mind.Notes for reviewers
claudesession uses (OAuth via keychain orANTHROPIC_API_KEY).--barewas deliberately removed because it ignores keychain OAuth.Note
Medium Risk
Medium risk because it changes local commit workflow and introduces a new git hook that sends commit messages and staged diffs to the external
claudeCLI for classification; misconfiguration or false positives can block commits or leak sensitive diff content.Overview
This PR removes running the full test suite during local
pre-commit(dropping.env.precommitand thetest-pre-commitscript) so commits only runlint-stagedby default.It adds a new
commit-msgHusky hook that runsscripts/check-commit-pii.js, which calls theclaudeCLI (Sonnet) to scan the commit message and staged diff for customer-identifying references and blocks the commit on aBLOCKverdict (with opt-out viaDISABLE_PRECOMMIT_PII_CHECK).CLAUDE.mdis updated to explicitly forbid customer-identifying info in repo artifacts and to document the new PII guard as an enforced commit guideline.Reviewed by Cursor Bugbot for commit 9515537. Configure here.