Skip to content

fix(hooks): migrate the legacy script in the dir hook_check reads - #4774

Open
danieldutu wants to merge 1 commit into
rtk-ai:developfrom
danieldutu:fix/hooks-config-dir-migration
Open

danieldutu wants to merge 1 commit into
rtk-ai:developfrom
danieldutu:fix/hooks-config-dir-migration

Conversation

@danieldutu

Copy link
Copy Markdown

Summary

With CLAUDE_CONFIG_DIR set, rtk gain kept printing Hook outdated — run rtk init -g to update after the user ran exactly that command. I reproduced it on develop 32b2ec4: with the binary hook registered and $CLAUDE_CONFIG_DIR/hooks/rtk-rewrite.sh present, rtk init -g --auto-patch left the script on disk and the warning up.

The cause is a directory mismatch. hook_status() in src/hooks/init/claude.rs reports Outdated for a leftover script in resolve_claude_dir(), which honours $CLAUDE_CONFIG_DIR, while migrate_old_hook_script() in the same file looked only under user_dirs::home().join(".claude") and never saw the file.

I pointed migrate_old_hook_script() at resolve_claude_dir() so both paths agree, and moved the Cursor cleanup to its own home lookup so it still runs when no Claude directory resolves. The settings-entry cleanup already resolved through resolve_claude_dir(), so it needed no change.

Test plan

Before (develop 32b2ec4, fresh HOME, CLAUDE_CONFIG_DIR=/x, LC_ALL=C):

$ rtk init -g --auto-patch
$ rtk gain 2>&1 | grep -i hook
[warn] Hook outdated — run `rtk init -g` to update
$ test -f /x/hooks/rtk-rewrite.sh && echo present
present

After (this patch, same setup):
$ rtk init -g --auto-patch
$ rtk gain 2>&1 | grep -i hook
(no output)
$ test -f /x/hooks/rtk-rewrite.sh && echo present
(no output)

The new tests cover both directories: a leftover script under $CLAUDE_CONFIG_DIR is removed with its settings entry while the rtk hook claude entry survives, and the ~/.claude default path still migrates. Boundaries: the hash-file cleanup follows the resolved directory too, which is a behaviour change only for a hash file left in ~/.claude while CLAUDE_CONFIG_DIR points elsewhere — that file was already invisible to hook_status(), so the warning it produced is gone. Cursor's directory resolution is untouched; macOS is the only platform I ran the repro on.

Fixes #4757

With CLAUDE_CONFIG_DIR set, `rtk gain` kept printing
`Hook outdated — run `rtk init -g` to update` after the user ran exactly
that command. I reproduced it on develop: with the binary hook registered
and `$CLAUDE_CONFIG_DIR/hooks/rtk-rewrite.sh` present, `rtk init -g
--auto-patch` left the script on disk and the warning up.

The cause is a directory mismatch. `hook_status()` in
src/hooks/init/claude.rs reports Outdated for a leftover script in
`resolve_claude_dir()`, which honours `$CLAUDE_CONFIG_DIR`, while
`migrate_old_hook_script()` in the same file looked only under
`user_dirs::home().join(".claude")` and never saw the file.

I pointed `migrate_old_hook_script()` at `resolve_claude_dir()` so both
paths agree, and moved the Cursor cleanup to its own `home` lookup so it
still runs when no Claude directory resolves. The settings-entry cleanup
already resolved through `resolve_claude_dir()`, so it needed no change.

Before (develop 32b2ec4, fresh HOME, CLAUDE_CONFIG_DIR=/x, LC_ALL=C):
    $ rtk init -g --auto-patch
    $ rtk gain 2>&1 | grep -i hook
    [warn] Hook outdated — run `rtk init -g` to update
    $ test -f /x/hooks/rtk-rewrite.sh && echo present
    present
After (this patch, same setup):
    $ rtk init -g --auto-patch
    $ rtk gain 2>&1 | grep -i hook
    (no output)
    $ test -f /x/hooks/rtk-rewrite.sh && echo present
    (no output)

The new tests cover both directories: a leftover script under
$CLAUDE_CONFIG_DIR is removed with its settings entry while the
`rtk hook claude` entry survives, and the `~/.claude` default path still
migrates. Boundaries: the hash-file cleanup follows the resolved
directory too, which is a behaviour change only for a hash file left in
~/.claude while CLAUDE_CONFIG_DIR points elsewhere — that file was
already invisible to hook_status(), so the warning it produced is gone.
Cursor's directory resolution is untouched; macOS is the only platform I
ran the repro on.

Fixes rtk-ai#4757

Signed-off-by: danieldutu <[email protected]>
@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added bug Something isn't working hooks labels Oct 24, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes a bug where migrate_old_hook_script() looked for the legacy rtk-rewrite.sh hook script under the fixed ~/.claude path, while hook_status() checked resolve_claude_dir() (which honors CLAUDE_CONFIG_DIR), causing the 'Hook outdated' warning to persist after rtk init -g. The fix points the migration at resolve_claude_dir() and moves Cursor cleanup to its own home-based lookup, plus adds tests covering both the CLAUDE_CONFIG_DIR and default ~/.claude paths.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4757


Analyzed automatically by wshm · This is an automated analysis, not a human review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working hooks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

With CLAUDE_CONFIG_DIR set, rtk init -g leaves the legacy hook script and "Hook outdated" never clears

1 participant