anomalyco / anomalyco/opencode
Windows: postinstall fails to copy binary from optionalDependency — stub remains 479 bytes
Open
@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
npm install -g opencode-aiopencode --version- 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:
- Detects platform (windows) and arch (x64)
- Checks AVX2 support
- Should copy
opencode-windows-x64/bin/opencode.exetobin/opencode.exe - 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.mjsusesfs.linkSyncwith fallback tofs.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:
- Verify the target binary was actually replaced (check file size or hash)
- Throw an explicit error if the copy/link failed
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.