claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

Git worktree path resolution bug - paths resolve to main repo instead of worktree

Open damianpolan opened this issue 10 months ago • 1 comments

damianpolan avatar Jan 13 '26 13:01 damianpolan

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

  1. Create a git worktree:
git worktree add /path/to/worktree -b my-branch
  1. Start Claude Code from the worktree directory:
cd /path/to/worktree
claude "Edit parsers.py"
  1. Claude will edit /path/to/main-repo/parsers.py instead 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)

damianpolan avatar Jan 13 '26 13:01 damianpolan

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.

ANogin avatar Feb 04 '26 04:02 ANogin

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

github-actions[bot] avatar Mar 05 '26 22:03 github-actions[bot]

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.

github-actions[bot] avatar Mar 14 '26 14:03 github-actions[bot]