Skip to content

fix(config): load project config from worktree root in linked worktrees#15936

Open
zerone0x wants to merge 1 commit intoanomalyco:devfrom
zerone0x:fix/worktree-config-linked-worktrees
Open

fix(config): load project config from worktree root in linked worktrees#15936
zerone0x wants to merge 1 commit intoanomalyco:devfrom
zerone0x:fix/worktree-config-linked-worktrees

Conversation

@zerone0x
Copy link
Contributor

@zerone0x zerone0x commented Mar 4, 2026

Issue for this PR

Closes #15911

Type of change

  • Bug fix

What does this PR do?

When OpenCode creates a sandbox (linked worktree), the working directory ends up at a path like ~/.local/share/opencode/worktree/<hash>/<name>/, while the main repo root (Instance.worktree) is at something like ~/code/myproject/. These two paths are on completely different branches of the filesystem tree.

ConfigPaths.projectFiles() and ConfigPaths.directories() both walk upward from Instance.directory toward Instance.worktree, but since the two paths share no common ancestor below /, the traversal never visits the worktree root — so .opencode/opencode.json there is silently skipped.

The fix adds an isAncestorOrEqual() helper that checks whether the worktree is actually reachable by upward traversal. When it's not, both functions now check the worktree root explicitly (at the lowest-priority slot, so anything in the linked worktree's own directory can still override).

How did you verify your code works?

Added three tests to test/config/config.test.ts covering the new linked-worktree path, as well as a regression test confirming normal (non-linked) projects are unaffected.

Screenshots / recordings

N/A — config loading, no visual output.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

When OpenCode creates a sandbox via git worktree, the working directory
(e.g. ~/.local/share/opencode/worktree/<hash>/<name>/) is on a completely
different filesystem branch from the main repo root (Instance.worktree).

ConfigPaths.projectFiles() and ConfigPaths.directories() both walk the
filesystem upward from Instance.directory toward Instance.worktree, but
this traversal never visits Instance.worktree when the two paths share no
common ancestor below the filesystem root.

Fix: detect when worktree is not a filesystem ancestor of directory and
explicitly include the worktree-root config entries (opencode.json/c and
.opencode/ directory) at the lowest-priority slot, so they can still be
overridden by any config found inside the linked worktree itself.

Fixes anomalyco#15911

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

The following comment was made by an LLM, it may be inaccurate:

The only PR that appears in these search results is the current PR itself (#15936). The related PRs that appeared are about different aspects:

No duplicate PRs found

IgorTavcar added a commit to IgorTavcar/opencode that referenced this pull request Mar 4, 2026
…es (anomalyco#15936)

Cherry-picked from upstream PR anomalyco#15936.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant