[BUG] Panic on UTF-8 boundary when editing files with Chinese characters
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?
Claude Code crashes with a Rust panic when performing an Edit operation on a file containing Chinese text.
## Error message
``五大功能 + 工程决策
thread '<unnamed>' panicked at .../core/src/str/mod.rs:833:21:
byte index 26 is not a char boundary; it is inside '策' (bytes 24..27) of
``
fatal runtime error: failed to initiate panic, error 5, aborting
zsh: abort claude
## Context
- The Edit tool was updating a markdown file with mixed Chinese/English
content
- The string being processed was
五大功能 + 工程决策 - Byte index 26 falls inside the 3-byte UTF-8 encoding of '策'
## Version
2.0.76
## Expected behavior
String slicing should respect UTF-8 character boundaries.
## Suggested fix
Use char_indices() or similar UTF-8-safe string operations instead of raw byte indexing."
What Should Happen?
String slicing should respect UTF-8 character boundaries.
Error Messages/Logs
byte index 26 is not a char boundary; it is inside '策' (bytes 24..27) of
`五大功能 + 工程决策`
fatal runtime error: failed to initiate panic, error 5, aborting
zsh: abort claude
Steps to Reproduce
The crash occurs when the Edit tool's diff display logic tries to slice the string 五大功能 + 工程决策 at byte index 26, which falls inside the multi-byte character '策'.
Each Chinese character is 3 bytes in UTF-8:
- 五 (bytes 0-2)
- 大 (bytes 3-5)
- 功 (bytes 6-8)
- 能 (bytes 9-11)
- (space, byte 12)
- (byte 13)
- (space, byte 14)
- 工 (bytes 15-17)
- 程 (bytes 18-20)
- 决 (bytes 21-23)
- 策 (bytes 24-26) ← byte 26 is the last byte of this char, not a valid boundary
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.0.76
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗