Skip to content

Portable process spawning across macOS and Windows #28

Closed

Description

@JohnnyVicious

Summary

The companion currently spawns opencode, node, and which directly. On Windows, npm-global binaries are usually .cmd shims (opencode.cmd, node may be outside the minimal PATH, etc.), and Node's spawn() with shell: false does not resolve .cmd wrappers.

This is the OpenCode equivalent of several upstream Codex plugin Windows issues.

Local evidence

Affected paths include:

  • plugins/opencode/scripts/lib/process.mjs
    • resolveOpencodeBinary() uses spawn("which", ["opencode"])
    • getOpencodeVersion() uses spawn("opencode", ["--version"])
    • runCommand() uses spawn(cmd, args, ...) without Windows shim handling
    • spawnDetached() uses spawn(cmd, args, ...) for background node
  • plugins/opencode/scripts/lib/opencode-server.mjs
    • ensureServer() uses spawn("opencode", ["serve", ...])

Expected behavior

Setup and runtime commands should work on Windows when OpenCode was installed through npm or another shim-based installer.

Suggested fix

Add a shared spawn helper that handles Windows command resolution deliberately:

  1. Prefer direct executable resolution where possible (where opencode on Windows, command -v/which elsewhere).
  2. For npm .cmd shims, use shell: true or resolve the concrete .cmd path only where needed.
  3. Preserve UNC/network-drive behavior by avoiding blanket shell: true for all git subprocesses.
  4. Add regression coverage around the command-building behavior.

Upstream references

Derived from these applicable upstream issues:

Activity

  1. changed the title [-]Windows: opencode/node process spawning fails for npm .cmd shims[/-] [+]Portable process spawning across macOS and Windows[/+] on Apr 12, 2026
  2. JohnnyVicious commented on Apr 12, 2026

    @JohnnyVicious
    OwnerAuthor

    Consolidating #18 and #46 here. The canonical scope is portable process invocation: Windows npm .cmd shims, Windows shell/SHELL behavior, and macOS Claude Code App minimal PATH/bare-node failures. Command-markdown quoting remains tracked separately in #29.

  3. JohnnyVicious commented on Apr 12, 2026

    @JohnnyVicious
    OwnerAuthor

    Fixed by PR #51 commit f8d3fcc — platformShellOption() picks false on POSIX and $SHELL||true on win32; uses 'where' instead of 'which' on win32; applied to runCommand, spawnDetached, resolveOpencodeBinary, getOpencodeVersion, and ensureServer.

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