OPENCODE_CONFIG_DIR is broken since 0.15.30 when only world-readable #2384

Open
opened 2026-02-16 17:35:24 -05:00 by yindo · 6 comments
Owner

Originally created by @arlt on GitHub (Oct 31, 2025).

Originally assigned to: @rekram1-node on GitHub.

Description

We use OPENCODE_CONFIG_DIR=/etc/opencode which is only world readable.

Each user has his own ~/.config/opencode/ directory. Here we can see the package.json which is gets generated and used by opencode.

Since 0.15.30 we have the following error when we start opencode:

Error: Unexpected error, check log file at /home/opencode/.local/share/opencode/log/2025-10-31T140216.log for more details

EACCES: permission denied, open '/etc/opencode/package.json'
    path: "/etc/opencode/package.json",
 syscall: "open",
   errno: -13,
    code: "EACCES"

      at write (unknown:1:1)
      at installDependencies (src/config/config.ts:164:17)
      at processTicksAndRejections (unknown:7:39)

Former versions work fine. Fresh setup creates the ~/.config/opencode/package.json and opencode starts.
0.15.30 throws this error.

OpenCode version

0.15.30

Steps to reproduce

  1. sudo install -m 755 -d /etc/opencode
  2. opencode auth login
  3. OPENCODE_CONFIG_DIR=/etc/opencode opencode

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Originally created by @arlt on GitHub (Oct 31, 2025). Originally assigned to: @rekram1-node on GitHub. ### Description We use `OPENCODE_CONFIG_DIR=/etc/opencode` which is only world readable. Each user has his own `~/.config/opencode/` directory. Here we can see the `package.json` which is gets generated and used by opencode. Since 0.15.30 we have the following error when we start `opencode`: ``` Error: Unexpected error, check log file at /home/opencode/.local/share/opencode/log/2025-10-31T140216.log for more details EACCES: permission denied, open '/etc/opencode/package.json' path: "/etc/opencode/package.json", syscall: "open", errno: -13, code: "EACCES" at write (unknown:1:1) at installDependencies (src/config/config.ts:164:17) at processTicksAndRejections (unknown:7:39) ``` Former versions work fine. Fresh setup creates the `~/.config/opencode/package.json` and opencode starts. 0.15.30 throws this error. ### OpenCode version 0.15.30 ### Steps to reproduce 1. sudo install -m 755 -d /etc/opencode 2. opencode auth login 3. OPENCODE_CONFIG_DIR=/etc/opencode opencode ### Screenshot and/or share link _No response_ ### Operating System _No response_ ### Terminal _No response_
yindo added the bug label 2026-02-16 17:35:24 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Oct 31, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #3410: This feature request specifically discusses global configuration support in /etc/opencode and mentions configuration data should be searchable in both /etc/opencode and ~/.config/opencode/. Your use case aligns closely with what was requested in that issue.
  • #3432: Discusses custom config path support via OPENCODE_CONFIG environment variable, which is related to your OPENCODE_CONFIG_DIR usage.

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Oct 31, 2025): This issue might be a duplicate of existing issues. Please check: - #3410: This feature request specifically discusses global configuration support in `/etc/opencode` and mentions configuration data should be searchable in both `/etc/opencode` and `~/.config/opencode/`. Your use case aligns closely with what was requested in that issue. - #3432: Discusses custom config path support via `OPENCODE_CONFIG` environment variable, which is related to your `OPENCODE_CONFIG_DIR` usage. Feel free to ignore if none of these address your specific case.
Author
Owner

@rekram1-node commented on GitHub (Oct 31, 2025):

hm ill take a look

@rekram1-node commented on GitHub (Oct 31, 2025): hm ill take a look
Author
Owner

@qwertologe commented on GitHub (Nov 8, 2025):

@rekram1-node I used Qwen 3 for analysis (i hope this helps) - result:

Root Cause

The issue is in the installDependencies function in packages/opencode/src/config/config.ts at line 150 - link:

if (!(await Bun.file(pkg).exists())) {  
  await Bun.write(pkg, "{}")  // This fails for read-only directories  
}  

When OpenCode loads a custom config directory via OPENCODE_CONFIG_DIR, it attempts to create a package.json file in that directory. If the directory is read-only (like /etc/opencode with 755 permissions), this write operation fails.

Relevant Commit

Concurrent Dependency Installation (commit c1ada302): Changed installDependencies calls to run concurrently using Promise.all for performance improvements

Solution

The installDependencies function should check directory write permissions before attempting to create files, or should handle permission errors gracefully when working with user-specified config directories.


maybe?!:

+    // Check if we have write permissions to the directory
+    try {
+      await fs.access(dir, fs.constants.W_OK)
+    } catch {
+      // If we don't have write permissions, skip installing dependencies
+      log.debug("skipping dependency installation due to lack of write permissions", { path: dir })
+      return
+    }
@qwertologe commented on GitHub (Nov 8, 2025): @rekram1-node I used Qwen 3 for analysis (i hope this helps) - result: ## Root Cause The issue is in the `installDependencies` function in `packages/opencode/src/config/config.ts` at line 150 - [link](https://github.com/sst/opencode/blob/dev/packages/opencode/src/config/config.ts#L150): ```typescript if (!(await Bun.file(pkg).exists())) { await Bun.write(pkg, "{}") // This fails for read-only directories } ``` When OpenCode loads a custom config directory via `OPENCODE_CONFIG_DIR`, it attempts to create a `package.json` file in that directory. If the directory is read-only (like `/etc/opencode` with 755 permissions), this write operation fails. ## Relevant Commit **Concurrent Dependency Installation** (commit c1ada302): Changed `installDependencies` calls to run concurrently using `Promise.all` for performance improvements ## Solution The `installDependencies` function should check directory write permissions before attempting to create files, or should handle permission errors gracefully when working with user-specified config directories. --- maybe?!: ``` + // Check if we have write permissions to the directory + try { + await fs.access(dir, fs.constants.W_OK) + } catch { + // If we don't have write permissions, skip installing dependencies + log.debug("skipping dependency installation due to lack of write permissions", { path: dir }) + return + } ```
Author
Owner

@rekram1-node commented on GitHub (Nov 8, 2025):

Yeah that looks fine, if u want u can open a pr and ill merge it since u found the issue, otherwise i can knock it out. Lmk ur preference @qwertologe

@rekram1-node commented on GitHub (Nov 8, 2025): Yeah that looks fine, if u want u can open a pr and ill merge it since u found the issue, otherwise i can knock it out. Lmk ur preference @qwertologe
Author
Owner

@qwertologe commented on GitHub (Nov 8, 2025):

@rekram1-node I really don't know if this is a good solution - maybe it would be better to fallback to project folder, ...

I would really be glad if you can take over from here.

@qwertologe commented on GitHub (Nov 8, 2025): @rekram1-node I really don't know if this is a good solution - maybe it would be better to fallback to project folder, ... I would really be glad if you can take over from here.
Author
Owner

@rekram1-node commented on GitHub (Nov 8, 2025):

sure will do thx @qwertologe just wanted to give u a chance to get the "credit" haha

@rekram1-node commented on GitHub (Nov 8, 2025): sure will do thx @qwertologe just wanted to give u a chance to get the "credit" haha
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2384