Skip to content

OpenCode plugin: process.execPath is opencode.exe, not a JS runtime - all execFile calls fail silently #187

Closed

Description

@zutur

Problem

The auto-installed OpenCode plugin (~/.config/opencode/plugin/wmux.js) uses process.execPath to run wmux.js:

const cli = process.env.WMUX_CLI;
const file = cli ? process.execPath : "wmux";
const argv = cli ? [cli, ...args] : args;
execFile(file, argv, { windowsHide: true }, () => {});

This assumes process.execPath is a Node or Bun binary that can execute JS files. In Claude Code that's true (process.execPath = node.exe), but in OpenCode it's the compiled binary:

C:\Users\stefan\.opencode\bin\opencode.exe

So every call becomes:

opencode.exe wmux.js agent-activity --surface ... --active

OpenCode doesn't recognize wmux.js as a subcommand and prints its help page. The () => {} callback swallows the error, so the failure is completely silent.

Result: The sidebar stays stuck on "Running" and never transitions to "Done", "Needs you", or any other state.

Fix

Replace process.execPath with an actual Node binary when it doesn't point to a JS runtime. For example:

function findNode() {
  const p = process.execPath;
  if (/\b(node|bun)(\.exe)?$/i.test(p)) return p;
  const fs = require("node:fs");
  const candidates = [
    process.env.LOCALAPPDATA + "\\Programs\\nodejs\\node.exe",
    "C:\\Program Files\\nodejs\\node.exe",
  ];
  for (const c of candidates) {
    try { if (fs.existsSync(c)) return c; } catch {}
  }
  return "node";
}
const NODE = findNode();

Then use NODE instead of process.execPath:

const file = cli ? NODE : "wmux";

Environment

  • wmux: latest (plugin version 2)
  • OpenCode: latest (opencode.exe compiled binary)
  • OS: Windows 11
  • Node: installed at %LOCALAPPDATA%\Programs\nodejs\node.exe but not on PATH inside OpenCode's process

Activity

  1. zutur commented on Aug 22, 2026

    @zutur
    Author

    One thought — looking at this more closely, the plugin could potentially avoid the node dependency entirely by talking to the named pipe directly from within the plugin process. OpenCode's runtime supports node:net, so something like:

    const net = require("node:net");
    
    function wmux(method, params) {
      try {
        const client = net.connect({ path: pipePath }, () => {
          const msg = JSON.stringify({ method, params, id: 1, token });
          client.write(msg + "\n", () => client.end());
          client.resume();
        });
        client.on("error", () => {});
      } catch {}
    }

    This is essentially what wmux-hook.js does under the hood. It would sidestep the process.execPath issue altogether and also be a bit faster since it avoids spawning a child process for every event.

    Just an idea — the findNode() fix works fine as a pragmatic solution too.

  2. amirlehmam commented on Aug 22, 2026

    @amirlehmam
    Owner

    Thanks @zutur — this is an excellent report, and the diagnosis was exactly right. Fixed in v1.9.0 (393ed65).

    You found a hosting assumption, not just a bad line. process.execPath was a JS runtime by accident of the host: under Claude Code it happens to be node.exe, so the code shipped and looked fine. Under OpenCode it is the compiled binary and the whole bridge silently disappears — and the () => {} callback is why it stayed invisible for an entire release line, which is arguably the worse half of the bug.

    I took your fix and pushed the resolution one step upstream. wmux spawns the pane, so it is the process best placed to answer "what can run a .js file on this machine", and it now does that once at launch and declares the answer to everything downstream:

    WMUX_NODE=C:\Program Files\nodejs\node.exe
    WMUX_NODE_ELECTRON=            # 1 only when WMUX_NODE is wmux's own binary
    

    The plugin's chain is now:

    1. $WMUX_NODE — wmux already looked, and it could look in places a plugin cannot.
    2. process.execPath, but only when its basename really is node/bun — your check, kept for a plugin installed by an older wmux.
    3. Every PATH entry, then the default install dirs (%ProgramFiles%\nodejs, %LOCALAPPDATA%\Programs\nodejs, ~/.bun/bin, …) — which is the case you hit: node installed, just not on the PATH that process inherited.
    4. Bare node.

    The last resort on the wmux side is wmux's own binary, which is plain Node when spawned with ELECTRON_RUN_AS_NODE=1. So the chain can't dead-end even on a machine with no Node at all. That flag is also the difference between "a JS runtime" and "a second wmux window opens", which is why it travels as its own variable rather than being inferred from the path.

    Two things came out of chasing it:

    • The wmux / wmux.cmd shims had the same latent bug. They ran bare node, i.e. the same assumption one layer down. They now prefer $WMUX_NODE and fall back to the old behaviour when it is absent.
    • wmux.cmd was one commit away from being LF-only, which cmd.exe "handles" by resuming mid-token — setlocal runs as tlocal, REM as M — while still reaching the last line. It half-works, so the only symptoms are stderr noise and a setlocal that never took. .gitattributes now pins eol=crlf instead of relying on core.autocrlf.

    Covered by tests that load the shipped resources/opencode-plugin/wmux.js itself rather than a paraphrase of it — a one-token bug deserves a test that would actually have caught the one token — plus tests that run the real .cmd through cmd.exe and assert on argument quoting and CRLF.

    The plugin carries a version marker, so wmux replaces the v2 copy in ~/.config/opencode/plugin/wmux.js on first launch. Nothing to do but update. And if it ever misbehaves again, WMUX_PLUGIN_DEBUG=1 now makes the plugin log failed CLI calls instead of swallowing them.

    Answering #188 separately.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions