Description
opencode upgrade fails with a raw npm EACCES stack trace when the detected npm global prefix is root-owned and the command runs as an unprivileged user. The UI reports "Upgrade complete"-style progress and then dumps the npm error object; there is no hint that the fix is either "run as the prefix owner / root" or "switch to the curl method".
Separately, after a successful upgrade the previously installed v1 standalone binary at ~/.opencode/bin/opencode still precedes the v2 npm bin on PATH (via a shell rc export PATH=$HOME/.opencode/bin:$PATH), so opencode --version keeps printing the v1 version. Nothing in the upgrade output mentions the shadowing binary, so the upgrade looks like it silently did nothing.
Steps to reproduce
- Install OpenCode 2 as root into npm's global prefix (
/usr/lib/node_modules, bin at /usr/bin/opencode).
- As a non-root user whose npm prefix is that same root-owned prefix (
npm prefix -g → /usr, test -w /usr/lib/node_modules → false), run opencode upgrade.
- OpenCode detects the npm install, then spawns
npm install --global --force @opencode/cli@<latest> as the current user and fails.
Relevant log lines from the CLI (~/.local/share/opencode/log/opencode.log):
message="cli starting" version=2.2.5 channel=latest local=false args="[\"upgrade\"]" role=cli
message="spawning process" command=npm args="[\"list\",\"-g\",\"--depth=0\",\"@opencode/cli\"]" role=cli
message="spawning process" command=npm args="[\"install\",\"--global\",\"--force\",\"@opencode/[email protected]\"]" role=cli
Error surfaced to the user:
npm error code EACCES
npm error syscall rename
npm error path /usr/lib/node_modules/@opencode/cli
npm error dest /usr/lib/node_modules/@opencode/.cli-wGQOdxhc
npm error errno -13
npm error Error: EACCES: permission denied, rename '/usr/lib/node_modules/@opencode/cli' -> '/usr/lib/node_modules/@opencode/.cli-wGQOdxhc'
npm error at async Object.rename (node:internal/fs/promises:1491:10)
npm error at async moveFile (/usr/lib/node_modules/npm/node_modules/@npmcli/fs/lib/move-file.js:30:5)
npm error at async Promise.allSettled (index 0)
npm error at async #reifyPackages (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:353:11)
npm error at async Arborist.reify (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist.js:139:7)
npm error at async Install.exec (/usr/lib/node_modules/npm/lib/commands/install.js:158:5)
Running the same command as root upgrades cleanly to 2.2.7.
Expected behaviour
- Before choosing the npm method, check that the detected global prefix is writable by the current user (
fs.access / process.getuid() vs prefix ownership). If it is not, fail fast with a one-line message: the prefix, its owner, and the two supported remedies (sudo opencode upgrade, or opencode upgrade --method curl to install a user-local build).
- Do not surface the raw npm
errno object as the primary error text for a permissions problem that is fully predictable before spawning npm.
- After an upgrade, compare the resolved
opencode on PATH against the newly installed binary and warn when an older one wins, naming its path.
Impact
Non-root users on shared/root-provisioned hosts cannot upgrade through the documented command, and the failure mode is a Node stack trace rather than guidance. On hosts that were previously on v1 via the curl installer, a second failure mode — the shadowed binary — makes the upgrade appear to succeed while opencode keeps running the old major version.
Environment
- OpenCode: 2.2.5 → 2.2.7 (upgrade failing on 2.2.5 and 2.2.7)
- OS: Ubuntu 26.04.1 LTS
- Node: v24.22.2, npm 11.19.1
- Install method: npm global as root (
/usr/bin/opencode → /usr/lib/node_modules/@opencode/cli/bin/opencode.exe); a v1.19.5 standalone also present at /root/.opencode/bin/opencode from the curl installer
- Terminal: non-interactive shell over SSH