claude-code - 💡(How to fix) Fix [BUG] EnterWorktree regression: errors when worktree already exists instead of attaching (regression of #45024) [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#60624Fetched 2026-05-20 03:53:42
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
0
Timeline (top)
labeled ×5commented ×1cross-referenced ×1

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.

Error Message

/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

Root Cause

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.

Fix Action

Fix / Workaround

Workarounds users will land on (none of them good)

Code Example

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'

---

/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
RAW_BUFFERClick to expand / collapse

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."

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] EnterWorktree regression: errors when worktree already exists instead of attaching (regression of #45024) [1 comments, 2 participants]