rtk icon indicating copy to clipboard operation
rtk copied to clipboard

OpenCode plugin (tool.execute.before) never fires on Windows — auto-rewrite broken

Open JettHayes opened this issue 6 months ago • 3 comments

Title

OpenCode plugin (tool.execute.before) never fires on Windows — auto-rewrite broken

Environment

  • RTK: latest (binary at D:\rtk_tools\rtk.exe)
  • OpenCode: latest
  • OS: Windows 11
  • Shell: CMD / PowerShell

Symptom

After rtk init -g --opencode, the plugin file is created at C:\Users\<user>\.config\opencode\plugins\rtk.ts. The plugin loads successfully, but bash commands are never auto-rewritten. Running git status produces raw output instead of rtk git status.

Root cause identified

The original rtk.ts uses which rtk to detect the binary, which does not exist on Windows. This causes the plugin to immediately return {} and disable itself. Replaced with where.exe rtk as primary check with which rtk as fallback — binary is confirmed in PATH — but the tool.execute.before hook still never fires.

Steps to reproduce

  1. Install RTK on Windows, place rtk.exe in a directory on PATH
  2. Run rtk init -g --opencode
  3. Open OpenCode and run any git or shell command
  4. Observe: commands are never rewritten to rtk equivalents

Additional context

  • where.exe rtk returns D:\rtk_tools\rtk.exe correctly inside OpenCode's shell
  • rtk rewrite "git status" correctly returns rtk git status when run manually
  • The hook structure appears identical to the master branch hooks/opencode/rtk.ts
  • Issue #1706 (macOS) was resolved by killing stale processes — no stale processes exist on this Windows setup, issue persists after clean restart

Question

Is tool.execute.before hook dispatch broken specifically on Windows, or is there a Windows-specific plugin format required?

JettHayes avatar May 20 '26 08:05 JettHayes

wshm · Automated triage by AI

🔍 Automated Triage

🐛 Category bug
🟠 Priority high
🎯 Confidence 83%

Summary

OpenCode tool.execute.before hook dispatch does not fire on Windows, completely breaking auto-rewrite; investigate Windows-specific plugin execution path in hooks/opencode/rtk.ts

📁 Relevant files
  • hooks/opencode/rtk.ts

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

pszymkowiak avatar May 27 '26 12:05 pszymkowiak

Confirmed on Windows 11 + OpenCode CLI (rtk 0.47.0). Root causes: (1) no Bun $ shell in the plugin context → silent TypeError, hooks never register; (2) which is Unix-only; (3) rtk rewrite exits non-zero on success (exit 3), so stdout must be recovered from the exception. Same approach as #3330 (which closes #3326) works — worth combining efforts there.

amnesiaof avatar Sep 02 '26 17:09 amnesiaof

Closing as a duplicate of #3326, which tracks the same problem with the more complete discussion. Please follow up there; if your case differs in a way that issue does not cover, comment here and it can be reopened.

KuSh avatar Sep 19 '26 02:09 KuSh