[BUG] Write tool still corrupts CJK UTF-8 to U+FFFD on v2.1.195 (Windows)

Open 💬 1 comment Opened Jun 29, 2026 by zhangjingrun4113-rgb

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?

之前 #7557 和 #44489 报告过类似问题,但在当前最新版 v2.1.195 上仍复现。Windows 11,Write 工具写入中文 .py 文件时 UTF-8 多字节字符全变成 U+FFFD,同内容走 Bash heredoc正常。估计 v2.1.94 的修复未覆盖 Write 工具的完整路径或有回退。
旧 issue #7557 已锁无法评论,故新开

What Should Happen?

Write 工具写入含中文的文件时和 Bash 工具一样正确保留 UTF-8 编码,中文字符不被替换为 U+FFFD。
The Write tool should correctly preserve UTF-8 encoded Chinese characters in file content, matching the behavior of the Bash tool (e.g. cat > file << 'EOF'). Characters should not be replaced by U+FFFD.

Error Messages/Logs

### 1. xxd 验证 — Write 工具写入的文件字节(U+FFFD 损坏)

  $ head -c 500 append_pvalue.py | xxd | head -10
  00000000: 2320 2d2a 2d20 636f 6469 6e67 3a20 7574  # -*- coding: ut
  00000010: 662d 3820 2d2a 2d0a 2222 220a efbf bdef  f-8 -*-.""".....
  00000020: bfbd efbf bdda a1ef bfbd cab5 efbf bdef  ................
  ...
  中文字符全部被替换为 ef bf bd (U+FFFD),而正常的 张 应为 e5 bc a0

  ### 2. Python 报错 — 含中文路径的文件无法被 python-docx 打开

  PackageNotFoundError: Package not found at 'D:/张景润/大二下期末备考/实验心理补充/...'

  ### 3. Python 报错 — print 中文时 gbk 编码失败

  UnicodeEncodeError: 'gbk' codec can't encode character '\u2705' in position 0

  ### 4. 对比:同内容通过 Bash heredoc 写入 — 完全正常

  $ cat > file.py << 'EOF'
  [相同中文内容]
  EOF
  $ python file.py
  Done. New section appended successfully.  ← 正常

Steps to Reproduce

  1. 使用 Claude Code(Windows 11,v2.1.195)
  2. 请求 Claude Code 使用 Write 工具创建一个包含中文字符的 .py 文件,例如:

``python
# -*- coding: utf-8 -*-
path = r'D:\测试\文件.docx'
print('路径:', path)
``

  1. Claude Code 调用 Write 工具写入文件
  2. 在终端中检查文件字节:

``bash
xxd file.py | head -5
``

  1. 观察结果:中文字符(如 测试)的 UTF-8 字节被替换为 ef bf bd(U+FFFD)
  1. 对比:在同一个会话中请求 Claude Code 通过 Bash 工具用 heredoc 写入相同内容:

``bash
cat > file2.py << 'EOF'
# -*- coding: utf-8 -*-
path = r'D:\测试\文件.docx'
print('路径:', path)
EOF
``

  1. 检查 file2.py 的字节 — 编码完全正常,中文字符字节正确保留

关键对比:同一会话、同一内容、同一模型输出,Write 工具链路损坏而 Bash 工具链路正常。

Claude Model

None

Is this a regression?

Yes, this worked in a previous version

Last Working Version

Unknown — 本机首次使用,未验证过更早版本

Claude Code Version

2.1.195 (Claude Code)

Platform

Other

Operating System

Windows

Terminal/Shell

Windows Terminal

Additional Information

_No response_

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗