`claude --worktree <name>` against a stale worktree registration silently destroys state

Resolved 💬 6 comments Opened Apr 11, 2026 by apshoemaker Closed May 24, 2026

Summary

Attempting to enter an existing worktree with claude --worktree <name>
fails confusingly when git has a stale worktree registration (the registered
directory no longer exists, or points somewhere unreachable from the current
environment). The error message suggests Claude is trying to create the
worktree rather than attach to it, and after exit the worktree registration
appears to have been removed as a side effect of the failed entry.

Stale registrations can arise in a number of ways: the worktree directory
was manually removed, the repo was moved, the registered path lives on a
filesystem the current shell can't see (e.g. a devcontainer path when
you're now on the host), etc. The common case is: git still knows about
the name, but the directory isn't there.

Steps to reproduce

  1. Have a git worktree registered under a given name whose directory is

no longer present at the registered path. (git worktree list will
show it as prunable.)

  1. Run claude --worktree <name>.

Actual behavior

Claude exits with an error of the form:

Error creating worktree: Failed to create worktree: fatal:
'<name>' is already used by worktree at '<stale path>'

After exit, the worktree registration appears to have been removed, and
the user is left believing any state associated with that worktree is
lost. Because the error path is destructive, there is no opportunity to
recover or inspect what was there.

Expected behavior

  • --worktree <name> should be an "enter existing" operation, not a

"create" operation that collides on the name. The "Error creating
worktree" message suggests the CLI is unconditionally trying to create.

  • A failed entry should be a no-op. Nothing should be deleted, pruned,

or otherwise modified as a side effect of an error path.

  • When a stale registration is detected, Claude should surface it

explicitly and let the user choose: prune and recreate (with a clear
warning that anything at the old path is gone), attach to the existing
branch in a fresh working directory, or abort without changes.

Environment

  • Claude Code CLI 2.1.101
  • macOS (Darwin 25.4.0)

View original on GitHub ↗

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