claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Write tool corrupts UTF-8 encoding (BOM loss)

Open StephFleury opened this issue 11 months ago • 2 comments

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:

  1. Have a file with UTF-8 BOM encoding containing accented characters (common in .ascx, .aspx, .cs files)
  2. Use Write tool to rewrite the entire file
  3. 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

StephFleury avatar Dec 08 '25 08:12 StephFleury

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.

StephFleury avatar Dec 08 '25 09:12 StephFleury

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.

github-actions[bot] avatar Jan 07 '26 10:01 github-actions[bot]

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:

  1. Have a file saved with UTF-8 BOM encoding
  2. Use the Edit tool to make any change to the file
  3. 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"

Image

tconkling avatar Jan 16 '26 16:01 tconkling

The issue is reproducible in the latest version. Blocks the work fully because random symbols are displayed in Visual Studio

Image Image Image

OleksandrMazhal avatar Jan 22 '26 09:01 OleksandrMazhal

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

github-actions[bot] avatar Feb 28 '26 10:02 github-actions[bot]

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.

github-actions[bot] avatar Mar 07 '26 14:03 github-actions[bot]