feat: add block-no-verify PreToolUse hook to prevent agents from bypassing git hooks#1089
feat: add block-no-verify PreToolUse hook to prevent agents from bypassing git hooks#1089
Conversation
Prevents agents from bypassing git hooks via the hook-skip flag.
📝 WalkthroughWalkthroughA Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
.claude/settings.json (1)
29-29: Prefer a locally pinned executable over runtimenpxfetches.Running
npx block-no-verify@1.1.2in a pre-exec hook introduces reliability and supply-chain drift at runtime (npm availability/cache/prompt behavior). To fix this, addblock-no-verifyas a repo dependency and invoke the local binary from lockfile-pinned artifacts.Suggested approach
- Add to package.json:
"block-no-verify": "1.1.2"- Run
npm installto update lockfile- Update command:
- "command": "npx block-no-verify@1.1.2" + "command": "./node_modules/.bin/block-no-verify"🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.claude/settings.json at line 29, Replace the runtime npx fetch with a repo-pinned binary: add "block-no-verify": "1.1.2" to package.json and run npm install to update the lockfile, then change the settings.json "command" value from "npx block-no-verify@1.1.2" to the local pinned binary invocation such as "node_modules/.bin/block-no-verify" (or the equivalent package manager-aware path) so the hook uses the lockfile-pinned artifact instead of fetching at runtime.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In @.claude/settings.json:
- Line 29: Replace the runtime npx fetch with a repo-pinned binary: add
"block-no-verify": "1.1.2" to package.json and run npm install to update the
lockfile, then change the settings.json "command" value from "npx
block-no-verify@1.1.2" to the local pinned binary invocation such as
"node_modules/.bin/block-no-verify" (or the equivalent package manager-aware
path) so the hook uses the lockfile-pinned artifact instead of fetching at
runtime.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3d7d18c6-d37d-41db-956a-f3689f1aaebb
📒 Files selected for processing (1)
.claude/settings.json
Summary
Adds
block-no-verify@1.1.2as aPreToolUseBash hook in.claude/settings.json, alongside the existingPostToolUsehooks.Details
When an agent runs
git commitorgit pushwith the hook-bypass flag, it silently disables pre-commit, commit-msg, and pre-push hooks.block-no-verifyreadstool_input.commandfrom the Claude Code hook stdin payload, detects the hook-bypass flag across all git subcommands, and exits 2 to block. The existingPostToolUsehooks are preserved unchanged.Closes #1088
Disclosure: I am the author and maintainer of
block-no-verify.Summary by CodeRabbit