anomalyco / anomalyco/opencode

Windows: postinstall fails to copy binary from optionalDependency — stub remains 479 bytes

Open
#41,370 2 comments 0 reactions 1 assignee View on GitHub

@Hona is already working on this.

Since Aug 9, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

After installing or updating opencode-ai via npm on Windows, the opencode command fails with:

Error al ejecutar el programa 'opencode.exe': El ejecutable especificado no es una aplicación válida para esta plataforma de sistema operativo.

The root cause: the postinstall.mjs script fails to copy the real platform-specific binary over the stub. The bin/opencode.exe remains a 479-byte stub instead of the ~174MB real binary.

Environment

  • OS: Windows 10/11 x64
  • Node.js: v22.16.0
  • npm: global install
  • opencode-ai version: 1.18.11 (also reproducible on 1.18.15)

Steps to Reproduce

  1. npm install -g opencode-ai
  2. opencode --version
  3. Error: binary not valid for platform

Diagnosis

The package structure:

opencode-ai/
  bin/opencode.exe          ← 479 bytes (STUB - broken)
  postinstall.mjs           ← should copy real binary
  node_modules/
    opencode-windows-x64/
      bin/opencode.exe      ← 174MB (REAL binary)

The postinstall.mjs script:

  1. Detects platform (windows) and arch (x64)
  2. Checks AVX2 support
  3. Should copy opencode-windows-x64/bin/opencode.exe to bin/opencode.exe
  4. Fails silently — stub remains unchanged

Running the postinstall manually works:

node "C:\Users\...\npm\node_modules\opencode-ai\postinstall.mjs"
# After this, bin/opencode.exe is 174MB and works

Additional Context

  • The real binary IS downloaded as an optionalDependency (opencode-windows-x64)
  • The postinstall.mjs uses fs.linkSync with fallback to fs.copyFileSync
  • No error is thrown — the script exits cleanly but the stub is not replaced
  • This happens consistently across multiple install/update cycles
  • Windows Defender may be blocking the binary copy operation

Suggested Fix

The postinstall.mjs should:

  1. Verify the target binary was actually replaced (check file size or hash)
  2. Throw an explicit error if the copy/link failed
  3. Or: skip the stub entirely and have npm use the optionalDependency binary directly

Workaround

Run the postinstall manually after each install/update:

node "$(npm root -g)/opencode-ai/postinstall.mjs"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.