bare-repo worktree: root detection resolves to bare repo parent instead of worktree root
Bug
In a bare-repo multi-worktree setup, Claude Code resolves the project root to the directory containing .bare/ instead of using the worktree root returned by git rev-parse --show-toplevel.
Repro
- Set up a bare repo with worktrees:
````
repo/.bare/ # bare repo
repo/.git # file: gitdir: .bare
repo/path/to/wt/ # worktree checkout
repo/path/to/wt/.git # file: gitdir: ../../.bare/worktrees/wt
cd repo/path/to/wt/ && git rev-parse --show-toplevelcorrectly returnsrepo/path/to/wt/.
- Start Claude Code inside
repo/path/to/wt/. It follows the.gitgitdir file up through.bare/worktrees/wtto.bare/, then resolves the root torepo/(the directory containing.bare/).
- Claude Code then tries to read files from
repo/— which is not the project root and may not even contain source files.
Expected behavior
Claude Code should use git rev-parse --show-toplevel (or equivalent logic) to determine the project root. In a worktree, this correctly returns the worktree directory, not the bare repo's parent.
Workaround
Adding a CLAUDE.md at the worktree root with explicit boundary instructions partially mitigates this, but the root detection itself should be fixed.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗