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
- SurfSense: an open-source local NotebookLM with MCP agents and a prompt-caching lesson — FurtiveMirth · 2026-10-23
- procedural-memory: let agents replay saved tool-call sequences instead of re-solving tasks — Sad-Response1560 · 2026-10-23
- Med student seeking whole-library book search: Cognee's graph memory beats plain RAG so far — shrike293103 · 2026-10-23
- Dev demos AI models handling 3D objects and animations surprisingly well — chongdashu · 2026-10-23
- Jason Kneen burns 104.56B tokens and $24.7K in 304 days of AI coding on Codex and Claude Code — jasonkneen · 2026-10-23
- Typosquatted Blender MCP Repo Hit 958 Stars in Days and Silently Ran Malware — Promptmethus · 2026-10-23