Skip to content

cli: upgrade --method bun reports success on Windows but leaves the old binary in place #51386

Open

Description

@KingUjjwal

Description

On Windows, opencode update --method bun prints Upgrade complete but opencode --version still reports the old version (2.0.6). bun does install 2.0.16 into the global package dir and even creates an opencode2 shim, but the opencode.exe on PATH is never replaced because Windows holds a write lock on a running executable. The failure is swallowed and success is reported.

Not a duplicate of #37055: that one is the curl/bash installer path, this is the bun method.

Plugins

None

OpenCode version

2.0.6 (upgrade attempted to 2.0.16); bun global install, bun 1.4.3

Steps to reproduce

  1. bun install -g @opencode/cli (2.0.6), so opencode resolves to %USERPROFILE%\.bun\bin\opencode.exe
  2. With opencode running, run opencode update --method bun
  3. It prints From 2.0.6 → 2.0.16, Upgrade complete, Done resolve
  4. opencode --version still prints opencode v2.0.6

Expected: the new version is in place after a reported success, or the command exits with a clear error if it cannot replace the binary.

The update is only partially applied: bun pm ls -g reports @opencode/[email protected] and %USERPROFILE%\node_modules\@opencode\cli\bin\opencode.exe is v2.0.16, but %USERPROFILE%\.bun\bin\opencode.exe is still v2.0.6. Writing to that file fails with "being used by another process". @opencode/cli's package.json maps both the opencode and opencode2 bin names to the same exe, so bun creates opencode2 and the failure goes unnoticed.

Screenshot and/or share link

┌  Upgrade
●  Using method: bun
●  From 2.0.6 → 2.0.16
◇  Upgrade complete
└  Done  resolve

Then opencode --version → opencode v2.0.6

Operating System

Windows 11 (10.0.26200), x64

Terminal

Windows Terminal, PowerShell 7.6.6

Activity

  1. added
    needs:complianceThis means the issue will auto-close after 2 hours.
    and removed
    needs:complianceThis means the issue will auto-close after 2 hours.
    on Sep 25, 2026
  2. github-actions commented on Sep 25, 2026

    @github-actions
    Contributor

    Thanks for updating the issue with the Bug Report description, reproduction steps, and system details!

  3. Veld101 commented on Sep 29, 2026

    @Veld101

    Adding a real-world occurrence on Windows (x64) with 2.0.19, in case it helps pin the fix.

    After updating to 2.0.19, opencode failed to start at all:

    无法启动 'D:\Data\npm\global\node_modules\@opencode\cli\bin\opencode.exe'
    The specified executable is not a valid application for this OS platform.
    

    What was on disk:

    • bin/opencode.exe was a 229-byte shell stub, not a PE image:
      echo "Error: @opencode/cli's postinstall script was not run." >&2
      echo "" >&2
      echo "This occurs when installation scripts are disabled." >&2
      echo "Run the package postinstall script or reinstall with scripts enabled." >&2
      exit 1
    • node_modules/@opencode/cli-windows-x64 was not installed (only node_modules/@opencode/cli was present), so postinstall.mjs had nothing to link.
    • npm config get ignore-scripts returned false, so this was not npm's global config disabling scripts.
    • The global prefix D:\Data\npm\global contains bun/bunx shims, so bun may have been involved in the install path; bun does not run dependency lifecycle scripts by default.

    Reinstalling fixed it: bin/opencode.exe became a valid PE image (~206 MB, magic MZ), opencode --version reports v2.0.19, and opencode service status responds.

    One more artifact from the same update: the reinstall left an orphaned staging directory node_modules/@opencode/.cli-<id> containing a full node_modules tree (~196 MB) that was never cleaned up.

    So the failure mode here is not "the old binary stayed in place" but "the installed binary is a postinstall placeholder because the platform optional dependency / postinstall did not run". Reporting it here because the trigger surface (Windows + bun-style install) looks the same.

  4. opencodejr commented on Oct 28, 2026

    @opencodejr
    Contributor

    Thanks for the detailed report and diagnosis. Reproducing this depends on how Windows locks running executables, and our test sandbox is Linux, where a running binary can be replaced, so the failure can't happen there. A maintainer with a Windows machine will need to confirm it.

    One thing that may matter: your upgrade was run by 2.0.6. A Windows workaround for upgrading while opencode is running (#50819) first shipped in 2.0.15. Even so, the upgrade command reports success without checking that the binary on your PATH actually changed. If you can, please try again once you're on 2.0.15 or later (for example after closing all opencode processes and reinstalling), then run opencode update --method bun with opencode open and tell us whether opencode --version changes. That would help narrow it down.

    Related issues:

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions