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
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗