[BUG] ENOENT on first run: cache directory not created before writing version file #8114

Open
opened 2026-02-16 18:09:12 -05:00 by yindo · 0 comments
Owner

Originally created by @winmin on GitHub (Jan 31, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

On first run, OpenCode fails with ENOENT: no such file or directory when trying to write to ~/.cache/opencode/version.

The issue is in packages/opencode/src/global/index.ts. The code creates directories for data, config, state, log, and bin, but does not create the cache directory:

await Promise.all([
  fs.mkdir(Global.Path.data, { recursive: true }),
  fs.mkdir(Global.Path.config, { recursive: true }),
  fs.mkdir(Global.Path.state, { recursive: true }),
  fs.mkdir(Global.Path.log, { recursive: true }),
  fs.mkdir(Global.Path.bin, { recursive: true }),
  // Missing: fs.mkdir(Global.Path.cache, { recursive: true }),
])

Later, the code tries to write to the cache directory (line 54):

await Bun.file(path.join(Global.Path.cache, "version")).write(CACHE_VERSION)

This fails because the parent directory doesn't exist.

Error Message

ENOENT: no such file or directory, open '/Users/xxx/.cache/opencode/version'
path: "/Users/xxx/.cache/opencode/version",
syscall: "open",
errno: -2,
code: "ENOENT"
Bun v1.3.5 (macOS x64)

OpenCode version

1.1.47

Steps to reproduce

  1. Fresh install OpenCode on a system where ~/.cache/opencode/ does not exist
  2. Run opencode
  3. Observe ENOENT error

Expected behavior

OpenCode should create the cache directory before attempting to write the version file.

Suggested fix

Add fs.mkdir(Global.Path.cache, { recursive: true }) to the directory creation block in packages/opencode/src/global/index.ts.

Operating System

macOS (also reported on other platforms)

Terminal

Any

Originally created by @winmin on GitHub (Jan 31, 2026). Originally assigned to: @rekram1-node on GitHub. ### Description On first run, OpenCode fails with `ENOENT: no such file or directory` when trying to write to `~/.cache/opencode/version`. The issue is in `packages/opencode/src/global/index.ts`. The code creates directories for `data`, `config`, `state`, `log`, and `bin`, but **does not create the `cache` directory**: ```typescript await Promise.all([ fs.mkdir(Global.Path.data, { recursive: true }), fs.mkdir(Global.Path.config, { recursive: true }), fs.mkdir(Global.Path.state, { recursive: true }), fs.mkdir(Global.Path.log, { recursive: true }), fs.mkdir(Global.Path.bin, { recursive: true }), // Missing: fs.mkdir(Global.Path.cache, { recursive: true }), ]) ``` Later, the code tries to write to the cache directory (line 54): ```typescript await Bun.file(path.join(Global.Path.cache, "version")).write(CACHE_VERSION) ``` This fails because the parent directory doesn't exist. ### Error Message ``` ENOENT: no such file or directory, open '/Users/xxx/.cache/opencode/version' path: "/Users/xxx/.cache/opencode/version", syscall: "open", errno: -2, code: "ENOENT" Bun v1.3.5 (macOS x64) ``` ### OpenCode version 1.1.47 ### Steps to reproduce 1. Fresh install OpenCode on a system where `~/.cache/opencode/` does not exist 2. Run `opencode` 3. Observe ENOENT error ### Expected behavior OpenCode should create the cache directory before attempting to write the version file. ### Suggested fix Add `fs.mkdir(Global.Path.cache, { recursive: true })` to the directory creation block in `packages/opencode/src/global/index.ts`. ### Operating System macOS (also reported on other platforms) ### Terminal Any
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8114