fix(hooks): gate eprintln! behind RTK_HOOK_MODE to prevent hook disablement#2048
Open
rosschurchill wants to merge 1 commit into
Open
fix(hooks): gate eprintln! behind RTK_HOOK_MODE to prevent hook disablement#2048rosschurchill wants to merge 1 commit into
rosschurchill wants to merge 1 commit into
Conversation
Adds in_hook_mode() helper to core/utils.rs. Hook entry points (run_claude/run_cursor/run_gemini/run_copilot) set RTK_HOOK_MODE=1 before any other work; all diagnostic eprintln! sites in filter/trust/permissions paths are guarded so no stderr escapes to Claude Code during hook execution. Any stderr during PreToolUse triggers bug #4669 and permanently disables the hook for the session. This commit covers permissions.rs (1 site) and the in_hook_mode helper. The trust.rs and toml_filter.rs gates are in the C-01 commit (same files). hook_cmd.rs set_var + load_cached changes are in the C-08 commit. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
|
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.
Any stderr output during a PreToolUse hook permanently disables the hook for that Claude Code session. There are 16 ungated
eprintln!sites acrosshook_cmd.rs,toml_filter.rs,trust.rs, andpermissions.rsthat can trigger this.This adds an
in_hook_mode()helper (checksRTK_HOOK_MODEenv var) and sets the var at the top of each hook entry point (run_claude,run_cursor,run_gemini,run_copilot). All 16 diagnosticeprintln!calls are gated behindif !in_hook_mode()so they only fire during normal CLI use, never during hook execution.Free to use as-is — no changes needed on your end.