Skip to content

rtk init --gemini treats any BeforeTool group whose first hook contains "rtk" as RTK's: uninstall deletes user hooks, install skips #4227

Open

Description

@KuSh

patch_gemini_settings and uninstall_gemini (src/hooks/init.rs) decide ownership with h.pointer("/hooks/0/command")...contains("rtk") on each BeforeTool group. This has two consequences:

  1. A user hook that shares a group with RTK's hook is deleted on uninstall. The whole group is dropped.
  2. A user hook whose path merely contains rtk counts as RTK's hook. Install then skips adding the real one, and uninstall deletes the user's.

Reproduced on develop f5e104e with LC_ALL=C and a fresh HOME:

# G1: user hook second in RTK's group
~/.gemini/settings.json = {"hooks":{"BeforeTool":[{"matcher":"run_shell_command","hooks":[
    {"type":"command","command":"rtk hook gemini"},
    {"type":"command","command":"/opt/audit/log-shell.sh"}]}]},"theme":"dark"}
$ rtk init -g --gemini --uninstall        -> exit 0, "removed RTK hook entry"
hooks.BeforeTool afterwards: []           # /opt/audit/log-shell.sh is gone

# G2: user hook whose path contains "rtk"
~/.gemini/settings.json = {"hooks":{"BeforeTool":[{"matcher":"run_shell_command","hooks":[
    {"type":"command","command":"/opt/smartkit/check.sh"}]}]}}
$ rtk init -g --gemini --auto-patch       -> exit 0, "Gemini CLI hook installed"
BeforeTool commands afterwards: ["/opt/smartkit/check.sh"]   # RTK hook never registered
$ rtk init -g --gemini --uninstall        -> exit 0, "removed RTK hook entry"
hooks.BeforeTool afterwards: []           # the user's hook is deleted

#4151 moves Claude, Codex, Cursor and Trae onto one presence/removal implementation, which matches the exact RTK command and removes only RTK's hook from a group. Moving Gemini onto it, or at least onto an exact-command, per-hook rule, closes both cases.

Activity

  1. added
    bug
    help wanted
    on Sep 25, 2026
  2. rtk-wshm-sync-bot commented on Sep 25, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 93%

    Summary

    Gemini hook ownership detection in patch_gemini_settings/uninstall_gemini uses a substring match on the group's first hook, causing user hooks to be deleted on uninstall and RTK's hook to be skipped on install when they share a group or path substring.

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

    Suggested Actions

    1. Port Gemini onto the exact-command, per-hook presence/removal logic added for Claude/Codex/Cursor/Trae in refactor(hooks): consolidate hook config I/O #4151
    2. Replace .pointer("/hooks/0/command").contains("rtk") with an exact match against RTK's known command string, checked …
    3. Add regression tests mirroring the G1/G2 repro cases from the issue

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

  3. KuSh commented on Oct 23, 2026

    @KuSh
    CollaboratorAuthor

    The warning check added in #4343 (gemini::is_configured(), read by rtk gain and the daily reminder) uses the same rule: a run_shell_command or * group whose first hook's command contains rtk counts as an RTK install. Two more consequences, both measured on #4343's head merged onto develop 2dabd83 (LC_ALL=C, fresh HOME, ~/.claude without a hook):

    # G3: user hook whose path contains "rtk", no RTK hook
    ~/.gemini/settings.json = {"hooks":{"BeforeTool":[{"matcher":"run_shell_command","hooks":[
        {"type":"command","command":"/home/u/src/rtk/tools/audit.sh"}]}]}}
    $ rtk gain   -> no warning (v1.0.1 and develop: "No hook installed")
    
    # G4: RTK registered, script deleted
    $ rtk init -g --gemini --auto-patch; rm ~/.gemini/hooks/rtk-hook-gemini.sh
    $ rtk gain   -> no warning (v1.0.1 and develop: "No hook installed")
    

    An exact-command rule for install and uninstall, shared with the probe, would close G3 as well. G4 additionally needs the probe to check that the registered script exists; Claude's hook_status() reports a settings entry for a deleted legacy script as Missing.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clibughelp wantedpriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions