[BUG] Panic when selecting text with Chinese characters: byte index is not a char boundary
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?
Bug Description:
Claude Code crashes with a Rust panic when selecting text from a markdown file containing Chinese characters.
What Should Happen?
Claude should vim markdown successfully.
Error Messages/Logs
thread '<unnamed>' (4645862) panicked at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/str/mod.rs:833:21:
byte index 19 is not a char boundary; it is inside '。' (bytes 17..20) of `演(胡琴方向)。这种音乐与技术的双重背景塑造了我对音乐计算研究的思考方式。`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5, aborting
Abort trap: 6
Steps to Reproduce
Steps to Reproduce:
- Open a markdown file containing Chinese text
- Select a portion of text that includes Chinese characters (specifically text containing Chinese punctuation like
。) - Claude Code crashes with the panic above
Root Cause:
The error indicates that the code is attempting to slice a UTF-8 string at a byte index (19) that falls in the middle of a multi-byte character (Chinese full stop 。 which occupies bytes 17-20). This violates UTF-8 character boundaries.
Environment:
- Platform: macOS (Darwin 25.2.0)
- Claude Code version: [your version]
- File:
动机信-英文.md(contains both English and Chinese text)
Expected Behavior:
Claude Code should handle multi-byte UTF-8 characters correctly when processing selected text, ensuring string operations respect character boundaries.
Additional Context:
The Chinese full stop 。 and other CJK characters occupy 3 bytes in UTF-8. String slicing operations need to use character-aware methods rather than raw byte indexing.
Claude Model
Sonnet (default)
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
v2.1.5
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗