[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)
11 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
You know that AI is overhyped when software still has path issues on Windows.
Anyone know how to get Claude to stop this unnecessary behaviour?
@TheMythologist I tried with explicit instructions in CLAUDE.md but I can get to a 50% reduction at best. Which means any long operation will block a dozen times.
Agree with @lucaspimentel that the source seems some mismatch in path detection, at least on windows an under git-bash. Used to work - no more. The /c/path/to/my/repo is not correctly stated somewhere in the context window, and compound
cd && ...commands keep being issues, with constant breaks.Same. I tried variations of this:
Currently I am using a hook that blocks such commands when detected and feeds these instructions to the agent.
edit: here's the hook
@lucaspimentel Very smart, love it. I think I'll bisect a version before the changes, so we can isolate the issue. This bug is hurting productivity more than anything else - nothing runs smoothly anymore, it's very severe. If I do I'll report back (I don't want to try out the C word competitor :)
Very annoying issue that started about 2 weeks ago. Hopefully fixed very soon
Same root cause as #28240 — Claude prepends
cdto commands, and the permission system matches thecdinstead of the actual command.Workaround — PreToolUse hook to auto-approve cd-prefixed commands:
npx cc-safe-setupincludes acd-git-allowhook that handles this pattern while still blocking dangerous commands in the chain.Sharing a short write-up in case it is useful:
LINK-TO-GIST
This issue was fixed as of version 2.1.71.
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.