Skip to content

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

Closed

Description

@arlt

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

Activity

  1. added
    bugSomething isn't working
    on Oct 31, 2025
  2. github-actions commented on Oct 31, 2025

    @github-actions
    Contributor

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

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

  3. self-assigned this
    on Oct 31, 2025
  4. rekram1-node commented on Oct 31, 2025

    @rekram1-node
    Contributor

    hm ill take a look

  5. qwertologe commented on Nov 8, 2025

    @qwertologe

    @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 c1ada30): 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
    +    }
    
  6. rekram1-node commented on Nov 8, 2025

    @rekram1-node
    Contributor

    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

  7. qwertologe commented on Nov 8, 2025

    @qwertologe

    @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.

  8. rekram1-node commented on Nov 8, 2025

    @rekram1-node
    Contributor

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

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions