[BUG]Edit tool preview crashes with Chinese text: "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
The Edit tool preview pane crashes when editing files containing Chinese characters during skill execution. The panic occurs because the Rust code uses
byte indices to slice strings, but Chinese characters are multi-byte (3 bytes per char).
What Should Happen?
This bug completely blocks the use of Edit tool for any workflows involving:
- Chinese text translation
- Files with CJK (Chinese/Japanese/Korean) characters
- Multilingual content processing
Users must fall back to Write tool, which is less efficient for single-line edits.
Error Messages/Logs
thread '' panicked at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/str/mod.rs:833:21:
byte index 42 is not a char boundary; it is inside '型' (bytes 40..43) of 的 AI 计划包括购物代理和新模型
note: run with RUST_BACKTRACE=1 environment variable for a backtrace
fatal runtime error: failed to initiate panic, error 5, aborting
Steps to Reproduce
## Steps to Reproduce
### Prerequisites
- Create or use any custom skill that edits markdown files with Chinese content
- Example skill:
daily-topic-selector(fetches AI news and adds Chinese translations)
### Reproduction Steps
- Run the skill command:
/daily-topic-selector
- The skill fetches articles and attempts to add Chinese translations using Edit tool:
```markdown
- [ ] 标题: Meta's AI Plans Include Shopping Agents and New Models
→ Edit to:
- [ ] 标题: Meta's AI Plans Include Shopping Agents and New Models / Meta 的 AI 计划包括购物代理和新模型
- The Edit tool preview pane triggers panic when displaying the diff
- Claude Code CLI crashes with the error above
- The process exits with code 134 (abort)
Minimal Reproduction
Create a test file test.md:
## Test
- [ ] 标题: Meta AI Plans / Meta 的 AI 计划
Then ask Claude to edit the title line. The preview will crash.
Environment
- OS: macOS 25.2.0 (Darwin)
- Model: opus
- Claude Code: Session crashed during skill execution
Root Cause
From the error message:
byte index 42 is not a char boundary; it is inside '型' (bytes 40..43)
The character '型' occupies bytes 40-43. When the code tries to slice at byte 42, it splits the multi-byte UTF-8 character, violating Rust's string
slicing rules.
Workaround
Use Write tool instead of Edit tool:
# In SKILL.md, change the workflow from:
"4. 使用 Edit 工具批量翻译所有未翻译的英文标题"
# to:
"4. 使用 Write 工具完成翻译(Edit 工具对中文有 bug)"
Suggested Fix
The Edit tool preview code should use character-aware slicing:
// Instead of:
let preview = &text[0..42]; // ❌ Crashes on multi-byte chars
// Use:
let preview = text.char_indices()
.nth(42)
.map(|(i, _)| &text[..i])
.unwrap_or(&text);
// Or simpler:
let preview = text.split_at(42).0; // ✅ Validates char boundary
Additional Context
- This affects the Edit tool preview pane specifically
- The actual edit operation might succeed, but the preview crashes the entire CLI
- The bug is 100% reproducible with Chinese text
- Similar issues likely affect Japanese, Korean, and other non-ASCII scripts
Claude Model
None
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
v2.1.5
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
Environment
- OS: macOS 25.2.0 (Darwin)
- Model: opus
- Claude Code: Session crashed during skill execution
Root Cause
From the error message:
byte index 42 is not a char boundary; it is inside '型' (bytes 40..43)
The character '型' occupies bytes 40-43. When the code tries to slice at byte 42, it splits the multi-byte UTF-8 character, violating Rust's string
slicing rules.
Workaround
Use Write tool instead of Edit tool:
# In SKILL.md, change the workflow from:
"4. 使用 Edit 工具批量翻译所有未翻译的英文标题"
# to:
"4. 使用 Write 工具完成翻译(Edit 工具对中文有 bug)"
Suggested Fix
The Edit tool preview code should use character-aware slicing:
// Instead of:
let preview = &text[0..42]; // ❌ Crashes on multi-byte chars
// Use:
let preview = text.char_indices()
.nth(42)
.map(|(i, _)| &text[..i])
.unwrap_or(&text);
// Or simpler:
let preview = text.split_at(42).0; // ✅ Validates char boundary
Additional Context
- This affects the Edit tool preview pane specifically
- The actual edit operation might succeed, but the preview crashes the entire CLI
- The bug is 100% reproducible with Chinese text
- Similar issues likely affect Japanese, Korean, and other non-ASCII scripts
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗