You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Branch display shows main repo branch instead of worktree branch when opening a git worktree directory #16474
When opening a git worktree directory directly in the OpenCode desktop app, the branch displayed in the UI shows the main repository's branch (e.g. dibble-dev) instead of the worktree's actual branch (e.g. i847761/PRD-manage-family).
Reproduction
Have a git repo at e.g. /Projects/my-app on branch main
Create a worktree: git worktree add /Projects/worktrees/my-app-feature feature-branch
Open the worktree directory /Projects/worktrees/my-app-feature in the OpenCode desktop app
Observe the branch indicator shows main instead of feature-branch
OpenCode appears to follow git rev-parse --git-common-dir (which returns /Projects/my-app/.git) and reads HEAD from there — getting the main repo's branch. It should instead read the worktree-specific HEAD at .git/worktrees/my-app-feature/HEAD.
Additionally, the project table in OpenCode's SQLite database (~/.local/share/opencode/opencode.db) stores the worktree column as the main repo path rather than the actual worktree directory, even when the worktree directory is opened directly.
Running git rev-parse --abbrev-ref HEAD from each directory confirms:
/Projects/my-app → main
/Projects/worktrees/my-app-feature → feature-branch
Suggested Fix
Use git rev-parse --abbrev-ref HEAD executed from the actual working directory (or session directory) rather than resolving through --git-common-dir. The project.worktree column should also be set to the worktree directory when one is opened directly.
Environment
OpenCode desktop app (macOS)
Git worktrees created via git worktree add
Reacted by Nate Williams, Dimitris Vichos and CedarFox
After patching the project.worktree column in the database and restarting, the correct worktree branch does appear briefly on startup, but then reverts back to the main repo branch mid-session (during agent thinking/processing).
This suggests there is a background git polling or project refresh cycle that re-derives the branch by following --git-common-dir rather than staying scoped to the worktree's working directory. The initial resolution is correct, but it gets overwritten by a subsequent refresh.
Activity
ke7in-zz commentedon Mar 7, 2026
Additional Detail
After patching the
project.worktreecolumn in the database and restarting, the correct worktree branch does appear briefly on startup, but then reverts back to the main repo branch mid-session (during agent thinking/processing).This suggests there is a background git polling or project refresh cycle that re-derives the branch by following
--git-common-dirrather than staying scoped to the worktree's working directory. The initial resolution is correct, but it gets overwritten by a subsequent refresh.natewill commentedon Mar 7, 2026
will work on
natewill commentedon Mar 8, 2026
PR coming in the morning
github-actions commentedon Jul 3, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.