-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Description
Summary
When OpenCode is opened from a git worktree, it looks for the .git/opencode cache file in the per-worktree git directory (.git/worktrees/<name>/opencode) rather than the common git directory (.git/opencode). This causes each worktree to compute a potentially different project ID, resulting in separate project records and empty session lists.
Steps to Reproduce
- Have a repo with a cached project ID in
.git/opencode - Create a git worktree:
git worktree add ../my-worktree feature-branch - Open OpenCode from the worktree directory
- Open the session list — it shows "No results found"
Root Cause
In src/project/project.ts, the fromDirectory() function resolves the .git path and looks for an opencode file there. For worktrees, .git is a file (not a directory) pointing to .git/worktrees/<name>/, so the cache lookup goes to .git/worktrees/<name>/opencode instead of the main .git/opencode.
Since the per-worktree cache doesn't exist, OpenCode falls back to git rev-list --max-parents=0 --all. This command can return different results depending on stash state (e.g., git stash -u creates orphan root commits), leading to a different project ID being computed and cached per-worktree.
Expected Behavior
All worktrees of the same repository should resolve to the same project ID and share sessions. The cache file should be read from and written to the common git directory (obtainable via git rev-parse --git-common-dir), not the per-worktree git directory.
Workaround
Manually create the cache file in each worktree's git directory:
echo "<project-id>" > .git/worktrees/<worktree-name>/opencodeThis must be repeated for every new worktree.
Suggested Fix
In fromDirectory(), use git rev-parse --git-common-dir (which is already being called later in the function) to determine where to read/write the opencode cache file, instead of using the dotgit path which varies per worktree.