[BUG] --worktree <name> silently falls back to parent repo cwd when worktree name already exists

Resolved 💬 2 comments Opened May 5, 2026 by batuhanduvarci Closed May 7, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] 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):

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

  1. Inside the new session:

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

  1. 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_

View original on GitHub ↗

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