Skip to content

OpenCode CLI on Windows: plugin module appears never loaded — tool.execute.before never fires, diagnostic plugin's top-level console.log never prints, distinct from #1993/#3326 #3742

Open

Description

@lmdev-ai

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 via cargo install --git https://github.com/rtk-ai/rtk, binary at C:\Users\itkam\.cargo\bin\rtk.exe)
  • opencode-ai 1.18.25 (npm global install, opencode.exe at C:\Users\itkam\AppData\Roaming\npm\node_modules\opencode-ai\bin\opencode.exe)
  • Windows 10.0.26200.0 (Windows 11), PowerShell 7
  • which.exe present 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

  1. rtk init -g --opencode --no-patch → generated C:\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/).
  2. 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 of rtk 0.42.4; PR fix(opencode): export plugin as default #2566 is open but appears unreleased).
  3. 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.exe PID).
  4. Verified the plugin file content is exactly the expected template + the export default line (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 TestMarkerPlugin

After 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 RtkOpenCodePlugin

Why this looks distinct from #1993 and #3326

  • OpenCode plugin (tool.execute.before) never fires on Windows — auto-rewrite broken #1993 (Windows, tool.execute.before never fires): confirms the same top-level symptom on Windows but does not identify a root cause; the reporter explicitly asks "Is tool.execute.before hook dispatch broken specifically on Windows, or is there a Windows-specific plugin format required?" — still open.
  • rtk init --opencode plugin silently does nothing on Desktop ($ is not a function) and on Windows (which not found) #3326 (Desktop $ is not a function, Windows which not found): the Windows portion of that report attributes the failure specifically to which being unavailable, causing the availability check to throw and the plugin to return {} from inside its async body. In this environment which is 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/.js modules in this directory at all, or (b) evaluation happens but console.log/console.warn output from within a plugin module is swallowed entirely (not routed to opencode.log, not visible via --print-logs).

Expected behavior

Either:

  1. tool.execute.before fires as documented (https://opencode.ai/docs/plugins/), and commands get rewritten by RTK automatically, or
  2. 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 gain command 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:

  1. Local ~/.config/opencode/plugins/*.ts are actually being scanned/loaded on OpenCode 1.18.25 + Windows, and
  2. Whether console.log/console.warn inside a plugin module is expected to be visible anywhere (which log/flag), so this can be debugged further from the reporter's side.

Activity

  1. amnesiaof commented on Oct 12, 2026

    @amnesiaof
    Contributor

    #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 over rtk hook opencode, so there is no longer a step where the module could fail to evaluate. tool.execute.before is also registered in the V2 shape, and Windows is exercised by the Rust test suite.

    Could you try a build from develop and say whether the top-level console.log prints 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.mjs is not wired into CI, so nothing in the pipeline exercises the TypeScript path on any platform yet.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions