claude-code - 💡(How to fix) Fix [BUG] --worktree <name> silently falls back to parent repo cwd when worktree name already exists [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#56225Fetched 2026-05-06 06:33:49
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Timeline (top)
labeled ×4commented ×1

Error Message

Error: worktree 'bugfix-blocker' already exists at <path>. cd into it and run claude, or choose a different name.

Code Example

Error: worktree 'bugfix-blocker' already exists at <path>.
    cd into it and run `claude`, or choose a different name.

---



---

cd /path/to/repo
     claude --worktree bugfix-blocker

---

pwd                       # → /path/to/repo (parent, NOT the worktree)
     git branch --show-current # → test         (parent's branch)
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

claude -w/--worktree <name> is documented as "Create a new git worktree for this session". When the requested name collides with an existing worktree at .claude/worktrees/<name>/, the flag neither attaches to it nor errors visibly — the session silently starts bound to the parent repo's cwd (and parent's checked-out branch). Any edits land on the parent branch, giving the impression the worktree was selected when it wasn't.

What Should Happen?

One of:

  • Attach to the existing worktree of that name and chdir into it, or
  • Fail loudly with a message like:
    Error: worktree 'bugfix-blocker' already exists at <path>.
    cd into it and run `claude`, or choose a different name.

Error Messages/Logs

Steps to Reproduce

  1. Have a worktree at .claude/worktrees/bugfix-blocker/ (branch worktree-bugfix-blocker) — created from a previous claude --worktree bugfix-blocker session, for example.
  2. From the parent repo (on a different branch, e.g. test):
    cd /path/to/repo
    claude --worktree bugfix-blocker
  3. Inside the new session:
    pwd                       # → /path/to/repo (parent, NOT the worktree)
    git branch --show-current # → test         (parent's branch)
  4. Any file edits go to test, not worktree-bugfix-blocker.

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.128 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

iTerm2

Additional Information

No response

extent analysis

TL;DR

The issue can be fixed by modifying the claude command to either attach to the existing worktree or error out when a worktree with the same name already exists.

Guidance

  • Verify the existence of a worktree with the same name before creating a new one, and handle the case where it already exists.
  • Consider adding a check to ensure the --worktree flag is properly handled when an existing worktree is found.
  • To mitigate the issue, users can manually check if a worktree with the same name exists before running the claude command.
  • The claude command should provide a clear error message when a worktree with the same name already exists, as described in the "What Should Happen?" section.

Example

No code snippet is provided as the issue does not contain sufficient information about the implementation details of the claude command.

Notes

The issue seems to be related to the handling of existing worktrees in the claude command. Without more information about the implementation, it's difficult to provide a more specific solution.

Recommendation

Apply a workaround by manually checking for existing worktrees before running the claude command, until a proper fix is implemented to handle this case.

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