Bug Description
OpenCode crashes on startup when OPENCODE_CONFIG_DIR points to a directory that does not exist.
Steps to Reproduce
- Set Windows user environment variable
OPENCODE_CONFIG_DIR to a path (e.g. D:\JavaTool\OpenCode\opencode-skills)
- Install/update OpenCode Desktop (NSIS installer wipes the install directory during auto-update)
- 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)
Bug Description
OpenCode crashes on startup when
OPENCODE_CONFIG_DIRpoints to a directory that does not exist.Steps to Reproduce
OPENCODE_CONFIG_DIRto a path (e.g.D:\JavaTool\OpenCode\opencode-skills)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 directorywhenensureGitignoretries to write.gitignoreinto the non-existentOPENCODE_CONFIG_DIR.Root Cause
In
packages/opencode/src/config/config.ts,ensureGitignoreusesfs.writeFileStringwhich does not create parent directories. WhenConfigPaths.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 usesEffect.orDie.Environment