You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEATURE]: Don't default agent scratch dir to a RAM-backed /tmp #55006
I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
OpenCode's scratch dir is os.tmpdir()/opencode, and the built-in env prompt tells the model to prefer it ("Prefer /tmp/opencode over generic system temporary directories...", packages/core/src/instructions/builtins.ts).
On most Linux distros, /tmp is a tmpfs, so everything the agent puts there lives in RAM until it's deleted. Agents use this dir for big stuff - downloads, extracted archives, builds. In one session mine left ~4.6 GB of firmware images in /tmp/opencode, which ate RAM and pushed the system into swap (zram on my Fedora system, so that's RAM too).
Setting TMPDIR=/var/tmp works around it, but most people won't know they need to.
Suggestion: default the scratch dir to disk-backed storage, e.g. $XDG_CACHE_HOME/opencode/tmp (with cleanup of old files), or at least avoid /tmp when it's tmpfs. The system prompt can still instruct to use /tmp where it makes sense such as high frequency I/O on smaller files.
To restate the request: OpenCode's agent scratch dir, which the env prompt tells the model to prefer, is os.tmpdir()/opencode. On distros where /tmp is tmpfs, large downloads, archives and builds placed there use up RAM. You suggest defaulting to disk-backed storage such as $XDG_CACHE_HOME/opencode/tmp (with cleanup of old files), or at least avoiding /tmp when it is tmpfs.
I checked the code, and it works the way you describe: the path comes from packages/util/src/global-roots.ts. Setting TMPDIR=/var/tmp is the workaround available today. This can't be done as a plugin, because the scratch path and its automatic access approval are set in core when OpenCode starts.
The RAM-backed scratch directory is not only a place where agent files are written — it is also loaded as a location, so it gets its own instance of every global stdio MCP server.
So the scratch dir is not only consuming RAM for its own file contents — it is a third "directory" in the per-location server fan-out described in #51003. On this machine the three active locations were:
and the RAM-backed one accounted for a full extra set of MCP processes (~150 MB per server set on this box).
There is a second, larger consequence. The location watcher subscribes to the ancestor chain of every location, so this scratch path additionally pulls in the following as watched directories:
see #55937. On this machine path=/ (the filesystem root) was subscribed as well, with 3122 backend=node watcher events against 1629 backend=fs-events events — the node backend is the fallback used for exactly those ancestor paths, so it is the path that turns unrelated filesystem activity into server-side event storms.
Making the scratch dir live on the same filesystem as the workspace, or excluding it from location discovery, would remove both the RAM pressure and the extra server instances.
Activity
opencode-agent commentedon Oct 13, 2026
Thanks for the detailed write-up, @joshuaeroman!
To restate the request: OpenCode's agent scratch dir, which the env prompt tells the model to prefer, is
os.tmpdir()/opencode. On distros where/tmpis tmpfs, large downloads, archives and builds placed there use up RAM. You suggest defaulting to disk-backed storage such as$XDG_CACHE_HOME/opencode/tmp(with cleanup of old files), or at least avoiding/tmpwhen it is tmpfs.I checked the code, and it works the way you describe: the path comes from
packages/util/src/global-roots.ts. SettingTMPDIR=/var/tmpis the workaround available today. This can't be done as a plugin, because the scratch path and its automatic access approval are set in core when OpenCode starts.Related issues:
/tmpdir #49073: request for a separate tmp dir per project or session/tmp/opencodeowned by another userThe maintainers will consider this.
CerisonAutomation commentedon Oct 22, 2026
The RAM-backed scratch directory is not only a place where agent files are written — it is also loaded as a location, so it gets its own instance of every global stdio MCP server.
From the server log:
So the scratch dir is not only consuming RAM for its own file contents — it is a third "directory" in the per-location server fan-out described in #51003. On this machine the three active locations were:
and the RAM-backed one accounted for a full extra set of MCP processes (~150 MB per server set on this box).
There is a second, larger consequence. The location watcher subscribes to the ancestor chain of every location, so this scratch path additionally pulls in the following as watched directories:
see #55937. On this machine
path=/(the filesystem root) was subscribed as well, with 3122backend=nodewatcher events against 1629backend=fs-eventsevents — the node backend is the fallback used for exactly those ancestor paths, so it is the path that turns unrelated filesystem activity into server-side event storms.Making the scratch dir live on the same filesystem as the workspace, or excluding it from location discovery, would remove both the RAM pressure and the extra server instances.