Claude Code silently strips backslashes in Bash tool; CLAUDE.md fix saves ~80% tokens
JoshuaJosephson · reddit · 2026-09-06
A Windows user diagnosed why Claude Code kept failing on file writes: the Bash tool strips one level of backslash escaping before the shell parses it — \\ arrives as \ — and neither single quotes nor <<'EOF' heredocs protect against it, since the collapse happens upstream of bash (isolated by byte-for-byte comparison with the PowerShell tool).
The failure is silent: commands succeed with plausible output, and corrupted "\n" characters surface much later as unrelated syntax or runtime errors.
The author shares a CLAUDE.md section that fixes it:
- Use built-in Write/Edit/Read tools for anything file-shaped; never create files via heredocs.
- Use the PowerShell tool for content that genuinely needs backslashes (Windows paths, regex, JSON payloads) — it preserves them exactly.
- For multi-line strings (commit messages, JSON payloads), write content to a file first and point the command at it.
- Last resort inside Bash: double every backslash (emit 2N to get N), verified but silent when wrong — never for file content.
Measured on 2026-09-05, this setup saves nearly 80% of tokens on those tasks.
More from coding & agent
- Agent plays Portal to the credits: 23h43m autonomous run setup open-sourced — banteg · 2026-09-07
- Having Codex summarize weekly screen recordings turns into a fun self-review — vista8 · 2026-09-07
- Claude Code team reportedly ditched GUI/TUI, now using claude tag for 70%+ of work — himanshustwts · 2026-09-07
- Microsoft open-sources tgrep, a trigram-indexed grep up to 52x faster than ripgrep — jedisct1 · 2026-09-07
- How should billing work when an AI system auto-selects the model? — Colddew-YJ · 2026-09-07
- SmolVM: open-source microVM sandbox runs OpenClaw 2.0 in isolation, boots in milliseconds — aniketmaurya · 2026-09-07