[BUG] Edit tool corrupts GBK-encoded Chinese comments in source files

Resolved 💬 3 comments Opened May 7, 2026 by zhenyunrao Closed May 10, 2026

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?

When using the Edit tool to modify a C++ source file that uses GBK/GB2312 encoding, the tool changes the file encoding
and corrupts existing Chinese comments (they become garbled/unreadable).

Steps to reproduce:

  1. Have a C++ file with GBK encoding containing Chinese comments
  2. Use Edit tool to modify a small portion of code
  3. Check the file - existing Chinese comments are now corrupted/garbled

Expected behavior: Edit tool should preserve the original file encoding (GBK/GB2312) and not corrupt existing content
outside the modified lines.

Actual behavior: The Edit tool appears to convert the file to a different encoding (UTF-8), causing all existing
Chinese comments in the file to become unreadable.

Environment: Windows 10, working with legacy C++ projects that use GBK encoding

---
希望这个问题能得到修复,让Edit工具能正确处理不同编码的文件。 而且使用sed时,文件的换行符CRLF被修改为LF

What Should Happen?

修改代码时,要保持文件编码不变

Error Messages/Logs

Steps to Reproduce

使用claude修改代码时,如果文件是GBK编码,修改后会中文乱码,换行符也被改了。希望保持原文件编码不变

Claude Model

None

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.1.107

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Windows Terminal

Additional Information

_No response_

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗