bare-repo worktree: root detection resolves to bare repo parent instead of worktree root

Resolved 💬 3 comments Opened Feb 23, 2026 by fluffywaffles Closed Feb 27, 2026

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

  1. 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
``

  1. cd repo/path/to/wt/ && git rev-parse --show-toplevel correctly returns repo/path/to/wt/.
  1. Start Claude Code inside repo/path/to/wt/. It follows the .git gitdir file up through .bare/worktrees/wt to .bare/, then resolves the root to repo/ (the directory containing .bare/).
  1. 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.

View original on GitHub ↗

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