[BUG] EnterWorktree regression: errors when worktree already exists instead of attaching (regression of #45024)

Resolved 💬 4 comments Opened May 19, 2026 by shawnbissell Closed Jun 25, 2026

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

  1. From any Claude Code surface (CLI in my case), call EnterWorktree for a new branch — e.g. my-feature-branch. Worktree gets created at .claude/worktrees/my-feature-branch, session cwd switches into it. Good.
  2. Make some edits in the worktree. Don't commit. Exit that Claude Code session.
  3. 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 — main for me), not the worktree.
  4. Invoke EnterWorktree my-feature-branch to re-attach.
  5. 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.
  6. Expected (per #45024): session's cwd switches to .claude/worktrees/my-feature-branch. git status thereafter 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)

  1. Add the worktree path as its own Claude Code project. Works, but bypasses worktree-awareness and now Project Picker has a confusing duplicate entry.
  2. ExitWorktree (or git worktree remove) → recreate. Risks destroying uncommitted work.
  3. 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."

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗