Repository navigation
Guards: send PreToolUse block reason to stderr - #11
Merged
Merged
Conversation
The hook wrapper redirected cli.py guard's stderr to stdout with 2>&1, so Claude Code reported "No stderr output" instead of the block reason on exit 2. Drop the redirect and pin the stream in a hook test. Amp-Thread-ID: https://ampcode.com/threads/T-01a1dac2-199b-7414-af14-4603154d1976 Co-authored-by: Dennis Pettas <[email protected]>
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.
When a guard blocks a tool call,
hooks/weft-pretooluse.shrancli.py guard 2>&1, which moved guard_engine's block reason from stderr to stdout. Claude Code shows a PreToolUse hook's stderr on exit 2, so builders saw "No stderr output" instead of why the command was blocked (about 200 times a month in the Mac mini session digest).This drops the redirect.
cli.py guardwrites nothing to stdout, so nothing else changes.tests/test_hooks.py::TestPreToolUseHook::test_block_reason_goes_to_stderrruns the real hook on a guardedgit commitand checks for exit 2, the guard message on stderr, and an empty stdout. It fails without the fix (stderr is empty and the reason is on stdout). Full suite passes locally: 2992 passed.