Panic: UTF-8 byte boundary errors when rendering CJK text

Status Closed — not planned
Maintainer reply None cached
Activity 7 comments · opened Dec 21, 2025 · closed Feb 21, 2026

Bug Description

Claude Code CLI crashes with Rust panics when rendering content containing Chinese (CJK) characters. Multiple crashes at different string positions indicate a systemic UTF-8 handling issue.

Error Messages

Crash 1:

thread '<unnamed>' panicked at library/core/src/str/mod.rs:833:21:
byte index 11 is not a char boundary; it is inside '职' (bytes 9..12)
fatal runtime error: failed to initiate panic, error 5, aborting
zsh: abort      claude

Crash 2:

thread '<unnamed>' panicked at library/core/src/str/mod.rs:833:21:
byte index 4 is not a char boundary; it is inside '里' (bytes 2..5)
fatal runtime error: failed to initiate panic, error 5, aborting
zsh: abort      claude

Analysis

  • Both crashes occur at Rust's str::mod.rs:833 (string slicing)
  • Different Chinese characters trigger the panic at different byte positions
  • This indicates a common text truncation/display function has the bug
  • The issue appears during CLI startup when processing CLAUDE.md

Root Cause

Byte-based string slicing without checking UTF-8 character boundaries. CJK characters are 3 bytes in UTF-8, so byte-index slicing frequently lands mid-character.

Reproduction

  1. Create a CLAUDE.md containing Chinese text (especially in markdown tables)
  2. Run claude in the directory
  3. CLI crashes during startup or conversation

Environment

  • OS: macOS Darwin 24.6.0
  • Claude Code: Latest version

Suggested Fix

Use character-aware string operations:

  • .chars().take(n) instead of &s[..n]
  • Check s.is_char_boundary(n) before slicing
  • Use s.floor_char_boundary(n) (Rust 1.80+) for safe truncation

View original on GitHub ↗

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