Panic: byte index 2 is not a char boundary when editing files with Chinese characters

Resolved 💬 3 comments Opened Jan 13, 2026 by aurochs-code Closed Feb 28, 2026

Bug Description

Claude Code crashes with a panic when editing files containing Chinese characters (specifically the punctuation mark -顿号).

Error Message

thread '<unnamed>' (66442451) 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 `、scheduling_discarded``
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5, aborting

Environment

  • Claude Code Version: 2.1.1
  • Rust Version: 1.88.0 (6b00bc388 2025-06-23)
  • OS: macOS (Darwin 25.1.0)
  • Platform: darwin

Steps to Reproduce

  1. Working in a directory with Chinese filename: docs/plans/2026-01-13-监控告警建设规划.md
  2. User prompts: "不需要具体的实现细节,输出明天一整年的建设计划就行了,完善一下刚刚的文档"
  3. Claude Code reads the file (253 lines)
  4. Claude Code writes the file with edits
  5. During "accept edits" phase (shift+tab to cycle), the panic occurs

Root Cause Analysis

The panic occurs because:

  • The Chinese punctuation character (顿号/ideographic comma) occupies 3 bytes in UTF-8 encoding
  • The code attempts to access the string using byte index 2, which falls in the middle of this character
  • String slicing in Rust requires byte indices to be on character boundaries for safety

Expected Behavior

Claude Code should handle multi-byte UTF-8 characters correctly when editing files, using character indices instead of byte indices for string operations.

Actual Behavior

Claude Code crashes with a panic when encountering certain Chinese characters during the edit acceptance phase.

Severity

High - causes complete crash when editing files with common Chinese punctuation marks.

Suggested Fix

Replace byte-indexed string operations with character-aware alternatives:

// ❌ Current (causes panic)
let substring = &str[0..2];

// ✅ Fix: Use char_indices
let end = str.char_indices().nth(n).map(|(i, _)| i).unwrap_or(str.len());
let substring = &str[0..end];

// ✅ Or use chars().take()
let substring: String = str.chars().take(n).collect();

Additional Context

  • The file path contains Chinese characters: 监控告警建设规划.md
  • The specific character causing the issue is (U+3001, 3 bytes in UTF-8)
  • The error string shown in panic: 、scheduling_discarded

🤖 Generated with Claude Code

View original on GitHub ↗

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