@devries-cameron20 / t3code-1 / commits / d6ecf15805
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Fix worktree→local branch switch causing 'already used by worktree' error

When in a secondary worktree and selecting a branch checked out in the main worktree (e.g. main), the code skipped the worktree redirect (because worktreePath === project.cwd) and tried git checkout, which git rejected. Now any branch with a worktreePath is handled as a redirect — main worktree redirects to local (worktreePath=null), secondary worktrees redirect to their path. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Julius Marminge committed Feb 11, 2026 at 15:36 UTC d6ecf1580510cd7f156dbe831c68f357fe162210
1 file changed +7 -6
apps/web/src/components/BranchToolbar.tsx
+7 -6
@@ -128,13 +128,14 @@ export default function BranchToolbar({ envMode, onEnvModeChange, envLocked }: B
128 return;
129 }
130
131 - // If the branch already lives in a secondary worktree, point the thread
132 - // there instead of trying to checkout (which git would reject).
133 - // Ignore the main worktree (project cwd) — that's just a normal local checkout.
134 - const isSecondaryWorktree = branch.worktreePath && branch.worktreePath !== activeProject?.cwd;
135 - if (isSecondaryWorktree) {
131 + // If the branch already lives in a worktree, redirect there instead of
132 + // trying to checkout (which git would reject with "already used by worktree").
133 + if (branch.worktreePath) {
134 + const isMainWorktree = branch.worktreePath === activeProject?.cwd;
135 setThreadError(null);
137 - setThreadBranch(branch.name, branch.worktreePath);
136 + // Main worktree → switch back to local (project cwd, worktreePath=null).
137 + // Secondary worktree → point the thread at that worktree path.
138 + setThreadBranch(branch.name, isMainWorktree ? null : branch.worktreePath);
139 setIsBranchMenuOpen(false);
140 return;
141 }