Skip to content

fix(hooks): keep a GateGuard deny when another Bash hook adds context - #4013

Merged
haelyra merged 1 commit into
affaan-m:mainfrom
divya0795:fix/bash-dispatcher-keep-deny
Nov 19, 2026
Merged

haelyra merged 1 commit into
affaan-m:mainfrom
divya0795:fix/bash-dispatcher-keep-deny

Conversation

@divya0795

Copy link
Copy Markdown
Contributor

What Changed

scripts/hooks/bash-hook-dispatcher.js: runHooks() now stops at the first sub-hook whose stdout is a PreToolUse permissionDecision: "deny" and returns that output unchanged. A new isPermissionDeny() helper parses the stdout JSON to recognise the decision.

tests/hooks/bash-hook-dispatcher.test.js: a regression test runs the pre dispatcher in the strict profile on git push --force origin main with an isolated GATEGUARD_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 advisory additionalContext priority over the hook stdout:

output: additionalContext
  ? buildPreToolUseAdditionalContext(additionalContext)
  : rawModified ? currentRaw : '',

In the strict profile, pre:bash:git-push-reminder adds additionalContext to every git 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 fresh HOME:

printf '%s' '{"tool_name":"Bash","session_id":"s1","tool_input":{"command":"git push --force origin main"}}' \
  | ECC_HOOK_PROFILE=strict node scripts/hooks/bash-hook-dispatcher.js pre
# {"hookSpecificOutput":{"hookEventName":"PreToolUse","additionalContext":"[Hook] Review changes before push..."}}

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 plain git push. The standard profile is not affected, because the reminder only runs in strict.

The early return also keeps later hooks from receiving the deny JSON as their input event.

Testing Done

  • Automated tests pass locally (node tests/run-all.js)
  • Edge cases considered and tested
  • The new test fails on unfixed main (permissionDecision is undefined, and the output is only the reminder) and passes with the fix.
  • npm test on Node 22 (macOS arm64) with ECC_TEST_JOBS=4 and 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 unmodified main: the validators pass, and the same 4 test files fail with and without the change. They fail on this machine regardless (hooks/gateguard-fact-force exempt-globs case, lib/grok-canonical-install, scripts/codex-hooks pre-commit scanner cases, scripts/install-apply), so none come from this PR. eslint . reports 0 errors.
  • I compared old and new dispatcher output over 11 commands × 2 runs each, across the minimal, standard and strict profiles: ls, plain and force git push, rm -rf, npm run dev, git commit --no-verify and git reset --hard. The only differences are the two strict-profile git push cases, 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-verify still exits 2, and the second, allowed run of each command still shows the reminder.

Type of Change

  • fix: Bug fix

Security & Quality Checklist

  • No secrets or API keys committed
  • No sensitive data exposed in logs or output
  • Follows conventional commits format

🤖 Generated with Claude Code

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.
@haelyra

haelyra commented Nov 19, 2026

Copy link
Copy Markdown
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 fbb1a85c59a8468c96454fc5b48cf7e4f8f79b55 passed CI, CodeQL, and Supply-Chain Watch. Thank you for helping improve ECC!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants