Skip to content

Fix: opencode spawn() fails with ENOENT on Windows - #7

Open
roend83 wants to merge 1 commit into
tasict:mainfrom
roend83:fix/windows-spawn-shell
Open

Fix: opencode spawn() fails with ENOENT on Windows#7
roend83 wants to merge 1 commit into
tasict:mainfrom
roend83:fix/windows-spawn-shell

Conversation

@roend83

@roend83 roend83 commented Jul 30, 2026

Copy link
Copy Markdown

Summary

  • child_process.spawn(\"opencode\", ...) fails with ENOENT on Windows because npm installs global CLI shims as opencode.cmd/opencode.ps1, and spawn() only resolves those through a shell (shell: true). This breaks every companion command on Windows — setup, review, rescue, and the background serve call — even when OpenCode is installed and on PATH.
  • Also swaps the which opencode install check for where opencode on win32, since which isn't a native Windows binary and the previous check would report "not installed" even when it was.
  • Added shell: process.platform === \"win32\" to all four affected spawn() calls (resolveOpencodeBinary, getOpencodeVersion, runCommand, spawnDetached in process.mjs, and the server-start spawn in opencode-server.mjs), plus error handlers so a missing binary resolves gracefully instead of throwing an unhandled ChildProcess error event.

Test plan

  • Verified locally on Windows 11 with OpenCode 1.18.9 installed via npm: node scripts/opencode-companion.mjs setup --json now returns {"installed": true, "version": "1.18.9", ...} instead of throwing Error: spawn opencode ENOENT.
  • No change in behavior on macOS/Linux (shell stays false, which unaffected).

child_process.spawn("opencode", ...) can't resolve npm's Windows CLI
shims (opencode.cmd/opencode.ps1) without shell: true, so every
companion command (setup, review, rescue, serve) fails with
ENOENT on Windows even when OpenCode is installed and on PATH.

Also swaps the `which opencode` availability check for `where`
on win32, since `which` isn't a native Windows binary.
@roend83
roend83 force-pushed the fix/windows-spawn-shell branch from 71d7ee1 to c1606aa Compare July 30, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant