rtk icon indicating copy to clipboard operation
rtk copied to clipboard

Persistent "No hook installed" warning on Windows after rtk init -g --opencode

Open amaldevice opened this issue 8 months ago • 15 comments

Description

After running rtk init -g --opencode (and also rtk init -g), the command rtk gain still shows this warning:

[warn] No hook installed — run rtk init -g for automatic token savings

This warning appears every time even though:

  • The OpenCode plugin has been installed successfully (rtk init --show shows [ok] OpenCode: plugin installed)
  • rtk --version works correctly (currently v0.34.1)
  • rtk gain successfully shows token savings statistics
  • Cursor hook is also installed and working

Steps to Reproduce

  1. Install RTK on Windows (rtk-x86_64-pc-windows-msvc.zip)
  2. Add C:\rtk to PATH
  3. Run rtk init -g --opencode
  4. Restart OpenCode
  5. Run rtk gain

→ Warning still appears.

Expected Behavior

rtk gain should recognize that the OpenCode plugin is installed and not show the "No hook installed" warning (or show a more accurate message for OpenCode/Windows).

Actual Behavior

The warning persists, which is confusing even though token savings are working and the plugin is active.

Environment

  • OS: Windows 11
  • RTK Version: 0.34.1
  • Tool: OpenCode (with custom plugin rtk.ts)
  • Other hooks: Cursor hook also installed

Additional Context

According to the troubleshooting docs, OpenCode uses a custom tool.execute.before plugin instead of native Unix-style hooks. The detection logic in rtk gain seems to only check for native hooks, causing this misleading warning on Windows.

It would be great if RTK could:

  • Better detect OpenCode plugin installation on Windows, or
  • Show a more specific message like "OpenCode plugin installed (native hook not available on Windows)" when the plugin is present.
Image

Thanks!

amaldevice avatar Mar 29 '26 14:03 amaldevice

Same issue. Looking for a way to silence this warning please, thanks!

AnshulJ999 avatar Mar 29 '26 16:03 AnshulJ999

same issue with codex

Image

Bobsans avatar Mar 31 '26 09:03 Bobsans

same issue

seccentral avatar Mar 31 '26 12:03 seccentral

same issue

SilasFan avatar Mar 31 '26 18:03 SilasFan

wshm · Automated triage by AI

🔍 Automated Triage

🐛 Category bug
🟡 Priority medium
🎯 Confidence 88%

Summary

rtk gain emits false 'No hook installed' warning on Windows when OpenCode plugin is installed — hook detection logic does not check for OpenCode plugin presence

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

📁 Relevant files
  • src/gain.rs
  • src/init.rs

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

pszymkowiak avatar Apr 04 '26 10:04 pszymkowiak

same issue with claude code

guillaumejay avatar Apr 13 '26 14:04 guillaumejay

I have a similar issue on linux & claude code; I ran rtk init -g resulting in;

rtk init --show
rtk Configuration:

[ok] Hook: /home/cwr/.claude/hooks/rtk-rewrite.sh (thin delegator, version 3)
[ok] RTK.md: /home/cwr/.claude/RTK.md (slim mode)
[ok] Integrity: hook hash verified
[ok] Global (~/.claude/CLAUDE.md): @RTK.md reference
[--] Local (./CLAUDE.md): not found
[ok] settings.json: RTK hook configured
[--] OpenCode: plugin not found
[--] Cursor hook: not found
[--] Cursor hooks.json: not found

but claude still shows this warning and rtk gain is empty as well

cwrau avatar Apr 15 '26 08:04 cwrau

Root Cause Analysis

I traced the detection logic in src/hooks/hook_check.rs and found the exact cause:

The Problem

hook_installed_path() (line 111) only checks for the bash script file, not the settings.json binary hook entry:

fn hook_installed_path() -> Option<PathBuf> {
    let home = dirs::home_dir()?;
    let path = home
        .join(CLAUDE_DIR)       // .claude
        .join(HOOKS_SUBDIR)     // hooks
        .join(REWRITE_HOOK_FILE); // rtk-rewrite.sh  <-- only checks this file!
    if path.exists() {
        Some(path)
    } else {
        None  // <-- Missing status, triggers warning
    }
}

On Windows:

  1. rtk init -g refuses to create the bash script ("Hook-based mode requires Unix" — src/hooks/init.rs:946)
  2. The settings.json binary hook entry ("rtk hook claude") IS correctly registered
  3. But hook_check.rs never reads settings.json — it only looks for the .sh file
  4. Result: permanent HookStatus::Missing on Windows, even when the hook is functional

This is especially relevant now that PR #956 (feat: binary hook w/ native cmd exec) has landed on develop, which registers binary hooks in settings.json instead of bash scripts.

Workaround

Create a dummy script file with the expected version tag:

mkdir -p ~/.claude/hooks
cat > ~/.claude/hooks/rtk-rewrite.sh << 'SCRIPT'
#!/bin/sh
# rtk-hook-version:3
# Dummy file for Windows binary hook detection (see #913)
# The actual hook is registered in settings.json as: rtk hook claude
SCRIPT

This satisfies hook_installed_path() and parse_hook_version() — warning disappears immediately.

Suggested Fix

hook_check.rs should also check settings.json for the binary hook pattern ("rtk hook claude") as an alternative to the bash script file. Something like:

fn hook_installed_path() -> Option<PathBuf> {
    let home = dirs::home_dir()?;
    // Check bash script (existing)
    let script = home.join(CLAUDE_DIR).join(HOOKS_SUBDIR).join(REWRITE_HOOK_FILE);
    if script.exists() {
        return Some(script);
    }
    // Check settings.json for binary hook (new)
    if binary_hook_registered_in_settings(&home) {
        return Some(/* sentinel or refactor to enum */);
    }
    None
}

Environment

  • OS: Windows 11
  • RTK: dev-0.37.0-rc.153 (binary reports 0.34.3 — version string not updated in RC)
  • Hook: Registered in ~/.claude/settings.json via "rtk hook claude"

1llum1n4t1s avatar Apr 16 '26 13:04 1llum1n4t1s

cc @pszymkowiak @aeppling — This is likely a quick follow-up to PR #956. The binary hook engine works great on Windows, but hook_check.rs still only looks for the bash script file. Would you be open to a PR that adds settings.json detection as a fallback?

1llum1n4t1s avatar Apr 16 '26 13:04 1llum1n4t1s

Fix is on develop branch, release asap, we just need another maintainer approval

aeppling avatar Apr 20 '26 17:04 aeppling

Should be resolved in 0.37.2

aeppling avatar Apr 20 '26 18:04 aeppling

Root Cause + Workaround

Root Cause

rtk init -g --opencode installs the opencode plugin but not the Claude Code hook. RTK's internal check (hook_check.rs) only looks for the Claude Code hook in ~/.claude/settings.json — if missing, it emits the warning on every command.

This is a false positive for opencode users. The opencode plugin (tool.execute.before -> rtk rewrite) handles token rewriting for all commands executed through opencode. The Claude Code hook (rtk hook claude) is a PreToolUse hook that only fires when Claude Code runs a bash command — it does NOT help opencode users at all, neither inside opencode nor in a direct terminal.

So the warning is misleading: it tells opencode users to install a hook that is irrelevant to their setup.

Workaround

Run rtk init -g --auto-patch to silence the warning:

rtk init -g --auto-patch    # installs Claude Code hook (silences the check)
rtk init -g --opencode      # installs opencode plugin (actual token rewriting)

This installs the Claude Code hook in ~/.claude/settings.json, which satisfies hook_check.rs. The hook is harmless — it only activates when Claude Code runs, not opencode.

Verification

Before workaround:

$ rtk git status
[rtk] /!\ No hook installed -- run `rtk init -g` for automatic token savings
* develop

After workaround:

$ rtk git status
* develop

Warning is gone.

Suggested Fix for RTK

hook_check.rs should recognize the opencode plugin as a valid hook mechanism. Two options:

  1. Check for ~/.config/opencode/plugins/rtk.ts existence — if present, the opencode plugin is active and the warning should be suppressed
  2. Have rtk init -g --opencode set an env var (e.g. RTK_OPENCODE_PLUGIN=1 in a config file) that hook_check.rs recognizes

This would make the warning accurate: it would only fire when neither the Claude Code hook nor the opencode plugin is installed.

Environment

  • RTK: 0.44.2
  • OS: Windows 11
  • Integration: opencode plugin

AndyS77 avatar Aug 11 '26 08:08 AndyS77

Another way to reach this: a Cursor-only install. hook_check::status() only looks for the Claude hook in ~/.claude/settings.json, so any agent other than Claude gets the warning as soon as a ~/.claude directory exists.

With #3000 (--agent cursor stops installing Claude Code files), on a home that has an empty ~/.claude:

$ rtk init -g --agent cursor --auto-patch   # exit 0, writes only ~/.cursor/hooks.json
$ rtk ls
[rtk] /!\ No hook installed — run `rtk init -g` for automatic token savings

On current develop, rtk init -g --gemini --auto-patch followed by rtk ls prints the same line. The suggested rtk init -g would install the Claude Code files that these users chose not to install.

KuSh avatar Sep 25 '26 23:09 KuSh

One more arm, from #3711 (native Antigravity hook): a project set up with rtk init --agent antigravity gets the same warning from rtk gain as soon as ~/.claude exists, for the reason named above: hook_check::status() inspects Claude's settings.json only. Antigravity's hook lives in .agents/plugins/rtk/hooks.json (or ~/.gemini/config/plugins/rtk/hooks.json with -g), so the detection has nothing to look at. Same mechanism, one more agent to cover when this is fixed.

KuSh avatar Sep 28 '26 00:09 KuSh

Part of the path is fixed, so this needs a retest rather than a close.

The plugin used to be a TypeScript file that had to find rtk on its own. It is now a shim over rtk hook opencode, and hook detection has an --agent opencode mode, so rtk gain is no longer blind to the integration by construction.

But #4518 reports that rtk hook check --agent opencode and the live plugin do not always agree on the same machine, so the warning may be gone while the answer behind it is still wrong. Worth confirming both halves on your box.

Leaving open.

amnesiaof avatar Oct 12 '26 07:10 amnesiaof