Panic when editing files containing Japanese text: byte index is not a char boundary

Resolved 💬 3 comments Opened Jan 8, 2026 by KTKR-DSK Closed Jan 11, 2026

Bug Description

Claude Code panics when attempting to edit Markdown files containing Japanese (multi-byte UTF-8) text. The error occurs during Edit operations on files with Japanese content.

Error Message

thread '<unnamed>' (95225) panicked at /rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb/library/core/src/str/mod.rs:833:21:
byte index 38 is not a char boundary; it is inside 'す' (bytes 36..39) of `集計するPythonスクリプトです。`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5, aborting

Steps to Reproduce

  1. Create or open a Markdown file containing Japanese text (e.g., README.md)
  2. Attempt to edit the file using Claude Code's Edit tool
  3. The panic occurs during text processing/truncation

Example File Content

# 工数集計スクリプト (timesheet_aggregator_v3.py)

指定されたフォルダ内の複数のExcelファイル(工数管理表)から、特定の商談番号(Deal ID)に関連する工数を集計するPythonスクリプトです。

The third line triggers the panic when Claude Code attempts to slice the string at byte index 38, which falls inside the character 'す' (bytes 36-39).

Root Cause Analysis

This appears to be a UTF-8 string slicing issue in the Rust implementation. Japanese characters are 3 bytes each in UTF-8, and the code is attempting to slice at a byte index that is not a character boundary.

Suggested Fix

Use safe string truncation that respects character boundaries:

fn safe_truncate(s: &str, max_bytes: usize) -> &str {
    if max_bytes >= s.len() {
        return s;
    }
    let mut end = max_bytes;
    while !s.is_char_boundary(end) && end > 0 {
        end -= 1;
    }
    &s[..end]
}

Or use str::floor_char_boundary() (available in nightly) or similar safe slicing methods.

Environment

  • OS: Windows 11 (WSL2 - Linux 6.6.87.2-microsoft-standard-WSL2)
  • Claude Code Version: Latest (as of January 2026)
  • File Type: Markdown (.md) with Japanese content

Workaround

Currently, users must edit files containing Japanese text using external editors (VSCode, etc.) instead of Claude Code's Edit tool.

Impact

This bug prevents Claude Code from being used effectively in Japanese-language projects or any project with Japanese documentation/comments.

View original on GitHub ↗

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