Skip to content

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

Closed

Description

@winmin

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

Activity

  1. github-actions commented on Apr 2, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions