[PR #5647] fix: desktop app worktree collision - use separate ID per worktree #11511

Open
opened 2026-02-16 18:16:21 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/5647

State: open
Merged: No


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
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/5647 **State:** open **Merged:** No --- 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
yindo added the pull-request label 2026-02-16 18:16:21 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11511