Fix: opencode spawn() fails with ENOENT on Windows - #7
Open
roend83 wants to merge 1 commit into
Open
Conversation
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
force-pushed
the
fix/windows-spawn-shell
branch
from
July 30, 2026 18:56
71d7ee1 to
c1606aa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
child_process.spawn(\"opencode\", ...)fails withENOENTon Windows because npm installs global CLI shims asopencode.cmd/opencode.ps1, andspawn()only resolves those through a shell (shell: true). This breaks every companion command on Windows —setup,review,rescue, and the backgroundservecall — even when OpenCode is installed and onPATH.which opencodeinstall check forwhere opencodeonwin32, sincewhichisn't a native Windows binary and the previous check would report "not installed" even when it was.shell: process.platform === \"win32\"to all four affectedspawn()calls (resolveOpencodeBinary,getOpencodeVersion,runCommand,spawnDetachedinprocess.mjs, and the server-startspawninopencode-server.mjs), pluserrorhandlers so a missing binary resolves gracefully instead of throwing an unhandledChildProcesserror event.Test plan
node scripts/opencode-companion.mjs setup --jsonnow returns{"installed": true, "version": "1.18.9", ...}instead of throwingError: spawn opencode ENOENT.shellstaysfalse,whichunaffected).