Write/Edit tool fails with special characters in file content on Windows
Resolved 💬 2 comments Opened May 30, 2026 by lwjlume Closed Jun 2, 2026
Bug Description
On Windows 10, the Write and Edit tools frequently fail with "Error writing file" / "Error editing file" when the file content contains special characters such as single quotes, backslashes, or XML-like sequences (e.g. </).
The model ends up retrying multiple times and eventually falls back to bash -c python -c "..." as a workaround.
Steps to Reproduce
- Ask Claude Code to write a Python script containing single quotes or backslashes in string literals
- Observe repeated failures even after retries
- Model is forced to use Bash workaround
Expected Behavior
Write and Edit tools should handle arbitrary file content without failing due to special characters.
Actual Behavior
Repeated errors:
Error editing file
Error editing file
Error writing file
Model self-diagnoses: "单引号冲突" (single quote conflict) and falls back to:
python -c "with open('file.py','w') as f: f.write('...')"
Environment
- OS: Windows 10 Home 10.0.19045
- Shell: bash (Git Bash)
- Claude Code version: latest (claude-sonnet-4-5)
Workaround
Using bash heredoc or python -c with file write works, but the native Write/Edit tools should handle this correctly.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗