fix(config): load project config from worktree root in linked worktrees#15936
Open
zerone0x wants to merge 1 commit intoanomalyco:devfrom
Open
fix(config): load project config from worktree root in linked worktrees#15936zerone0x wants to merge 1 commit intoanomalyco:devfrom
zerone0x wants to merge 1 commit intoanomalyco:devfrom
Conversation
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>
Contributor
|
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #15911
Type of change
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()andConfigPaths.directories()both walk upward fromInstance.directorytowardInstance.worktree, but since the two paths share no common ancestor below/, the traversal never visits the worktree root — so.opencode/opencode.jsonthere 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.tscovering 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