Skip to content

Crash on startup when OPENCODE_CONFIG_DIR points to a non-existent directory #31341

@weiconghe

Description

@weiconghe

Bug Description

OpenCode crashes on startup when OPENCODE_CONFIG_DIR points to a directory that does not exist.

Steps to Reproduce

  1. Set Windows user environment variable OPENCODE_CONFIG_DIR to a path (e.g. D:\JavaTool\OpenCode\opencode-skills)
  2. Install/update OpenCode Desktop (NSIS installer wipes the install directory during auto-update)
  3. Launch OpenCode

Expected Behavior

OpenCode should start normally and create the config directory if it does not exist.

Actual Behavior

The server process crashes with ENOENT: no such file or directory when ensureGitignore tries to write .gitignore into the non-existent OPENCODE_CONFIG_DIR.

Error: ENOENT: no such file or directory, open D:JavaToolOpenCodeopencode-skills.gitignore

Root Cause

In packages/opencode/src/config/config.ts, ensureGitignore uses fs.writeFileString which does not create parent directories. When ConfigPaths.directories() returns a path that does not exist on disk (e.g. after auto-update wipes the install dir), the write fails with ENOENT. The error is fatal because the call site uses Effect.orDie.

Environment

  • Windows 11
  • OpenCode Desktop (latest, auto-updated)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions