Repository navigation
Description
tool.execute.before never fires on OpenCode CLI (Windows) even though which rtk succeeds and a diagnostic plugin's top-level console.log never prints — plugin module appears never evaluated
Related to #1993 and #3326, but neither root cause matches this environment: in #1993 no cause was confirmed; in #3326 the reported cause is which not found on Windows. In this environment which is present and succeeds (exit 0, verified manually both in PowerShell and via cmd /c), yet the RTK plugin's hook still never fires — and, more importantly, a diagnostic plugin's top-level console.log (which runs at module-evaluation time, before any which/availability check) also never prints anywhere, which suggests the plugin module itself is never being loaded/evaluated by OpenCode's plugin loader on this setup, not merely disabling itself inside its async body.
Environment
rtk 0.42.4(installed viacargo install --git https://github.com/rtk-ai/rtk, binary atC:\Users\itkam\.cargo\bin\rtk.exe)opencode-ai 1.18.25(npm global install,opencode.exeatC:\Users\itkam\AppData\Roaming\npm\node_modules\opencode-ai\bin\opencode.exe)- Windows 10.0.26200.0 (Windows 11), PowerShell 7
which.exepresent via Git for Windows (C:\Program Files\Git\usr\bin\which.exe), confirmed working:PS> cmd /c "which rtk" /c/Users/itkam/.cargo/bin/rtk PS> echo $LASTEXITCODE 0
Setup steps taken
rtk init -g --opencode --no-patch→ generatedC:\Users\itkam\.config\opencode\plugins\rtk.ts(the plugin directory path,~/.config/opencode/plugins/, matches OpenCode's own docs at https://opencode.ai/docs/plugins/).- Manually added
export default RtkOpenCodePlugin(workaround for OpenCode plugin missing default export — plugin never loaded by plugin loader #2516 — the generated template still ships without it as ofrtk 0.42.4; PR fix(opencode): export plugin as default #2566 is open but appears unreleased). - Restarted OpenCode CLI completely (verified via process start time newer than the plugin file's mtime; confirmed the running shell's parent process chain resolves to the new
opencode.exePID). - Verified the plugin file content is exactly the expected template + the
export defaultline (full content below).
Empirical test: rtk gain count does not change for commands sent with zero rtk prefix
Baseline (rtk gain) before test: Total commands: 34.
Sent a genuinely un-prefixed command through the assistant's bash tool (constructed via a PowerShell variable specifically to rule out any accidental literal rtk prefix in the command text):
$g = "git"; & $g "blame" "README.md"This executes plain git blame README.md — a command rtk rewrite "git blame README.md" confirms should be rewritten:
PS> rtk rewrite "git blame README.md"
rtk git blame README.md
After running it through the assistant's bash tool (twice, across two separate full OpenCode restarts): rtk gain still reports Total commands: 34 — unchanged. The command executed as raw git blame, not rtk git blame.
Diagnostic plugin: top-level console.log never appears anywhere
To rule out "the hook fires but does nothing" vs. "the module is never loaded", a second, minimal diagnostic plugin was added alongside rtk.ts:
C:\Users\itkam\.config\opencode\plugins\zzz-test-marker.js:
console.log("[RTK-DIAGNOSTIC] plugin file loaded at startup")
export const TestMarkerPlugin = async ({ $ }) => {
console.log("[RTK-DIAGNOSTIC] plugin function invoked")
return {
"tool.execute.before": async (input, output) => {
console.log("[RTK-DIAGNOSTIC] tool.execute.before fired, tool=" + input?.tool)
},
}
}
export default TestMarkerPluginAfter a full OpenCode restart with this file present, [RTK-DIAGNOSTIC] does not appear in:
~/.local/share/opencode/log/opencode.log(searched full file, case-insensitive)- Any other file under
~/.local/share/opencode/or~/.cache/opencode/
Note the top-level console.log("[RTK-DIAGNOSTIC] plugin file loaded at startup") runs at module-evaluation time — before the exported async function is even called, before any $/which logic runs. If the module were loaded at all (even if the plugin function's body later failed), this line should execute and print. It never does, on this OpenCode version/platform combination.
Content of the (working-per-spec) rtk.ts at time of test
import type { Plugin } from "@opencode-ai/plugin"
// RTK OpenCode plugin — rewrites commands to use rtk for token savings.
// Requires: rtk >= 0.23.0 in PATH.
//
// This is a thin delegating plugin: all rewrite logic lives in `rtk rewrite`,
// which is the single source of truth (src/discover/registry.rs).
// To add or change rewrite rules, edit the Rust registry — not this file.
export const RtkOpenCodePlugin: Plugin = async ({ $ }) => {
try {
await $`which rtk`.quiet()
} catch {
console.warn("[rtk] rtk binary not found in PATH — plugin disabled")
return {}
}
return {
"tool.execute.before": async (input, output) => {
const tool = String(input?.tool ?? "").toLowerCase()
if (tool !== "bash" && tool !== "shell") return
const args = output?.args
if (!args || typeof args !== "object") return
const command = (args as Record<string, unknown>).command
if (typeof command !== "string" || !command) return
try {
const result = await $`rtk rewrite ${command}`.quiet().nothrow()
const rewritten = String(result.stdout).trim()
if (rewritten && rewritten !== command) {
;(args as Record<string, unknown>).command = rewritten
}
} catch {
// rtk rewrite failed — pass through unchanged
}
},
}
}
// WORKAROUND for rtk-ai/rtk#2516
export default RtkOpenCodePluginWhy this looks distinct from #1993 and #3326
- OpenCode plugin (tool.execute.before) never fires on Windows — auto-rewrite broken #1993 (Windows,
tool.execute.beforenever fires): confirms the same top-level symptom on Windows but does not identify a root cause; the reporter explicitly asks "Istool.execute.beforehook dispatch broken specifically on Windows, or is there a Windows-specific plugin format required?" — still open. rtk init --opencodeplugin silently does nothing on Desktop ($ is not a function) and on Windows (whichnot found) #3326 (Desktop$ is not a function, Windowswhichnot found): the Windows portion of that report attributes the failure specifically towhichbeing unavailable, causing the availability check to throw and the plugin toreturn {}from inside its async body. In this environmentwhichis present and the manual invocation succeeds outside the plugin — so if the same code path ran, the availability check should pass and the hook should register. It does not appear to reach that far at all (see diagnostic plugin result above), suggesting either (a) OpenCode 1.18.25 on this platform never evaluates local plugin.ts/.jsmodules in this directory at all, or (b) evaluation happens butconsole.log/console.warnoutput from within a plugin module is swallowed entirely (not routed toopencode.log, not visible via--print-logs).
Expected behavior
Either:
tool.execute.beforefires as documented (https://opencode.ai/docs/plugins/), and commands get rewritten by RTK automatically, or- If the plugin fails to load/register for any reason, OpenCode or RTK's own plugin surfaces a visible error/warning (currently: total silence — no error, no warning, no log entry, not even from a bare top-level
console.log).
Actual behavior
rtk gaincommand count is unaffected by un-prefixed commands (34 → 34 across two restarts and multiple distinct git subcommands tested).- Zero trace of the diagnostic plugin ever executing, in any log file.
- No error surfaced anywhere in the CLI, log files, or process output that would explain why.
Request
Since the exact reason the module appears never-evaluated is not identifiable from the client side (no error, no log line), could someone with visibility into OpenCode's local-plugin-directory loader (or a maintainer who can reproduce on Windows + OpenCode 1.18.x) confirm whether:
- Local
~/.config/opencode/plugins/*.tsare actually being scanned/loaded on OpenCode 1.18.25 + Windows, and - Whether
console.log/console.warninside a plugin module is expected to be visible anywhere (which log/flag), so this can be debugged further from the reporter's side.
Activity
amnesiaof commentedon Oct 12, 2026
#4187 changed exactly what this report is about, so it is worth a retest rather than a close.
The plugin no longer calls
which, no longer depends on a Bun$shell, and no longer recovers stdout from a non-zero exit. It is a thin shim overrtk hook opencode, so there is no longer a step where the module could fail to evaluate.tool.execute.beforeis also registered in the V2 shape, and Windows is exercised by the Rust test suite.Could you try a build from
developand say whether the top-levelconsole.logprints and the hook fires? If it still does not, the diagnosis that the module is never evaluated points somewhere rtk no longer reaches, and that is worth knowing.Note that
hooks/opencode/rtk.test.mjsis not wired into CI, so nothing in the pipeline exercises the TypeScript path on any platform yet.