fix: Enable Windows builds and fix bun+pnpm install on Windows#4273
Merged
rekram1-node merged 4 commits intoanomalyco:devfrom Nov 13, 2025
Merged
fix: Enable Windows builds and fix bun+pnpm install on Windows#4273rekram1-node merged 4 commits intoanomalyco:devfrom
rekram1-node merged 4 commits intoanomalyco:devfrom
Conversation
Fixes anomalyco#3363 - `bun install -g opencode-ai` now works on Windows
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes critical Windows build and installation issues for OpenCode by ensuring platform identifier consistency and proper path handling across the build and postinstall scripts.
- Unified platform identifier to use
"win32"instead of"windows"throughout the codebase to match Node.js'sprocess.platform - Fixed Windows path separator issues by normalizing backslashes to forward slashes in bundled paths
- Added explicit bun support on Windows by copying the executable directly instead of relying on wrapper scripts
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
packages/opencode/script/postinstall.mjs |
Updated platform detection to use "win32" consistently, added bun-specific binary installation logic for Windows that copies the .exe directly, and improved user agent detection with safe fallback |
packages/opencode/script/build.ts |
Changed platform identifier from "windows" to "win32" in target definitions, normalized Windows path separators in the tree-sitter worker path, and simplified package.json OS field generation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
xywsxp
pushed a commit
to xywsxp/opencode
that referenced
this pull request
Apr 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3363 -
bun install -g opencode-ainow works on WindowsFixes #4195 -
pnpm install -g opencode-ainow works on WindowsProblem
OpenCode could not be built or installed on Windows using bun due to three critical issues:
Build script platform mismatch: The build script used
"windows"as the platform identifier, butprocess.platformreturns"win32"on Windows. This caused:--singleflag to fail (built wrong platform or nothing at all)opencode-windows-x64that didn't match the expectedopencode-win32-x64Windows path separator bug: The build script used
path.relative()which returns backslashes on Windows (\), but the bundled code expected forward slashes (/). Thiscaused syntax errors and made all Windows builds fail.
Bun install failure: The postinstall script skipped all processing when detecting bun on Windows, causing bun to generate a default
#!/bin/shwrapper script that failedwith:
error: interpreter executable "/bin/sh" not found in %PATH%
Solution
1. Platform naming consistency
"windows"to"win32"in:build.ts: Target definitions and package.json generationpostinstall.mjs: Platform detection logicprocess.platformvalueWarning
I'm not sure how this would interact with old installs -> upgrade paths
2. Path separator normalization
.replace(/\\/g, "/")to normalize Windows backslashes to forward slashes in bundled pathsOTUI_TREE_SITTER_WORKER_PATHdefine that was causing build failures3. Bun support on Windows
postinstall.mjs.exedirectly to the bin directory (bun doesn't need wrapper scripts)npm rebuildto regenerate CMD/PS1 wrappersTesting
Verified the following scenarios work correctly:
bun run script/build.ts --singleon Windows (now buildsopencode-win32-x64)bun install -g opencode-aion Windows (no more/bin/sherror)npm install -g opencode-aion Windows (CMD wrappers still generated correctly)