[BUG] Bash tool on Windows halves runs of backslashes, even inside single quotes and quoted heredocs
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report
- [x] I am using the latest version of Claude Code
What's Wrong?
On Windows (Git Bash), the Bash tool halves every run of backslashes in the command before bash receives it. This happens even inside single quotes and inside a quoted heredoc (<<'EOF'), where bash itself never touches backslashes. The session transcript records the tool input with the original count, so the model sent the right bytes and the reduction happens between the tool input and the shell.
The Write tool is not affected: the same content written with Write keeps every backslash.
Effects seen in practice:
node -escripts break: a regex such as/\\/greaches node as/\/gand fails withSyntaxError.- A quoted heredoc that writes a script file loses backslashes in the file (Windows paths, regexes).
- Verification commands silently lie:
grep -c 'a\\\\b' filesearches for a different pattern than the one written, so a byte check can report 0 or a false match.
What Should Happen?
The command string should reach bash byte-for-byte as the tool input records it. Inside single quotes and quoted heredocs, \\ should stay two backslashes, as it does when the same command is run in Git Bash directly.
Error Messages/Logs
Bash tool command (as recorded in the session transcript):
printf '%s\n' 'two:a\\b' 'four:a\\\\b' | od -c
Output:
0000000 t w o : a \ b \n f o u r : a \ \
0000020 b \n
Expected od output: a \ \ b for the first line and four backslashes for the second.
Steps to Reproduce
- On Windows with Git Bash as the shell, start Claude Code (interactive or
claude -p). - Ask it to run exactly:
printf '%s\n' 'two:a\\b' 'four:a\\\\b' | od -c - Check the transcript JSONL: the recorded
tool_use.input.commandholds 2 and 4 backslashes. - Check the output: bash received 1 and 2.
- Same with a heredoc:
````
cat > t.txt <<'EOF'
two:a\\b
EOF
od -c t.txt
The file holds one backslash.
- For comparison, write
two:a\\bwith the Write tool andod -cit: two backslashes, as expected.
Reproduced in an interactive session and in a fresh claude -p session.
Claude Model
Opus
Is this a regression?
I don't know
Claude Code Version
2.1.286 (Claude Code)
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Git Bash
Additional Information
- OS: Windows 11 Pro 10.0.26200; model
claude-opus-5-5. - A single backslash is preserved (
a\bstaysa\b); only runs of two or more are halved (2 → 1, 4 → 2). - Workaround: write scripts with the Write tool and run the file; check written bytes with Read rather than a shell pattern that contains backslashes.
- Not checked on macOS or Linux.