anomalyco / anomalyco/opencode
postinstall runs `opencode --version`, so `sudo npm install -g` leaves `/tmp/opencode` root-owned
@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
sudo npm install -g opencode-ails -ld /tmp/opencode→drwxr-xr-x 2 root root ... /tmp/opencode- As the normal user,
touch /tmp/opencode/x→Permission 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
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.