Skip to content

fix(hooks): gate eprintln! behind RTK_HOOK_MODE to prevent hook disablement#2048

Open
rosschurchill wants to merge 1 commit into
rtk-ai:developfrom
rosschurchill:fix/c07-hook-stderr-gate
Open

fix(hooks): gate eprintln! behind RTK_HOOK_MODE to prevent hook disablement#2048
rosschurchill wants to merge 1 commit into
rtk-ai:developfrom
rosschurchill:fix/c07-hook-stderr-gate

Conversation

@rosschurchill
Copy link
Copy Markdown

Any stderr output during a PreToolUse hook permanently disables the hook for that Claude Code session. There are 16 ungated eprintln! sites across hook_cmd.rs, toml_filter.rs, trust.rs, and permissions.rs that can trigger this.

This adds an in_hook_mode() helper (checks RTK_HOOK_MODE env var) and sets the var at the top of each hook entry point (run_claude, run_cursor, run_gemini, run_copilot). All 16 diagnostic eprintln! calls are gated behind if !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.

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>
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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