[BUG] Bash tool on Windows halves runs of backslashes, even inside single quotes and quoted heredocs

Status Open
Reported on v2.1.286
Maintainer reply None cached
Activity 0 comments · opened Oct 1, 2026

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 -e scripts break: a regex such as /\\/g reaches node as /\/g and fails with SyntaxError.
  • A quoted heredoc that writes a script file loses backslashes in the file (Windows paths, regexes).
  • Verification commands silently lie: grep -c 'a\\\\b' file searches 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

  1. On Windows with Git Bash as the shell, start Claude Code (interactive or claude -p).
  2. Ask it to run exactly: printf '%s\n' 'two:a\\b' 'four:a\\\\b' | od -c
  3. Check the transcript JSONL: the recorded tool_use.input.command holds 2 and 4 backslashes.
  4. Check the output: bash received 1 and 2.
  5. Same with a heredoc:

``
cat > t.txt <<'EOF'
two:a\\b
EOF
od -c t.txt
``
The file holds one backslash.

  1. For comparison, write two:a\\b with the Write tool and od -c it: 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\b stays a\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.

View original on GitHub ↗