[BUG] byte index is not a char boundary when processing Chinese/CJK characters

Resolved 💬 3 comments Opened Dec 29, 2025 by feiyu23 Closed Jan 1, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Claude Code CLI crashes with a Rust panic when processing output containing Chinese (CJK) characters. The error occurs during string slicing operations where the byte index falls in the middle of a multi-byte UTF-8 character.

Error Message

thread '<unnamed>' (298128) panicked at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/str/mod.rs:833:21:
byte index 5 is not a char boundary; it is inside '缘' (bytes 3..6) 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

Steps to Reproduce

  1. Work on a project with heavy Chinese text content (e.g., editing TypeScript files with Chinese string literals)
  2. Have Claude Code perform file edits that contain Chinese characters
  3. The crash occurs randomly during edit operations, particularly when the output preview contains Chinese text

Environment

  • OS: macOS (Darwin 24.6.0)
  • Claude Code version: (run claude --version to get this)
  • Shell: zsh

Expected Behavior

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

Root Cause Analysis

The Rust code appears to be slicing strings by byte index rather than character boundary. Chinese characters in UTF-8 encoding use 3 bytes each. When the code attempts to slice at a byte position that falls within a multi-byte character, it causes a panic.

Suggested Fix

Use character-aware string slicing methods in Rust, such as:

  • str::char_indices() to find valid character boundaries
  • str::chars() iterator instead of byte indexing
  • Libraries like unicode-segmentation for proper Unicode handling

Impact

This bug makes Claude Code unreliable for any project involving CJK (Chinese, Japanese, Korean) text, which affects a significant portion of users.

What Should Happen?

Claude Code CLI crashes with a Rust panic when processing output containing Chinese (CJK) characters. The error occurs during string slicing operations where the byte index falls in the middle of a multi-byte UTF-8 character.

Error Messages/Logs

thread '<unnamed>' (298128) panicked at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/str/mod.rs:833:21:
  byte index 5 is not a char boundary; it is inside '缘' (bytes 3..6) 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

Steps to Reproduce

  1. Work on a project with heavy Chinese text content (e.g., editing TypeScript files with Chinese string literals)
  2. Have Claude Code perform file edits that contain Chinese characters
  3. The crash occurs randomly during edit operations, particularly when the output preview contains Chinese text

Claude Model

Opus

Is this a regression?

No, this never worked

Last Working Version

_No response_

Claude Code Version

2.0.76

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

Environment

  • OS: macOS (Darwin 24.6.0)
  • Claude Code version: (run claude --version to get this)
  • Shell: zsh

Expected Behavior

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

Root Cause Analysis

The Rust code appears to be slicing strings by byte index rather than character boundary. Chinese characters in UTF-8 encoding use 3 bytes each. When the code attempts to slice at a byte position that falls within a multi-byte character, it causes a panic.

Suggested Fix

Use character-aware string slicing methods in Rust, such as:

  • str::char_indices() to find valid character boundaries
  • str::chars() iterator instead of byte indexing
  • Libraries like unicode-segmentation for proper Unicode handling

Impact

This bug makes Claude Code unreliable for any project involving CJK (Chinese, Japanese, Korean) text, which affects a significant portion of users.

View original on GitHub ↗

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