Panic: UTF-8 boundary error when processing Chinese characters

Resolved 💬 4 comments Opened Dec 29, 2025 by shizhilya Closed Jan 13, 2026

Description

Claude Code crashes with a Rust panic when processing strings that start with Chinese characters. The error indicates an invalid UTF-8 byte boundary access.

Error Message

thread '<unnamed>' (18396128) panicked at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/str/mod.rs:833:21:
byte index 2 is not a char boundary; it is inside '同' (bytes 0..3) of `同 `
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5, aborting
[1]    32993 abort      claude

Root Cause Analysis

The panic occurs because the code attempts to slice a UTF-8 string at byte index 2, but the Chinese character "同" occupies bytes 0-2 (3 bytes total in UTF-8). Index 2 falls inside the character boundary, which is invalid in Rust's string handling.

Environment

  • OS: macOS (Darwin 25.1.0)
  • Claude Code version: Latest
  • Context: Processing Chinese text in CLAUDE.md configuration files

Expected Behavior

Claude Code should correctly handle multi-byte UTF-8 characters (Chinese, Japanese, Korean, emoji, etc.) without crashing.

Suggested Fix

Ensure all string slicing operations use character boundaries rather than raw byte indices. In Rust, this typically means using .char_indices() or .chars() instead of direct byte indexing.

// ❌ Problematic
let slice = &s[0..2];  // May split multi-byte char

// ✅ Safe
let slice: String = s.chars().take(n).collect();

Additional Context

This appears to be triggered by Chinese text in user configuration files (CLAUDE.md). The specific string "同 " (Chinese character + space) was being processed when the crash occurred.

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗