Panic: UTF-8 byte boundary error when editing files with Chinese characters
Status Closed — duplicate
Reported on v2.0.76
Maintainer reply None cached
Activity 3 comments · opened Dec 26, 2025 · closed Dec 29, 2025
Bug Description
Claude Code panics when editing files containing Chinese text. The status bar preview truncates strings at byte boundaries instead of character boundaries, causing a crash when the cut happens in the middle of a multi-byte UTF-8 character.
Error Message
thread '<unnamed>' panicked at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/str/mod.rs:833:21:
byte index 20 is not a char boundary; it is inside '体' (bytes 18..21) of `可以给文字斜体`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5, aborting
zsh: abort claude --dangerously-skip-permissions -c
Steps to Reproduce
- Create/edit a file containing Chinese text, e.g., a comment like
# 可以给文字斜体 - Ask Claude Code to edit/update that file
- During the "Whirring…" phase (status bar showing edit progress), the panic occurs
Root Cause Analysis
- Chinese characters in UTF-8 are 3 bytes each
- The character
体occupies bytes 18-20 - Code attempts to slice at byte index 20, which is inside the character
- Rust panics because you cannot slice a string at non-character boundaries
Expected Behavior
String truncation should respect UTF-8 character boundaries, e.g., using .chars().take(n) instead of byte slicing.
Environment
- Claude Code version: 2.0.76
- OS: macOS (Darwin 25.0.0)
- Platform: darwin
Suggested Fix
Replace byte-based string slicing with character-aware truncation:
// Instead of:
text[0..20]
// Use:
text.char_indices()
.take_while(|(i, _)| *i < 20)
.map(|(_, c)| c)
.collect::<String>()
Or use a crate like unicode-segmentation for proper grapheme cluster handling.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗