[BUG] --worktree flag fails with EEXIST on second worktree creation (Windows)
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?
When using claude --worktree <name> on Windows, the first worktree is created successfully, but every subsequent call fails with:
Error creating worktree: EEXIST: file already exists, mkdir 'C:\users\lucho\desktop\SISTEMASDATIX\.claude\worktrees'
The error is on the parent directory .claude\worktrees, not on the new worktree itself. The parent already exists from the first worktree creation, and the code tries to create it again without checking.
What Should Happen?
Each claude --worktree <name> call should create only the new subdirectory .claude\worktrees\<name>, without trying to recreate the parent .claude\worktrees every time. The fix would be using mkdir with { recursive: true } or checking if the directory already exists first.
Error Messages/Logs
Error creating worktree: EEXIST: file already exists, mkdir
'C:\users<user><project>.claude\worktrees'
The error is on the **parent directory** `.claude\worktrees`, not on the new
worktree itself. The parent already exists from the first worktree creation, and
the code tries to create it again without checking.
Steps to Reproduce
- Open a project with a git repo
- Run
claude --worktree first-task→ ✅ works - Run
claude --worktree second-task→ ❌ EEXIST error
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.186 (Claude Code)
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Warp
Additional Information
The --worktree implementation calls mkdir('.claude/worktrees') unconditionally
instead of mkdir('.claude/worktrees', { recursive: true }) or checking if the
directory already exists first. On Windows, mkdir throws EEXIST on existing
directories instead of silently succeeding (unlike POSIX).
Related to other EEXIST/Windows issues: #37306, #31030, #55427
Environment
- Claude Code version: 2.1.186
- OS: Windows 11
- Terminal: Warp
- Shell: PowerShell