Skip to content

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

Closed as not planned

Description

@jadatorin

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"

Activity

  1. github-actions commented on Aug 9, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. MilkyWay008 commented on Aug 17, 2026

    @MilkyWay008

    Saw the 479-byte stub after your npm install -g opencode-ai reinstall...... classic Defender signature-match swallowing the binary copy in postinstall.mjs. The fs.linkSync / copyFileSync fallback in that script swallows the failure and exits 0, so npm thinks everything's fine. Easiest unblock: add opencode-ai's npm cache + your %LOCALAPPDATA%\npm-cache\_npx and the global install path to a Defender exclusion, then rerun npm install -g opencode-ai. Or just disable real-time protection for the install window and re-enable. Btw, I keep a portable Hermes-OTG on a USB stick for exactly these 'Windows toolchain half-broken' moments...... imo, runs the same agent framework side-by-side so you can keep working while the install heals. https://github.com/MilkyWay008/Hermes-OTG

  3. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions