[BUG] Panic on UTF-8 boundary when processing Chinese text
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 crashed with a Rust panic while processing Chinese text during a normal session. The error indicates improper byte-level string slicing on multi-byte UTF-8 characters.
The crash occurred while working on a Chinese novel project. Chinese characters are 3 bytes each in UTF-8, so byte index 44 falls inside the character '铁' (bytes 42-45). The code is using byte indexing (e.g., &s[0..44]) instead of character-aware methods like .chars(), .char_indices(), or the unicode-segmentation crate. This will affect any user working with CJK text. Environment: Ubuntu 22.04 WSL2, Claude Code CLI.
What Should Happen?
Claude Code should handle Chinese/CJK text without crashing. When processing,
displaying, or truncating multi-byte UTF-8 strings, the application should:
- Complete the session normally without panicking
- Correctly handle string operations on Chinese text by respecting UTF-8
character boundaries
- If text truncation is needed (for display, context limits, etc.), truncate
at valid character boundaries, not arbitrary byte positions
The session should continue working with Chinese text files the same way it
works with ASCII/Latin text.
Error Messages/Logs
thread '<unnamed>' (928) panicked at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/str/mod.rs:833:21:
byte index 44 is not a char boundary; it is inside '铁' (bytes 42..45) of `在很远的地方用砂纸打磨生锈的铁。声音从我们两侧山坡传来,不止一个方向。`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5, aborting
Aborted (core dumped)
Steps to Reproduce
- Open Claude Code in a project containing Chinese/CJK text files
- Work with files containing Chinese prose (in my case, a Chinese novel in markdown)
- The crash occurred during normal session operation - exact trigger unknown as it happened mid-session
- Cannot reliably reproduce, but the crash is deterministic once the specific text is being processed internally
Note: The problematic string was: 在很远的地方用砂纸打磨生锈的铁。声音从我们两侧山坡传来,不止一个方向。
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
claude-opus-4-5-20250101
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
WSL (Windows Subsystem for Linux)
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗