Repository navigation
fix(hooks): keep a GateGuard deny when another Bash hook adds context - #4013
Merged
Merged
Conversation
GateGuard denies by printing a PreToolUse permissionDecision on stdout at exit 0. runHooks only stopped early on a non-zero exit, and its final return preferred any advisory additionalContext over the hook stdout, so in the strict profile the git-push reminder replaced GateGuard's deny and the command ran. Stop at the first deny and return it unchanged.
Collaborator
|
Thank you for preserving a GateGuard denial when another hook adds context. We merged your original commit history through #4048 so the related changes could be tested together. The resulting main commit |
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.
What Changed
scripts/hooks/bash-hook-dispatcher.js:runHooks()now stops at the first sub-hook whose stdout is a PreToolUsepermissionDecision: "deny"and returns that output unchanged. A newisPermissionDeny()helper parses the stdout JSON to recognise the decision.tests/hooks/bash-hook-dispatcher.test.js: a regression test runs the pre dispatcher in thestrictprofile ongit push --force origin mainwith an isolatedGATEGUARD_STATE_DIR, and asserts that the output is GateGuard's deny.Why This Change
GateGuard denies by writing a
hookSpecificOutput.permissionDecision: "deny"JSON to stdout with exit code 0.runHooks()only returned early on a non-zero exit. Its final return then gave any advisoryadditionalContextpriority over the hook stdout:In the
strictprofile,pre:bash:git-push-reminderaddsadditionalContextto everygit push. GateGuard runs later in the list, so its denial was overwritten by the reminder, and Claude Code received only the reminder with exit 0. The push ran.Reproduction on
main(3f14a10), with a freshHOME:Calling GateGuard's
run()directly on the same input returns the deny (Destructive command detected...). Because GateGuard records the command as checked when it denies, a retry is then allowed, so the gate never actually stops that force-push. The same thing happens to GateGuard's first-Bash-command gate when a strict session's first command is a plaingit push. Thestandardprofile is not affected, because the reminder only runs instrict.The early return also keeps later hooks from receiving the deny JSON as their input event.
Testing Done
node tests/run-all.js)main(permissionDecisionisundefined, and the output is only the reminder) and passes with the fix.npm teston Node 22 (macOS arm64) withECC_TEST_JOBS=4and CI's serial list, run with this change applied (together with one unrelated fix in another file, sent as a separate PR). I then reran the failing files on unmodifiedmain: the validators pass, and the same 4 test files fail with and without the change. They fail on this machine regardless (hooks/gateguard-fact-forceexempt-globs case,lib/grok-canonical-install,scripts/codex-hookspre-commit scanner cases,scripts/install-apply), so none come from this PR.eslint .reports 0 errors.ls, plain and forcegit push,rm -rf,npm run dev,git commit --no-verifyandgit reset --hard. The only differences are the two strict-profilegit pushcases, which now return GateGuard's deny where they used to return the reminder. Pass-through commands still emit no stdout (PreToolUse:Bash dispatcher echoes input event to stdout → "Hook JSON output validation failed — (root): Invalid input" #2239),--no-verifystill exits 2, and the second, allowed run of each command still shows the reminder.Type of Change
fix:Bug fixSecurity & Quality Checklist
🤖 Generated with Claude Code