Skip to content

fix(init): migrate Cursor hooks.json before deleting the legacy hook script - #3570

Open
guyoron1 wants to merge 1 commit into
rtk-ai:developfrom
guyoron1:fix/cursor-hook-migration
Open

fix(init): migrate Cursor hooks.json before deleting the legacy hook script#3570
guyoron1 wants to merge 1 commit into
rtk-ai:developfrom
guyoron1:fix/cursor-hook-migration

Conversation

@guyoron1

Copy link
Copy Markdown
Contributor

Summary

  • rtk init -g --agent cursor deleted ~/.cursor/hooks/rtk-rewrite.sh first and updated hooks.json in a separate, error-swallowed pass; cursor_hook_already_present then accepted the stale legacy entry as "RTK hook already present". Net result on any failure of the cleanup pass: a registered Cursor preToolUse hook whose script no longer exists, reported as success (rtk init --agent cursor deletes ~/.cursor/hooks/rtk-rewrite.sh, leaves hooks.json referencing it, and reports success #3465).
  • patch_cursor_hooks_json now strips legacy rtk-rewrite.sh entries and registers rtk hook cursor in the same atomic write, and the presence check only accepts the new binary command — a legacy entry can never satisfy it, since its script is about to be deleted.
  • The legacy script is deleted only after hooks.json was successfully patched, so a parse failure propagates and leaves the still-working script hook in place. The now-redundant remove_legacy_cursor_hooks_json_entries pass is removed.
  • The third problem in the issue (--agent cursor also running the Claude installer and touching ~/.claude/) is the scope of fix(init): keep cursor setup out of claude config #3290 / RTK init want to install in .claude when using another agent #3282 and is not changed here.

Test plan

  • cargo fmt --all --check
  • cargo clippy --all-targets (no warnings)
  • cargo test — 2661 passed, 8 ignored
  • New regression test test_patch_cursor_hooks_json_migrates_legacy_entry: a hooks.json referencing the legacy script is rewritten to a single rtk hook cursor entry in one operation. Updated test_cursor_hook_already_present_legacy_script* to assert a legacy entry does not count as present.

Fixes #3465

🤖 Generated with Claude Code

…script

'rtk init -g --agent cursor' deleted ~/.cursor/hooks/rtk-rewrite.sh and
then treated the stale hooks.json entry referencing it as 'RTK hook
already present', printing a success message while leaving Cursor with a
registered preToolUse hook whose script no longer exists (rtk-ai#3465).

- patch_cursor_hooks_json now strips legacy rtk-rewrite.sh entries and
  registers the 'rtk hook cursor' command in the same atomic write; a
  legacy entry no longer satisfies the presence check.
- The legacy script is deleted only after hooks.json was successfully
  patched, so a parse failure leaves the working script in place.
- The separate remove_legacy_cursor_hooks_json_entries pass (whose
  swallowed errors caused the dangling reference) is gone.
@guyoron1
guyoron1 force-pushed the fix/cursor-hook-migration branch from 1dd3789 to 03d03ab Compare August 15, 2026 07:22
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.

rtk init --agent cursor deletes ~/.cursor/hooks/rtk-rewrite.sh, leaves hooks.json referencing it, and reports success

1 participant