[BUG] Unnecessary "cd" prepended to Bash commands on Windows due to path format mismatch

Status Fixed / completed
Reported on v2.1.63
Maintainer reply ✓ Yes — claude[bot]
Activity 11 comments · opened Mar 3, 2026 · closed May 18, 2026
💡 Likely answer: A maintainer (claude[bot], contributor) responded on this thread — see the highlighted reply below.

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)

View original on GitHub ↗

11 Comments

github-actions[bot] · 5 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/30111
  2. https://github.com/anthropics/claude-code/issues/28240
  3. https://github.com/anthropics/claude-code/issues/28003

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

Narretz · 5 months ago

You know that AI is overhyped when software still has path issues on Windows.

TheMythologist · 5 months ago

Anyone know how to get Claude to stop this unnecessary behaviour?

enricoros · 5 months ago

@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.

lucaspimentel · 5 months ago
I tried with explicit instructions in CLAUDE.md but I can get to a 50% reduction at best.

Same. I tried variations of this:

Don't use `cd <path> && <command>` or `git -C <path> <command>` when the current directory already matches the target path. In Git Bash on Windows, the following paths all resolve to the same location. Don't try to `cd` between them.
- D:\my-repo
- D:/my-repo
- /d/my-repo

Currently I am using a hook that blocks such commands when detected and feeds these instructions to the agent.

edit: here's the hook

enricoros · 5 months ago

@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 :)

Ethorsen · 5 months ago

Very annoying issue that started about 2 weeks ago. Hopefully fixed very soon

yurukusa · 5 months ago

Same root cause as #28240 — Claude prepends cd to commands, and the permission system matches the cd instead of the actual command.

Workaround — PreToolUse hook to auto-approve cd-prefixed commands:

#!/bin/bash
CMD=$(cat | jq -r '.tool_input.command // empty')
if echo "$CMD" | grep -qE '^\s*cd\s+' && ! echo "$CMD" | grep -qE 'rm\s+-rf|git\s+push\s+--force|git\s+reset\s+--hard'; then
    echo '{"decision":"approve"}'
    exit 0
fi
exit 0

npx cc-safe-setup includes a cd-git-allow hook that handles this pattern while still blocking dangerous commands in the chain.

thedavidyoungblood · 4 months ago

Sharing a short write-up in case it is useful:

[!tip] explores using PreToolUse hook function(s) as interim mitigation for ISSUE: #3024 (and related).

LINK-TO-GIST

[!NOTE] It includes: - an expanded issue-commentary - a PR-description draft - a narrow local workaround sketch for rewriting redundant cwd-equivalent cd <path> && ... wrappers rather than broadly auto-approving them The examples are intentionally incomplete and should be reviewed before use. They are meant as discussion material and local testing notes, not as authoritative guidance. If any of it is helpful, feel free to ignore the parts that are not.
claude[bot] contributor · 3 months ago

This issue was fixed as of version 2.1.71.

github-actions[bot] · 1 month ago

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.