Write tool corrupts UTF-8 multi-byte characters (box-drawing chars become NULL bytes)
Summary
The Write tool corrupts UTF-8 multi-byte characters by stripping the high bytes, leaving only the low byte of each Unicode codepoint. This results in files that appear as "binary" and cannot be opened in text editors.
Environment
- OS: Linux 6.17.0-7-generic
- Claude Code: VS Code extension
Steps to Reproduce
- Ask Claude to write a file containing Unicode box-drawing characters:
````
Write a markdown file with box-drawing characters like ─ │ ┌ ┐ └ ┘
- Try to open the resulting file in VS Code,
bat,micro, or other text editors
- Editors report the file is binary or has unsupported encoding
Expected Behavior
Box-drawing character ─ (U+2500) should be encoded as 3-byte UTF-8: e2 94 80
Actual Behavior
The character is written as a single byte 00 (just the low byte of the codepoint)
Hex dump comparison:
Corrupted file (written by Write tool):
7c 20 60 00 60 20 7c → | `.` | (NULL byte!)
^^ ^^ ^^
Correct file (copy-pasted from Claude's stdout):
7c 20 60 e2 94 80 60 20 7c → | `─` | (proper UTF-8)
^^ ^^ ^^
Pattern
The corruption consistently strips UTF-8 encoding, keeping only codepoint & 0xFF:
| Character | Unicode | Expected UTF-8 | Actual Byte |
|-----------|---------|----------------|-------------|
| ─ | U+2500 | e2 94 80 | 00 |
| │ | U+2502 | e2 94 82 | 02 |
| ┌ | U+250C | e2 94 8c | 0c |
| ┐ | U+2510 | e2 94 90 | 10 |
| └ | U+2514 | e2 94 94 | 14 |
| ┘ | U+2518 | e2 94 98 | 18 |
Workaround
Copy-paste Claude's stdout output to a file manually instead of using the Write tool.
Impact
- Files containing emoji, CJK characters, box-drawing, or any non-ASCII Unicode will be corrupted
- Affected files cannot be opened in standard text editors
- No warning is given that corruption occurred
6 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Experiencing this issue as well. This corruption resulting in weird control chars / null bytes also started happening VERY consistently whenever Claude edits an empty markdown file.
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
This issue is part of a larger UTF-8/encoding bug pattern affecting Claude Code's Edit/Write tools.
I've posted a consolidated impact analysis at #13939 showing at least 6+ related issues spanning 6+ months. The technical analysis you provided here (showing
codepoint & 0xFFtruncation) is particularly valuable for debugging.Cross-linking for visibility: #13939, #7134, #7332, #7335
This affects all non-English users and should be prioritized.
---
🤖 Generated with Claude Code
This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.