opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix: desktop app worktree collision - use separate ID per worktree

Open Eric162 opened this issue 1 month ago • 0 comments

Fixes #5638

Problem

Opening multiple git worktrees from the same repository in the desktop app causes the second worktree to replace the first one's project data. This happens because project IDs were derived from the root commit hash only, which is identical across all worktrees.

Solution

  • Main worktree: Uses root commit as project ID (backwards compatible)
  • Linked worktrees: Uses rootCommit|worktreeHash format for unique IDs
  • Stores worktree hash in separate .git/opencode-worktree file for linked worktrees
    • without this, it can be quite jarring to upgrade versions, as all of the previous conversations disappear. ideally, there'd only be the original .git/opencode but then there's a bad upgrade experience.
  • Migrates sessions from old format to new when upgrading
  • Disables git fsmonitor in snapshot repos to prevent hangs with linked worktrees

Testing

  • All existing tests pass
  • Added new test to verify different ID formats for main vs linked worktrees
  • Verified backwards compatibility: old opencode can still access main worktree sessions

Eric162 avatar Dec 16 '25 20:12 Eric162