[BUG] Desktop app: starting a session on a branch held by a linked worktree runs `git switch` in the main repo and fails (code 128) — even when the worktree folder itself is selected

Status Open
Reported on v2.1.201
Maintainer reply None cached
Activity 0 comments · opened Aug 10, 2026

Environment

  • Platform: darwin (macOS 26.6.1, build 25G76, Darwin 25.6.0)
  • Claude Code desktop app — CLI reports 2.1.201
  • Repo uses linked worktrees under <repo>/.worktrees/<name> (created outside the app)

Summary

Starting a session with a branch that is already checked out in a linked worktree always fails: the app runs git switch <branch> in the main repository checkout, which git refuses with exit code 128:

Failed to switch to "codex/fable-organizer-profiles" in /Users/<user>/Developer/ai-os:
/usr/bin/git exited with code 128: fatal: 'codex/fable-organizer-profiles' is already
used by worktree at '/Users/<user>/Developer/ai-os/.worktrees/fable-organizer-profiles'

The critical part: this happens even when the linked worktree directory itself is selected as the session folder. The app appears to resolve the worktree's .git pointer file back to the main repository and issues the git switch there — the one place git must refuse it — instead of noticing that the selected directory already has that branch as HEAD (where no switch is needed at all).

So there is no working path in the UI to open a session on such a branch:

  • Main repo + branch selected → git switch fails (branch held by the worktree).
  • Worktree folder + branch selected → same failure, because the switch still targets the main repo.

Only workaround: select the worktree folder and leave the branch picker untouched, so no switch is attempted.

Steps to reproduce

  1. In a repo, create a linked worktree for a branch:

``
git worktree add .worktrees/my-feature my-feature
``

  1. In the desktop app, start a new session:
  • Case A: select the main repo folder, pick branch my-feature.
  • Case B: select the worktree folder .worktrees/my-feature, pick branch my-feature.
  1. Both cases fail with git exited with code 128: fatal: '<branch>' is already used by worktree at '…', and the error message names the main repo path even in case B.

Expected

  • If the selected directory already has the requested branch checked out (linked worktree), start the session there with no git switch — the branch is already HEAD.
  • If the main repo is selected and the branch lives in a linked worktree, offer to open the existing worktree (or explain the conflict) instead of failing with a raw git error.

Actual

git switch is always executed in the main repository checkout (the worktree's .git file is resolved back to the primary checkout), so any branch held by a linked worktree is impossible to start a session on via the branch picker.

Related

  • #79515 — same root cause (the app doesn't recognize existing linked worktrees for a branch), different symptom there (a duplicate worktree is created when the worktree checkbox is on). Here, with a plain branch selection, the result is a hard failure instead.

View original on GitHub ↗