Skip to content

Per-repo .opencode/opencode.json not loaded in linked worktrees (sandboxes) #15911

Description

@athal7

Summary

When OpenCode creates a sandbox (linked worktree) under ~/.local/share/opencode/worktree/<hash>/<name>/, per-repo configuration from .opencode/opencode.json in the main repo root is not picked up — even though the main repo root is correctly resolved via git rev-parse --git-common-dir.

Steps to Reproduce

  1. Have a project at e.g. ~/code/myproject with .opencode/opencode.json containing a model override:
    { "model": "anthropic/claude-sonnet-4-6" }
  2. Ensure .opencode/opencode.json is not tracked by git — this is common for shared repos where teammates may not use OpenCode, so you don't want to commit personal tool config
  3. Create a new sandbox/worktree from within OpenCode
  4. The worktree is created at ~/.local/share/opencode/worktree/<hash>/<name>/
  5. The model override from .opencode/opencode.json is not applied in the sandbox session — it falls back to the global config

Root Cause

config.ts uses Filesystem.findUp() to search for .opencode/opencode.json, walking from Instance.directory (the worktree path) up to Instance.worktree (the main repo root resolved from git rev-parse --git-common-dir).

The problem is that for linked worktrees, the filesystem paths are on completely different branches of the directory tree:

  • Instance.directory = ~/.local/share/opencode/worktree/<hash>/<name>/
  • Instance.worktree = ~/code/myproject/ (resolved from git-common-dir)

findUp walks up the directory tree from Instance.directory:

~/.local/share/opencode/worktree/<hash>/<name>/  ← start (no .opencode/)
~/.local/share/opencode/worktree/<hash>/          ← no .opencode/
~/.local/share/opencode/worktree/                 ← no .opencode/
~/.local/share/opencode/                          ← no .opencode/
~/.local/share/                                   ← no .opencode/
...

It never visits ~/code/myproject/ because that directory is not a filesystem ancestor of the worktree path. The stop boundary (Instance.worktree) is never reached by walking up, so the loop terminates at the filesystem root without finding the config.

Additionally, since .opencode/opencode.json is gitignored, it's not in the git index and git worktree add + git reset --hard won't check it out into the worktree.

Expected Behavior

OpenCode should load .opencode/opencode.json from the main repo root (Instance.worktree) when running inside a linked worktree, even when the worktree is on a different filesystem path.

Workaround

Set a commands.start script on the project (via Edit Project → "Workspace startup script") to symlink .opencode from the main repo into new worktrees:

if [ -d "$(git rev-parse --git-common-dir 2>/dev/null)/../.opencode" ]; then
  ln -sfn "$(cd "$(git rev-parse --git-common-dir)/.." && pwd)/.opencode" .opencode
fi

Environment

  • OpenCode v1.2.16
  • macOS (arm64)
  • Git worktrees created by OpenCode's sandbox feature

Activity

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