Skip to content

fix(init): replace stale legacy hook registrations - #2588

Closed
YOMXXX wants to merge 1 commit into
rtk-ai:developfrom
YOMXXX:fix/issue-1962-missing-rewrite-hook
Closed

YOMXXX wants to merge 1 commit into
rtk-ai:developfrom
YOMXXX:fix/issue-1962-missing-rewrite-hook

Conversation

@YOMXXX

@YOMXXX YOMXXX commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • treat legacy rtk-rewrite.sh settings entries as stale when installing the native rtk hook claude command
  • remove legacy settings entries even when the old hook script file is already missing
  • add regression coverage for missing legacy hook registrations and native idempotency detection

Fixes #1962

Verification

  • cargo +1.93.0 fmt --check
  • git diff --check
  • cargo +1.93.0 test legacy -- --nocapture
  • cargo +1.93.0 test hooks::init -- --nocapture
  • manual temp-HOME smoke for rtk init -g --auto-patch replacing a missing rtk-rewrite.sh registration
  • cargo +1.93.0 clippy --all-targets
  • cargo +1.93.0 test --all -- --skip small_grep_not_worse_than_plain

@mattbuot

Copy link
Copy Markdown

Flagging a behaviour change in this diff before it lands, from reproducing the #1962 state against current develop.

On develop today, rtk init -g with a legacy install splits into two outcomes, decided by the dominated_by_legacy predicate in remove_legacy_hook_entries_from_json (init.rs:1356):

  • rtk's legacy entry alone in the Bash matcher group → script deleted and entry removed; settings.json ends as "PreToolUse": [].
  • another hook sharing that group → script deleted, entry kept → the dangling reference reported in rtk-rewrite.sh: No such file or directory #1962. Verified: with a co-resident /opt/acme/audit-hook.sh, settings.json comes back byte-identical and the script is gone.

This diff hoists remove_legacy_settings_entries out of the deletion-success branch, so the entry is stripped unconditionally — including when fs::remove_file failed (the Err arm now only logs) and when no legacy script exists at all.

That does remove the dangling reference, but by removing the registration rather than repairing it, and the replacement write is not guaranteed: patch_settings_json_command under the default PatchMode::Ask calls prompt_user_consent, which returns Ok(false) on non-TTY stdin (init.rs:445) and yields PatchResult::Declined. The Declined arm at init.rs:1211 prints nothing, and the RTK hook registered (global). banner at init.rs:1179 has already printed at step 4, before settings.json is touched at step 5.

So for the shared-group case this trades a visible failure for a silent one — Claude Code raises a hook error on a dangling script, and raises nothing at all when there is no entry. I reproduced the non-interactive run in an isolated HOME and it exits 0 with the success banner in both shapes.

The ordering PR #3570 adopted for Cursor avoids this: patch the config first, delete the legacy artefacts only after that write succeeds. Applying the same order here would let this PR close #1962 without the trade.

Happy to send a rebased version on top of current develop with that ordering and regression coverage for both the declined-prompt path and the co-resident-hook case — this PR is mergeable_state: dirty and not rebaseable in place. Full credit to @YOMXXX for the original.

@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.

@rtk-release-bot

Copy link
Copy Markdown
Contributor

Closing this pull request after a prolonged period of inactivity. If this is still relevant, please ask for it to be reopened. Thank you!

@rtk-release-bot rtk-release-bot Bot closed this Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk-rewrite.sh: No such file or directory

2 participants