feat: add block-no-verify PreToolUse hook to prevent agents from bypassing git hooks#98
feat: add block-no-verify PreToolUse hook to prevent agents from bypassing git hooks#98tupe12334 wants to merge 1 commit intoawslabs:mainfrom
Conversation
Prevents agents from bypassing git hooks via the hook-skip flag.
There was a problem hiding this comment.
Pull request overview
Adds a Claude Code PreToolUse hook to block git commands that attempt to bypass repository git hooks (e.g., --no-verify), strengthening enforcement of existing quality gates for agent-driven commits/pushes.
Changes:
- Add a
PreToolUsehook in.claude/settings.jsonfor theBashtool. - Run
npx block-no-verify@1.1.2as the hook command while preserving existing attribution settings.
| "hooks": [ | ||
| { | ||
| "type": "command", | ||
| "command": "npx block-no-verify@1.1.2" |
There was a problem hiding this comment.
This PreToolUse hook runs before every Bash tool invocation. Using npx without a non-interactive flag and without a timeout can cause the hook to hang (e.g., when npx needs to download/install the package and prompts for confirmation), effectively blocking all Bash commands. Consider running via npx --yes … / npm exec --yes … and setting an explicit timeout (and/or preinstalling the tool via the repo’s toolchain) so hook execution is bounded and reliable.
| "command": "npx block-no-verify@1.1.2" | |
| "command": "npx --yes block-no-verify@1.1.2", | |
| "timeoutMs": 10000 |
Summary
Adds
block-no-verify@1.1.2as aPreToolUseBash hook in.claude/settings.json, alongside the existing attribution config.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 existing attribution config is preserved unchanged.Closes #97
Disclosure: I am the author and maintainer of
block-no-verify.