[BUG] EnterWorktree regression: errors when worktree already exists instead of attaching (regression of #45024)
Summary
EnterWorktree fails with fatal: '<branch>' is already used by worktree at '<path>' when a worktree+branch for the requested name already exists on disk. Per #45024 (closed COMPLETED 2026-04-08), the tool is supposed to detect that case and switch the session's cwd into the existing worktree. That behavior has regressed.
This breaks a very common multi-surface workflow: do work in a worktree from Claude Code CLI, then try to open the same worktree from Claude Code Desktop to view the diff in the desktop diff viewer. The desktop session lands in the main repo cwd, EnterWorktree is the documented way to re-attach, and it errors out.
Exact error
Failed to switch to "my-feature-branch" in /path/to/repo:
/opt/homebrew/bin/git exited with code 128:
fatal: 'my-feature-branch' is already used by worktree at
'/path/to/repo/.claude/worktrees/my-feature-branch'
Git is correct to refuse — you can't check out the same branch twice. The bug is that EnterWorktree is invoking git switch (a create/checkout path) instead of detecting the existing worktree at the expected .claude/worktrees/<name> path and just changing the session's cwd to it.
Reproduction
- From any Claude Code surface (CLI in my case), call
EnterWorktreefor a new branch — e.g.my-feature-branch. Worktree gets created at.claude/worktrees/my-feature-branch, session cwd switches into it. Good. - Make some edits in the worktree. Don't commit. Exit that Claude Code session.
- Open the same repo in a different Claude Code surface (Desktop, in my case). The new session's cwd is the main repo root (on whatever branch was checked out there —
mainfor me), not the worktree. - Invoke
EnterWorktree my-feature-branchto re-attach. - Actual: the error above. Session stays in the main repo. No way to view the worktree's uncommitted diff in Desktop's diff viewer without manually opening the worktree path as a separate Claude Code project.
- Expected (per #45024): session's cwd switches to
.claude/worktrees/my-feature-branch.git statusthereafter shows the in-progress diff. No git mutation needed — the worktree is already at the right state.
Why this matters
The whole point of #45024's fix was that worktrees outlive sessions. CLI → Desktop handoff, accidental session exits, picking up tomorrow what you started today — none of these should require ExitWorktree + commit-or-stash + recreate gymnastics. Especially when the alternative path (open the worktree dir as its own Claude Code project) bypasses worktree-awareness entirely and confuses the project picker.
Environment
- Claude Code: 2.1.144 (Desktop; also reproduces on CLI on the same machine)
- macOS 26.3.1 (arm64)
- git: 2.54.0 (Homebrew,
/opt/homebrew/bin/git)
Secondary / related observation
Before installing Homebrew git I was on Apple's /usr/bin/git 2.39.5. The same EnterWorktree call failed earlier in the pipeline with a different error:
/usr/bin/git exited with code 1:
error: pathspec '--end-of-options' did not match any file(s) known to git
error: pathspec 'my-feature-branch' did not match any file(s) known to git
Looks like flag-ordering with --end-of-options is incompatible with older git. git 2.24+ documents the option, but the way it's positioned in the EnterWorktree invocation seems to be misparsed by 2.39.5. Newer git accepts it fine. Worth either pinning a minimum git version or putting --end-of-options strictly after the subcommand and before positional args. Filing this separately if it's a distinct issue.
Workarounds users will land on (none of them good)
- Add the worktree path as its own Claude Code project. Works, but bypasses worktree-awareness and now Project Picker has a confusing duplicate entry.
ExitWorktree(orgit worktree remove) → recreate. Risks destroying uncommitted work.- Commit + push + tear down + re-EnterWorktree. Works but is busywork users shouldn't have to perform every time they switch surfaces.
Reference
Regression of #45024 — that issue's stated fix description matches the missing behavior exactly: "If a worktree with the given name/branch already exists, switch into it rather than erroring."
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗