Git worktree path resolution bug - paths resolve to main repo instead of worktree
Description
When running Claude Code from within a git worktree, relative file paths are incorrectly resolved to the main repository instead of the worktree directory.
Steps to Reproduce
- Create a git worktree:
git worktree add /path/to/worktree -b my-branch
- Start Claude Code from the worktree directory:
cd /path/to/worktree
claude "Edit parsers.py"
- Claude will edit
/path/to/main-repo/parsers.pyinstead of/path/to/worktree/parsers.py
Expected Behavior
Claude should resolve relative paths relative to its working directory (the worktree), using git rev-parse --show-toplevel which correctly returns the worktree path.
Actual Behavior
Claude appears to be using git rev-parse --git-common-dir (which returns the main repo's .git directory) to determine the repository root, causing all paths to resolve relative to the main repo instead of the worktree.
Workaround
Include explicit instructions in the prompt telling Claude it's in a worktree and to use paths relative to that directory.
Environment
- Claude Code version: 2.1.2
- OS: macOS (Darwin 24.1.0)
As far as I can tell currently at least (Claude 2.1.31) the issues is that tool descriptions IMHO incorrectly tell Claude to use absolute paths, and then it gets confused. I run Claude with CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1 and these instructions to use absolute paths are very counterproductive and take a lot of work to overwrite in CLAUDE.md.
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.