-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Description
Description
claude -w (or claude --worktree) silently fails to create a worktree when the repository has a detached HEAD, which is the default state for all jj (Jujutsu) colocated repositories.
Steps to reproduce
- Have a jj colocated repo (
.jj/alongside.git/) - Run
claude -w my-test - Claude starts but is not in a worktree - it's in the main repo
Expected behavior
Claude should create a git worktree and start the session inside it.
Root cause
jj colocated repos always present as detached HEAD to git. git worktree add requires the -b <branch> flag when HEAD is detached (to create a new branch for the worktree). Without -b, git worktree add fails.
Manual workaround that works:
git worktree add /tmp/test-worktree -b test-branch
# succeeds on detached HEAD
So the fix is likely to pass -b <generated-branch-name> to git worktree add when HEAD is detached.
Environment
- Claude Code v2.1.50
- macOS (Darwin 24.6.0)
- jj 0.x colocated with git
--worktreeflag introduced in 2.1.49
Notes
jj is growing in popularity and all colocated jj repos have this issue. The failure is silent - no error message, Claude just starts in the main repo instead of a worktree.