Panic when truncating Korean (UTF-8 multibyte) strings
Resolved 💬 3 comments Opened Feb 5, 2026 by GeoEmmy Closed Feb 8, 2026
Bug Description
Claude Code CLI panics when handling strings containing Korean characters. The error occurs because the code attempts to slice a UTF-8 string at a byte index that falls in the middle of a multibyte character.
Error Message
thread '<unnamed>' panicked at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb\library\core\src\str\mod.rs:833:21:
byte index 8 is not a char boundary; it is inside '트' (bytes 6..9) of `이언트 (OC=kazzang)`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Root Cause
- Korean characters use 3 bytes in UTF-8 encoding
- The character '트' occupies bytes 6-9
- The code tries to slice at byte index 8, which is in the middle of '트'
- Rust panics because slicing at non-char boundaries is not allowed
Environment
- OS: Windows 11
- Claude Code CLI version: latest
- Locale: Korean
Frequency
This issue occurs frequently during normal usage, especially when:
- Working with Korean filenames
- Working in directories with Korean paths
- Processing Korean text content
Expected Behavior
The CLI should properly handle UTF-8 multibyte characters by using character boundaries instead of byte indices when truncating strings.
Suggested Fix
Use char_indices() or similar UTF-8 aware methods when truncating strings:
// Instead of: &s[..8]
// Use something like:
fn safe_truncate(s: &str, max_chars: usize) -> &str {
match s.char_indices().nth(max_chars) {
Some((idx, _)) => &s[..idx],
None => s,
}
}
Or use the unicode-segmentation crate for proper grapheme cluster handling.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗