claude -w (worktree mode) doesn't work correctly when invoked from a git submodule

Resolved 💬 5 comments Opened Feb 20, 2026 by gsim-inbolt Closed Apr 1, 2026

Description

When running claude -w from inside a git submodule, the worktree is created for the parent repository instead of the submodule. The submodule directory in the resulting worktree is empty and not initialized, making the worktree useless for the intended purpose.

Steps to Reproduce

  1. Have a repo with a git submodule (e.g., a project with a libjpeg-turbo submodule)
  2. cd into the submodule directory
  3. Run claude -w

Expected Behavior

The worktree should be created for the submodule's git repository, since that's the repo the user is currently working in.

Actual Behavior

  • The worktree is created for the parent repository under <parent-repo>/.claude/worktrees/<name>/
  • The submodule directory inside the worktree is empty (not checked out)
  • The user's working directory is set to the parent repo's worktree, not the submodule

Git Topology

From inside the submodule, git correctly identifies it as its own repo with a superproject:

$ cd my-project/my-submodule/
$ git rev-parse --show-toplevel
~/my-project/my-submodule

$ git rev-parse --show-superproject-working-tree
~/my-project

But claude -w resolves to the superproject and creates the worktree there. The submodule dir in the resulting worktree is empty:

$ ls -la <parent-repo>/.claude/worktrees/<name>/my-submodule/
total 8
drwxrwxr-x  2 user user 4096 Feb 20 15:26 .
drwxrwxr-x 12 user user 4096 Feb 20 15:26 ..

Likely Root Cause

The worktree creation logic probably uses something like git rev-parse --show-toplevel walking up to find the repo root, but doesn't account for the case where the user is inside a submodule. It should check --show-superproject-working-tree to detect this and scope the worktree to the submodule's own repo.

Environment

  • Claude Code version: 2.1.49
  • OS: Ubuntu 22.04.5 LTS
  • Kernel: 6.8.0-94-generic x86_64
  • Git version: 2.34.1
  • Node.js: v24.11.1
  • Shell: zsh

View original on GitHub ↗

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