[BUG] Panic: UTF-8 string slicing at non-character boundary when processing multi-byte characters

Resolved 💬 3 comments Opened Dec 27, 2025 by ruizrica Closed Dec 31, 2025

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?

## Description

Claude Code panics when processing content containing multi-byte UTF-8 characters (Chinese text in this case). The CLI attempts to slice a string at a byte index that falls inside a multi-byte character, which is invalid in Rust.

## Error

thread '' 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 框架</h2>
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

## Analysis

The string 框架</h2> contains Chinese characters where:

  • occupies bytes 0-2
  • occupies bytes 3-5
  • </h2> starts at byte 6

The code attempts to index at byte 5, which is inside the second character, causing the panic.

## Environment

  • OS: macOS (Darwin 25.2.0)
  • Claude Code version: 2.0.76

## Expected Behavior

Claude Code should handle multi-byte UTF-8 characters correctly, using character boundaries rather than raw byte indices when slicing strings.

## Additional Context

This appears to happen during HTML/markdown content processing. The 框架 means "framework" in Chinese, suggesting this may have originated from web content or internationalized documentation.

What Should Happen?

Claude Code should handle multi-byte UTF-8 characters correctly when processing HTML/markdown content, using character boundaries rather than raw byte indices when slicing or truncating strings.

Error Messages/Logs

thread '<unnamed>' 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 `框架</h2>`
  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. Process content containing multi-byte UTF-8 characters (e.g., Chinese text like 框架</h2>)
  2. The exact trigger is unclear, but likely occurs during HTML/markdown rendering or web fetch content processing
  3. CLI crashes with the above panic

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.0.76

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Other

Additional Information

I was using Wezterm terminal emulator.

View original on GitHub ↗

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