claude-code - 💡(How to fix) Fix Write/Edit tool fails with special characters in file content on Windows

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

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. </). Error editing file Error editing file Error writing file

Fix Action

Workaround

Using bash heredoc or python -c with file write works, but the native Write/Edit tools should handle this correctly.

Code Example

Error editing file
Error editing file
Error writing file

---

python -c "with open('file.py','w') as f: f.write('...')"
RAW_BUFFERClick to expand / collapse

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

  1. Ask Claude Code to write a Python script containing single quotes or backslashes in string literals
  2. Observe repeated failures even after retries
  3. 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.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Write/Edit tool fails with special characters in file content on Windows