Repository navigation
Description
Summary
guardrails hook scripts have no abort boundary. Every explicit exit in cli-flag-verify.sh and block-windows-drive-tmp.sh is 0 or 2, yet both were recorded exiting 1 with no stderr in a live session. For block-windows-drive-tmp.sh — a PreToolUse blocking guard — exit 1 is a non-blocking error: it enforced nothing, and nobody was told.
Evidence
Reported by claude-ops' unsurfaced-hook-failure detector at session stop:
2 hook failure record(s) in this session's transcript were never surfaced:
PostToolUse:Write [Verifying CLI flags...] (1x; completed non-zero exit; exit 1; last stderr: (none))
PreToolUse:Bash [Checking for Windows drive-root /tmp writes...] (1x; completed non-zero exit; exit 1; last stderr: (none))
Both hooks are plugins/guardrails/hooks/, registered in that plugin's hooks.json. Installed version 0.29.22.
Neither script can produce exit 1 from its own logic. Every explicit exit:
cli-flag-verify.sh: exit 0 (x7), and a final `exit 0` at line 418
block-windows-drive-tmp.sh: exit 0 (x5), exit 2 (x4), and a final `exit 0` at line 329
Both use set -uo pipefail — no set -e — so an internal command failure does not itself terminate the script.
Reproduction attempted, not achieved
I could not reproduce exit 1 on demand. Both hooks behaved correctly across the payloads I tried (own script file, a markdown file, a nonexistent path, an empty file_path, a malformed payload with no tool_input, and empty stdin; for the Bash guard also a benign command, a /tmp write, and a D:/tmp write):
cli-flag-verify.sh all payloads -> rc=0, no stderr
block-windows-drive-tmp.sh benign -> rc=0
/tmp write -> rc=2 with the correct 385-byte diagnostic
D:/tmp write -> rc=2 with the correct 385-byte diagnostic
malformed -> rc=0
So the trigger is intermittent and most likely environmental. This host shows severe process-creation cost (0.3–0.9 s per spawn; see #3508), and a spawn-time failure is a plausible source of a generic exit 1 with no script output. That does not make the report less actionable — see below.
Why this is a defect regardless of the trigger
The root cause of the exit code may be environmental, but the silence is a design gap in the hooks. A blocking guard has three possible outcomes and currently conflates two of them:
| outcome | intended signal | what actually happened |
|---|---|---|
| allow | exit 0 | exit 0 |
| block | exit 2 + stderr | exit 2 + stderr |
| could not run | (nothing defined) | exit 1, no stderr, enforcement silently skipped |
There is no trap on ERR or EXIT, so any abort between source hook-utils.sh (line 32/36) and the final exit 0 exits with whatever status the shell last had and writes nothing. From the harness's point of view that is indistinguishable from an environmental kill, and PreToolUse treats it as non-blocking and proceeds.
This is the same failure class ADR 0004 documents for killed hooks, and the same one disk-hygiene's destructive_guard.py closes explicitly with a fail-closed boundary that converts any unexpected exception into a deliberate exit 2 plus a diagnostic. The guardrails hooks have no equivalent.
Suggested fix
For every guardrails hook, and especially the PreToolUse blocking ones:
- Add an
EXITtrap that fires when the script exits with a status it did not choose, and have it emit a one-line diagnostic to stderr naming the hook and the status. A guard that could not run should say so. - Decide the policy for that case deliberately per hook — fail-open with a visible diagnostic, or fail-closed — rather than inheriting "exit 1, silent, proceed" by accident. Note that exit 1 is the one status that guarantees the operator learns nothing.
- Consider whether
source hook-utils.shfailing should be fatal-and-loud rather than falling through into undefinedhook::calls.
A shared helper in hook-utils.sh would cover the whole hook set at once, which matters given 17 PreToolUse and 22 PostToolUse registrations.
Verification expected of a fix
- A test that forces an abort mid-hook (for example by making a sourced helper fail) and asserts the hook exits with its declared policy status and writes a diagnostic naming itself.
- Confirmation that
claude-ops' unsurfaced-failure detector reports zero records for these hooks over a session that includes the forced-abort case.
Related
- perf(hooks): Windows process-creation tax makes the hook set unusable - 1,778 timeouts / 20.6 hours blocked over 9 days #3508 — the process-creation tax that makes an environmental spawn failure plausible on this host.
- perf(claude-ops): Stop-event unsurfaced-failure detector times out 113x, ~44x the per-turn hook budget #3512, perf(guardrails): block-windows-drive-tmp.sh averages 73.4s and timed out 49x - reduce process spawns #3517 — performance issues on these same two hooks. This one is correctness, not latency, and is independent of them.
- fix(guardrails): block-hook-bypass.sh fails CLOSED on a Windows stdin read stall, blocking valid tool calls with 'hook stdin is not valid JSON' #3507 —
block-hook-bypass.shfailing closed on a stdin stall: the opposite failure mode (loud false block) in the same hook set, and further evidence that abort handling is unowned across guardrails. docs/adr/0004-rightsize-instruction-surfaces-by-incumbent-first-arbitration.md— a killed PreToolUse hook yields nopermissionDecision, so the tool call proceeds unguarded.
Activity
kyle-sexton commentedon Sep 6, 2026
This was generated by AI during triage.
Cross-reference: #3713 is the same defect class on four other hooks. Both stay open.
#3713 came into a duplicate-triage pass as a candidate duplicate of this issue. It is not one, and this issue is staying open unchanged. Recording why, since the surface similarity is high enough that someone will pair them again.
Same mechanism, which this issue diagnoses better. #3713 reports four
hook_non_blocking_errorrecords, allexitCode: 1with empty stdout and stderr, from the same cause this issue names:set -uo pipefailwithoutset -e, no terminalexit 0, noEXITtrap, so the last command's status leaks out silently. The three-outcome table here (allow / block / could-not-run) and the ADR 0004 grounding are the canonical statement of the class; #3713 has neither and does not need to restate them.Different hooks, mostly in other plugins. This issue is scoped to guardrails and names
cli-flag-verify.shandblock-windows-drive-tmp.sh. #3713 names four different hooks:claude-opshooks/hook-failure-audit.shanddisk-hygieneskills/clean/scripts/guard_launch_monitor.py(both on Stop, both observed 2026-09-04 while the host had roughly 190 livebash.exeprocesses), theguardrailssecrets check on PreToolUse:Edit, and theinstruction-placementrules-index hook on PostToolUse:Write. Only the third falls inside this issue's stated scope. A shared helper in guardrails'hook-utils.sh, as suggested here, would not reach the other three plugins, and the disk-hygiene one is Python (raise SystemExit(main())), so it needs the equivalent boundary in a different language.Different severity, so worth keeping separately prioritized. This issue is a blocking guard that enforces nothing while staying silent, hence
priority: highandarea: security. #3713's hooks are advisory, where the loss is diagnosability rather than enforcement. One detail there is still worth knowing here: the failinghook-failure-audit.shis the fleet's decoupled detector for exactly this class, so when it dies this way, other instances of the class stop being reported at all.One correlating data point for the "trigger is environmental" reasoning in the reproduction section above: #3713's two Stop failures occurred under heavy process load, while its PreToolUse and PostToolUse failures occurred hours earlier under normal load. Load raises the frequency, but is not the root cause — which is the same conclusion reached here from the other direction.
No action taken on either issue beyond this cross-reference.
Generated by Claude Code
kyle-sexton commentedon Sep 6, 2026
This was generated by AI during triage.
Claiming for triage-only evaluation (no execution).
Generated by Claude Code
kyle-sexton commentedon Sep 6, 2026
This was generated by AI during triage.
Triage: verified, routed agent-ready (decision-defaulted)
The report holds. Two things change its shape: the gap is wider than the two hooks named, and the fix already exists in this directory as a working reference implementation.
Verification
The two named hooks cannot produce exit 1 from their own logic. Confirmed.
cli-flag-verify.shcontains onlyexit 0;block-windows-drive-tmp.shonlyexit 0andexit 2. Theexit 1andexit 2strings that a naive grep finds incli-flag-verify.share both inside comment text, not code. No production hook in the set exits 1 exceptresolve-convention-pattern.sh, which is a helper invoked by other hooks rather than a registered hook, and which documents that status as deliberate fail-closed.The gap is fleet-wide, not limited to the two named hooks. Every production hook in the guardrails set declares
set -uo pipefailand installs zero traps, with exactly one exception:setblock-hook-bypass.shset -uoblock-convention-violation.shset -uoblock-dangerous-git.shset -uoblock-no-verify.shset -uoblock-noncanonical-commit.shset -uoblock-windows-drive-tmp.shset -uocli-flag-verify.shset -uoflag-commit-pr-skill-bypass.shset -uohardcoded-path-check.shset -uosecret-pattern-detection.shset -uoskill-reference-verify.shset -uostale-path-verify.shset -uoworkflow-resilience-check.shset -uorun-guards.shset -uoSo the three-outcome table in the report applies to twelve blocking and advisory hooks, not two. Several of the untrapped ones are blocking guards on security-relevant surfaces.
hook-utils.shexposes roughly fortyhook::helpers and none of them is an abort or exit boundary, which is why no hook inherits one.The fix already exists here
block-hook-bypass.shcarries a complete implementation of what the report asks for, added under the crash-posture work referenced in its own comments:EXITtrap that reads$?, passes the two chosen statuses (0 and 2) straight through, and treats anything else as "the guard did not run";trap - EXITbefore re-exiting, so the handler cannot re-enter;hook::emit_channels, so the operator sees it even where stderr is not surfaced;That is the shared helper the report proposes, already written and already in production for one hook. The work is to lift it into
hook-utils.shand adopt it across the rest, not to design it.The same file also shows the related posture the report's third suggestion asks about: it treats a malformed enable-flag as enabled-and-loud rather than silently off.
Agent Brief
Type: Bug
Summary: Give every guardrails hook an abort boundary, so a hook that exits with a status it did not choose says so instead of failing silently.
Current behavior:
A guardrails hook that aborts between sourcing its shared utilities and reaching its final chosen exit terminates with whatever status the shell last carried, and writes nothing. For a PreToolUse blocking guard the harness reads that as non-blocking and lets the tool call proceed unguarded. The operator learns nothing, because the status is not one the hook defines and no diagnostic is produced. One hook in the set already handles this; the rest do not.
Desired behavior:
Every registered guardrails hook distinguishes three outcomes rather than two: allow, block, and could-not-run. The could-not-run outcome always emits a one-line diagnostic naming the hook and the unexpected status, on stderr and through the shared notice channel, and then exits with the posture that hook has declared. A hook's chosen statuses pass through the boundary untouched, and the boundary cannot recurse if the handler itself fails.
Key interfaces:
Acceptance criteria:
Out of scope:
set -e. The boundary is a trap, and turning on errexit across the hook set would change behavior far beyond the abort case.Decision defaulted: could-not-run posture is fail-open with a loud dual-channel diagnostic — veto before merge
The report's second suggestion asks for a deliberate per-hook policy rather than an inherited accident. Defaulting it rather than gating on it, because the repository has already made this call once on its most safety-critical surface: the bypass-blocking guard chose fail-open with a visible notice, and documented why, that a guard sitting on the hottest path must not be able to freeze a session through its own defect.
The default preserves every hook's current effective enforcement and adds only the diagnostic, so it is strictly additive and reversible. It converts the report's actual complaint, silence, into a signal without changing what any guard permits.
The alternative, converting blocking guards to fail-closed on abort, is a real change in enforcement and in failure mode. It is the reversible-alternative half of this default: a maintainer who wants it should say so before merge, per-hook, and the abort boundary is where it would be configured. Flipping it later is a one-line change per hook once the boundary exists.
Labels: keeping
priority: high,area: security,work-class: scoped; addingagent-ready,status: ready.Note on scope overlap: the parallel duplicate-closing pass touching #3713 concerns a related-but-distinct issue. This brief stays on the abort boundary and does not depend on that outcome.
Triage claim released.
Generated by Claude Code
fix(guardrails): name the event by lookup, refuse competing EXIT trap…
fix(guardrails): give every hook an abort boundary so a guard that co…
fix(guardrails): name the event by lookup, refuse competing EXIT trap…