anomalyco / anomalyco/opencode

postinstall runs `opencode --version`, so `sudo npm install -g` leaves `/tmp/opencode` root-owned

Open
#48,457 0 comments 0 reactions 1 assignee View on GitHub

@neriousy is already working on this.

Since Sep 11, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

opencode-ai's npm postinstall ends with a smoke test that runs the binary it just downloaded, verifyBinary()opencode --version. That is enough to create every global directory, because global.ts does the mkdirs at module top level, before any command dispatch.

So sudo npm install -g opencode-ai, which is the normal way to install globally and the only way when the npm prefix is under /usr, leaves /tmp/opencode owned by root. The user can never write to it afterwards.

Nothing warns, because fs.mkdir(..., { recursive: true }) on an existing directory succeeds whoever owns it, so opencode itself starts fine. But the shell tool description tells every agent that directory "has already been created, already exists, and is pre-approved for external directory access", which is then false. Agents go there first and get Permission denied.

The $HOME directories usually escape, since sudo gives the command root's own HOME. With sudo -E they land in the user's home owned by root and opencode fails outright.

#44696 is the same broken state reached without root: /tmp/opencode is a fixed name in a shared namespace, so on a multi-user box whoever runs opencode first owns it. It was read there as host provisioning, but installing as root gets you there before anyone runs opencode at all.

I think a simple fix would be making --version have no side effects (stop creating files/dirs when just querying the version).

At the moment we needed to add a workaround to clean up after the installation in our container environment:

Plugins

None

OpenCode version

1.18.30

Steps to reproduce
  1. sudo npm install -g opencode-ai
  2. ls -ld /tmp/opencodedrwxr-xr-x 2 root root ... /tmp/opencode
  3. As the normal user, touch /tmp/opencode/xPermission denied

The side effects on their own, no root needed:

$ mkdir -p probe/home probe/tmp
$ env -i PATH=/usr/bin:/bin HOME=$PWD/probe/home TMPDIR=$PWD/probe/tmp opencode --version
1.18.30
$ find probe -type d | sed 's|^probe||'
/home/.cache/opencode
/home/.cache/opencode/bin
/home/.config/opencode
/home/.local/share/opencode
/home/.local/share/opencode/log
/home/.local/share/opencode/repos
/home/.local/state/opencode
/tmp/opencode
Screenshot and/or share link

No response

Operating System

Ubuntu 25.10, Node 24, npm prefix /usr

Terminal

No response (happens at install time, no terminal involved)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.