[BUG] Unnecessary "cd" prepended to Bash commands on Windows due to path format mismatch
Bug report
On Windows with Git Bash, Claude Code frequently prepends unnecessary cd <path> && to shell commands even when the shell's working directory is already correct.
Environment
- OS: Windows 11 (10.0.26200.7840)
- Shell: Git Bash (MSYS2) used internally by Claude Code
- Claude Code: 2.1.63
Observed behavior
When the working directory is e.g. D:\source\my-repo, commands are issued as:
cd D:\source\my-repo && git diff
cd D:/source/my-repo && git diff
cd /d/source/my-repo && git diff
All three path formats resolve to the same directory in Git Bash.
Expected behavior
Claude Code should recognize that the shell is already in the correct directory and omit the unnecessary cd, just as it does on macOS/Linux.
Likely cause
The working directory comparison appears to use string equality rather than canonicalizing paths across the three equivalent Windows/Git Bash formats:
D:\source\my-repo(Windows backslash)D:/source/my-repo(Windows forward slash)/d/source/my-repo(MSYS/Git Bash mount path)
On macOS/Linux this isn't an issue since paths have a single canonical form.
Impact
This causes unnecessary permission prompts. For example, even if git diff is an allowed command, the compound cd <path> && git diff triggers an approval request with the message: "Compound commands with cd and git require approval to prevent bare repository attacks". This significantly disrupts workflow on Windows.
(this github issue generated with 🤖 Claude Code)
This issue has 11 comments on GitHub. Read the full discussion on GitHub ↗