Panic when processing Chinese text: byte index not a char boundary in UTF-8 string
Resolved 💬 4 comments Opened Dec 30, 2025 by kiki830621 Closed Feb 26, 2026
Description
Claude Code crashes with a Rust panic when processing text containing Chinese characters. The error occurs during string slicing where the byte index falls inside a multi-byte UTF-8 character.
Error Message
thread '<unnamed>' (19968778) panicked at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/str/mod.rs:833:21:
byte index 95 is not a char boundary; it is inside '。' (bytes 93..96) of `易產生內在歸因(「我需要加強」)而非外在歸因(「老師針對我」)。`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5, aborting
[1] 91024 abort claude --dangerously-skip-permissions
Environment
- OS: macOS (Darwin 25.2.0)
- Claude Code version: Latest (as of 2024-12-30)
- Command:
claude --dangerously-skip-permissions
Steps to Reproduce
- Open Claude Code in a project containing Chinese text files
- The CLI attempts to process/display Chinese content
- Crash occurs when the internal string slicing hits a multi-byte character boundary
Root Cause Analysis
The error indicates that the code is using byte indexing instead of character indexing when slicing a UTF-8 string containing CJK characters:
- Chinese punctuation
。(U+3002) is encoded as 3 bytes in UTF-8 - The code attempted to slice at byte index 95
- This index falls inside the character
。(bytes 93..96) - Rust's string safety correctly panics to prevent invalid UTF-8
Suggested Fix
The string slicing logic should use character-aware methods:
// Instead of:
&s[0..byte_index]
// Use:
s.char_indices()
.take_while(|(i, _)| *i < target_char_count)
.map(|(_, c)| c)
.collect::<String>()
// Or use the `unicode-segmentation` crate for proper grapheme handling
Impact
This bug affects all users working with:
- Chinese (Traditional/Simplified)
- Japanese
- Korean
- Any other multi-byte UTF-8 text
Additional Context
The affected text was from an educational psychology document discussing attribution theory in a Taiwanese high school context. The project contains extensive Chinese documentation.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗