--worktree flag silently fails on jj (Jujutsu) colocated repos (detached HEAD)

Resolved 💬 8 comments Opened Feb 21, 2026 by tom-pang Closed Apr 5, 2026

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

  1. Have a jj colocated repo (.jj/ alongside .git/)
  2. Run claude -w my-test
  3. 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
  • --worktree flag 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.

View original on GitHub ↗

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