Skip to content

rtk init claims any Claude or Cursor hook command that mentions rtk-rewrite.sh #4427

Open

Description

@KuSh

Claude and Cursor recognise the legacy hook with cmd.contains("rtk-rewrite.sh"): hook_already_present and remove_legacy_hook_entries_from_json in src/hooks/init/claude.rs, is_cursor_hook_entry and remove_legacy_cursor_hook_entries_from_json in src/hooks/init/cursor.rs. A user hook that only mentions the name is treated as RTK's.

Repro on develop 6f5503d, with ~/.claude/settings.json holding one PreToolUse Bash group:

[{"type":"command","command":"echo rtk-rewrite.sh"},
 {"type":"command","command":"/custom/rtk-rewrite.sh.backup"},
 {"type":"command","command":"python3 /custom/audit.py --label rtk-rewrite.sh"}]
  • rtk init -g --auto-patch prints settings.json: hook already present and registers nothing; the file is unchanged, so RTK is not installed.
  • rtk init -g --uninstall removes all three (settings.json: removed RTK hook entry).
  • The same uninstall, with ~/.cursor/hooks.json holding echo rtk-rewrite.sh, /custom/rtk-rewrite.sh.backup and my-guard under preToolUse, leaves only my-guard.

Expected: only the script run on its own (one word whose file name is rtk-rewrite.sh) is RTK's. The Codex installer is getting the same rule in #4309.

Related: #4227 (the same class for Gemini), #3036 (uninstall removes a whole matcher group), #3693 (legacy script deleted before the replacement is registered).

Activity

  1. rtk-wshm-sync-bot commented on Oct 3, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 90%

    Summary

    Claude/Cursor hook detection uses substring match on 'rtk-rewrite.sh', wrongly claiming unrelated user hooks that merely mention the name during init/uninstall.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/hooks/init/claude.rs
    • src/hooks/init/cursor.rs

    Suggested Actions

    1. Fix hook_already_present/remove_legacy_hook_entries_from_json in src/hooks/init/claude.rs to match the command as a…
    2. Apply same fix to is_cursor_hook_entry/remove_legacy_cursor_hook_entries_from_json in src/hooks/init/cursor.rs
    3. Coordinate with fix(init): migrate legacy Codex hooks #4309 (Codex) and rtk init --gemini treats any BeforeTool group whose first hook contains "rtk" as RTK's: uninstall deletes user hooks, install skips #4227 (Gemini) since they share the same matching bug
    4. Add regression tests covering commands that merely reference rtk-rewrite.sh (e.g. backups, audit scripts, echo)

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

  2. TechWizard9999 commented on Oct 5, 2026

    @TechWizard9999
    Contributor

    Hi @KuSh , Could you please assign it to me

  3. TechWizard9999 commented on Oct 5, 2026

    @TechWizard9999
    Contributor

    Hi @KuSh , About this implementation
    We'd decouple the OpenCode plugin installation from Claude side failures: always attempt the OpenCode install, then report any errors, with regression tests for the malformed CLAUDE.md and read-only ~/.claude cases.Is this design okay ? or anything ekse

  4. KuSh commented on Oct 5, 2026

    @KuSh
    CollaboratorAuthor

    About this implementation We'd decouple the OpenCode plugin installation from Claude side failures: always attempt the OpenCode install, then report any errors, with regression tests for the malformed CLAUDE.md and read-only ~/.claude cases.Is this design okay ? or anything ekse

    Hi @TechWizard9999, that's not the subject of the issue. Most of what you're talking about is already handled in #4269. If something is missing there, either review/comment on it or push a separate PR for what's missing.

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions