Skip to content

fix(hooks): keep the hook protocol channel free of the setup nag - #3614

Open
rhishi99 wants to merge 1 commit into
rtk-ai:developfrom
rhishi99:fix/hook-protocol-stderr-silence
Open

rhishi99 wants to merge 1 commit into
rtk-ai:developfrom
rhishi99:fix/hook-protocol-stderr-silence

Conversation

@rhishi99

Copy link
Copy Markdown
Contributor

Problem

rtk hook and rtk rewrite are the hook. The agent that invokes them parses their stdout and stderr as a protocol channel, so an extra line there is corruption, not a diagnostic.

maybe_warn() was allowed to fire for both. On a machine that has Claude Code installed but not the rtk hook, that puts

[rtk] /!\ No hook installed - run `rtk init -g` for automatic token savings

into the protocol stream once a day. Gain was already excluded for exactly this reason; Hook and Rewrite were missed.

This is not theoretical

On such a machine, ten tests in tests/copilot_selfheal_test.rs fail today — every one on the same assertion:

stderr must stay silent (protocol safety) for payload {"tool_name":"Bash",...},
got: [rtk] /!\ No hook installed - run `rtk init -g` ...

CI never sees it because a fresh runner has no ~/.claude at all, so status() returns Ok and the warning never fires. The tests are correct; the nag was leaking into a channel it must never touch.

Fix

Add Commands::Hook and Commands::Rewrite to the same exclusion list Commands::Gain already sits in.

Testing

No new test — copilot_selfheal_test.rs already pins this contract with 12 assertions on stderr silence; they were simply unreachable in CI. Before/after on an affected machine:

before: test result: FAILED. 2 passed; 10 failed
after:  test result: ok.    12 passed;  0 failed

Full suite, cargo fmt --check, and cargo clippy --all-targets clean on x86_64-pc-windows-gnu.

🤖 Generated with Claude Code

`rtk hook` and `rtk rewrite` are the hook. The agent that invokes them
parses their stdout and stderr as a protocol channel, so any extra line
there is corruption, not a diagnostic.

`maybe_warn()` was allowed to fire for them, which meant a developer with
Claude Code installed but without the rtk hook got

    [rtk] /!\ No hook installed - run `rtk init -g` for automatic token savings

emitted mid-protocol once a day. Gain was already excluded for the same
reason; Hook and Rewrite were missed.

This is not theoretical: on such a machine ten tests in
`copilot_selfheal_test.rs` fail today, every one of them on the
`stderr must stay silent (protocol safety)` assertion. CI never sees it
because a fresh runner has no `~/.claude` at all, so `status()` reports
Ok and the warning never fires.

Co-Authored-By: Claude Opus 5 <[email protected]>
@CLAassistant

CLAassistant commented Aug 20, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@rtk-release-bot

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet.

@KuSh

KuSh commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

#4550 (merged 2026-10-13) made run_cli skip hook_check::maybe_warn for Commands::Hook, alongside Gain, Init and Verify, so the Hook half of this PR is on develop. What develop still lacks is the same exclusion for Commands::Rewrite: with a ~/.claude/settings.json and no hook installed, rtk rewrite git status still prints the missing-hook warning on stderr before the rewrite. Could you rebase onto current develop and narrow the PR to adding Commands::Rewrite to that matches! list? It conflicts because run_cli moved from src/main.rs to src/lib.rs, so the change now goes there. Thanks for the fix.

@rtk-release-bot rtk-release-bot Bot removed the stale label Nov 30, 2026
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.

3 participants