claude-code - 💡(How to fix) Fix Multi-byte UTF-8 characters corrupted in Write tool and Bash tool output [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#51835Fetched 2026-04-23 07:43:41
View on GitHub
Comments
2
Participants
2
Timeline
8
Reactions
0
Author
Timeline (top)
labeled ×5commented ×2closed ×1

When using Claude Code with Japanese text (3-byte UTF-8 characters), characters are frequently corrupted to U+FFFD replacement characters. This has become noticeably more frequent in recent sessions.

Root Cause

When using Claude Code with Japanese text (3-byte UTF-8 characters), characters are frequently corrupted to U+FFFD replacement characters. This has become noticeably more frequent in recent sessions.

Fix Action

Workaround

  • Re-read the file after Write and manually fix corrupted characters
  • For Bash --title arguments, append a trailing ASCII character (space) to avoid end-of-buffer truncation
RAW_BUFFERClick to expand / collapse

Description

When using Claude Code with Japanese text (3-byte UTF-8 characters), characters are frequently corrupted to U+FFFD replacement characters. This has become noticeably more frequent in recent sessions.

Environment

  • Claude Code: v2.1.117
  • Model: Claude Opus 4.6 (1M context)
  • OS: WSL2 (Linux 6.6.87.2-microsoft-standard-WSL2)
  • Shell: fish

Reproduction

Two distinct corruption patterns observed:

Pattern 1: Write tool — mid-text corruption

When the Write tool outputs a long Japanese markdown file (~160 lines), random multi-byte characters in the middle of the text are corrupted.

Example:

  • Expected: として正常ハンドリングする
  • Actual: と���て正常ハンドリングする

The corrupted character ��� is U+FFFD, indicating an incomplete UTF-8 byte sequence. In a single Write call, 16 characters across 164 lines were corrupted.

Pattern 2: Bash tool — trailing character truncation

When passing Japanese text as a CLI argument (e.g., gh issue create --title "..."), the final multi-byte character is truncated.

Example:

  • Expected: Phase 1 残りツール実装(11 ツール)
  • Actual: Phase 1 残りツール実装(11 ツール���

The closing full-width parenthesis (3 bytes: EF BC 89) loses its final byte.

Likely Cause

The output streaming buffer appears to split at arbitrary byte boundaries rather than UTF-8 character boundaries. Since Japanese characters are 3 bytes each, a chunk boundary falling mid-character produces incomplete byte sequences that are replaced with U+FFFD.

This is consistent with:

  • Longer texts having more corruptions (more chunk boundaries)
  • Corruption occurring at seemingly random positions
  • Only multi-byte characters being affected (ASCII is never corrupted)

Workaround

  • Re-read the file after Write and manually fix corrupted characters
  • For Bash --title arguments, append a trailing ASCII character (space) to avoid end-of-buffer truncation

Expected Behavior

All UTF-8 characters should be correctly preserved when passed to tool parameters, regardless of text length or character byte width.

extent analysis

TL;DR

The issue can be mitigated by ensuring that output streaming buffers split at UTF-8 character boundaries rather than arbitrary byte boundaries.

Guidance

  • Verify that the Claude Code version (v2.1.117) has any known issues or updates related to UTF-8 character handling.
  • Check the documentation for the Write tool and Bash tool to see if there are any configuration options or parameters that can be adjusted to handle multi-byte characters correctly.
  • Consider appending a trailing ASCII character to the end of Japanese text passed as CLI arguments to avoid end-of-buffer truncation.
  • Test the workaround of re-reading the file after Write and manually fixing corrupted characters to see if it consistently resolves the issue.

Example

No code snippet is provided as the issue does not imply a specific code-based solution.

Notes

The provided workaround may not be a permanent solution and may need to be revisited if the underlying issue is not addressed. The corruption patterns observed may be specific to the combination of Claude Code, model, and OS used.

Recommendation

Apply the workaround of appending a trailing ASCII character to the end of Japanese text passed as CLI arguments and re-reading the file after Write to manually fix corrupted characters, as this may provide a temporary solution to mitigate the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING