Skip to content

Portable process spawning across macOS and Windows #28

@JohnnyVicious

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:

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