[BUG] Write tool corrupts UTF-8 encoding (BOM loss)
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Tool affected: Write
Environment: Windows, ASP.NET project (Visual Studio 2026)
Issue: When using the Write tool to completely rewrite a file, UTF-8 BOM (Byte Order Mark) is not preserved. This causes accented characters to display incorrectly (e.g., "sécurisé" becomes "sécurisé").
Expected behavior: Write tool should detect and preserve the original file's encoding (including BOM) when overwriting.
What Should Happen?
This causes accented characters to display incorrectly (e.g., "sécurisé" becomes "sécurisé")
Error Messages/Logs
Steps to Reproduce
Reproduction:
- Have a file with UTF-8 BOM encoding containing accented characters (common in .ascx, .aspx, .cs files)
- Use Write tool to rewrite the entire file
- Accented characters are corrupted
Claude Model
None
Is this a regression?
No, this never worked
Last Working Version
No response
Claude Code Version
2.0.61
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Windows Terminal
Additional Information
No response
Bug: Write tool creates files without proper UTF-8 BOM, causing ASP.NET to misinterpret encoding in browser even though file content is correct.
Proof: Creating a new file manually and copy-pasting the same content works correctly. The issue is the file metadata/BOM, not the content.
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 is occurring for me as well, on Mac using JetBrains Rider. Here's the issue text from Claude Code:
Bug summary: The Edit tool corrupts UTF-8 BOM files by converting the BOM encoding marker (EF BB BF) into visible content (ZWNBSP/U+FEFF character) while also stripping the BOM encoding flag.
Steps to reproduce:
- Have a file saved with UTF-8 BOM encoding
- Use the Edit tool to make any change to the file
- The resulting diff shows the BOM being converted to a "ZWNBSP" character prepended to line 1
Expected: Edit should preserve the file's original encoding (UTF-8 BOM)
Actual: BOM is stripped from encoding and inserted as visible content
And here's a screenshot of what this looks like in the Rider diff viewer. 'ZWNBSP' is a single character, the unicode "zero-width no-break space"
The issue is reproducible in the latest version. Blocks the work fully because random symbols are displayed in Visual Studio
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
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.