Skip to content

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

@tom-pang

Description

@tom-pang

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions