fix(sdk): spawn fails on Windows - ENOENT for opencode command #5210

Open
opened 2026-02-16 17:50:00 -05:00 by yindo · 0 comments
Owner

Originally created by @jc01rho on GitHub (Jan 13, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

The SDK's createOpencodeServer and createOpencodeTui functions fail on Windows with:

ENOENT: no such file or directory, uv_spawn 'opencode'

Root Cause

On Windows, npm-installed packages create .cmd wrapper scripts (e.g., opencode.cmd). Node.js spawn() without shell: true cannot find these .cmd files in PATH.

Affected Files

  • packages/sdk/js/src/server.ts (lines 34 and 109)
  • packages/sdk/js/src/v2/server.ts (same locations)

Proposed Fix

Add shell: process.platform === 'win32' to both spawn() calls:

const proc = spawn(\, args, {
  signal: options.signal,
  shell: process.platform === 'win32',  // Add this line
  env: { ... },
})

How to Reproduce

  1. Install OpenCode via npm on Windows: npm i -g opencode-ai
  2. Use the SDK to spawn the server:
    import { createOpencodeServer } from '@opencode-ai/sdk/server'
    await createOpencodeServer({ port: 0 })
    
  3. Observe ENOENT error

Verified Fix

Tested the fix manually - adding shell: true on Windows resolves the issue while maintaining Unix compatibility.

OpenCode Version

1.1.16

Operating System

Windows 11

Originally created by @jc01rho on GitHub (Jan 13, 2026). Originally assigned to: @rekram1-node on GitHub. ## Description The SDK's `createOpencodeServer` and `createOpencodeTui` functions fail on Windows with: ``` ENOENT: no such file or directory, uv_spawn 'opencode' ``` ## Root Cause On Windows, npm-installed packages create `.cmd` wrapper scripts (e.g., `opencode.cmd`). Node.js `spawn()` without `shell: true` cannot find these `.cmd` files in PATH. ## Affected Files - `packages/sdk/js/src/server.ts` (lines 34 and 109) - `packages/sdk/js/src/v2/server.ts` (same locations) ## Proposed Fix Add `shell: process.platform === 'win32'` to both `spawn()` calls: ```typescript const proc = spawn(\, args, { signal: options.signal, shell: process.platform === 'win32', // Add this line env: { ... }, }) ``` ## How to Reproduce 1. Install OpenCode via npm on Windows: `npm i -g opencode-ai` 2. Use the SDK to spawn the server: ```typescript import { createOpencodeServer } from '@opencode-ai/sdk/server' await createOpencodeServer({ port: 0 }) ``` 3. Observe ENOENT error ## Verified Fix Tested the fix manually - adding `shell: true` on Windows resolves the issue while maintaining Unix compatibility. ## OpenCode Version 1.1.16 ## Operating System Windows 11
yindo added the windows label 2026-02-16 17:50:00 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#5210