diff --git a/apps/web/src/components/BranchToolbar.tsx b/apps/web/src/components/BranchToolbar.tsx index bc14843cf4c46180b6755a2fb00ab95a4668c21f..9fd8774d0fe31c00efe0c696ed378bffc3843d6f 100644 --- a/apps/web/src/components/BranchToolbar.tsx +++ b/apps/web/src/components/BranchToolbar.tsx @@ -128,13 +128,14 @@ export default function BranchToolbar({ envMode, onEnvModeChange, envLocked }: B return; } - // If the branch already lives in a secondary worktree, point the thread - // there instead of trying to checkout (which git would reject). - // Ignore the main worktree (project cwd) — that's just a normal local checkout. - const isSecondaryWorktree = branch.worktreePath && branch.worktreePath !== activeProject?.cwd; - if (isSecondaryWorktree) { + // If the branch already lives in a worktree, redirect there instead of + // trying to checkout (which git would reject with "already used by worktree"). + if (branch.worktreePath) { + const isMainWorktree = branch.worktreePath === activeProject?.cwd; setThreadError(null); - setThreadBranch(branch.name, branch.worktreePath); + // Main worktree → switch back to local (project cwd, worktreePath=null). + // Secondary worktree → point the thread at that worktree path. + setThreadBranch(branch.name, isMainWorktree ? null : branch.worktreePath); setIsBranchMenuOpen(false); return; }