AIToday
AI Coding AssistantsZenn AI/MLPublished: Nov 26, 2026, 10:01 JST

Windows cp932 traps make Claude Code silently corrupt Japanese

Send on LINE
Windows cp932 traps make Claude Code silently corrupt Japanese

3 Key Points

  1. What happened

    The write-up reproduces six traps on Windows 11 with Windows PowerShell 5.1 at code page 932 and Python 3.13, including piping Japanese into 'claude -p' arriving as '??' and a BOM-less .ps1 that exits 0 with wrong characters.

  2. Why it matters

    The failures pass with exit code 0 and only the output is wrong in four of the six cases, so the author says to verify with hex dumps and comparison results rather than what the screen shows.

Not sure about something? Ask the AI

Questions and answers are published on this page.

Summaries like this, every morning.

By signing up you agree to the Terms of Service and Privacy Policy.

Context & Analysis

That makes them hard to catch by eye, and the author notes that terminal settings can mask them further — setting the code page to 65001 or running PowerShell 7 changes which traps reproduce, so a script that works interactively can still fail when launched from a scheduler or another program. Two of the traps are about the two directions of a pipe: PowerShell 5.1 encodes text sent to an external command using $OutputEncoding, which defaults to ASCII, while it reads that command's output using [Console]::OutputEncoding, which defaults to cp932. Fixing only one direction leaves the other broken. A third trap appears only on redirection, where Python tries to write cp932 to a file and crashes on characters like em dashes that AI-generated text often contains. A fourth shows that Python's -I isolated mode ignores the PYTHONIOENCODING workaround, so the script itself must reconfigure its output. The last two are file-format traps: a .ps1 saved as UTF-8 without a BOM is read as cp932 by PowerShell 5.1, and a .cmd file with LF line endings and cp932 encoding can cause cmd.exe to execute parts of comment lines. The author cites a report in the anthropics/claude-code repository (#92328) where an LF .cmd file turned 'del /F /Q "%VAR%"' into 'del /F /Q ""' and deleted files in the working folder, though the author did not reproduce that deletion. The piece closes by pointing to a free GitHub reproduction script and a Zenn book covering 14 total traps.

FAQ
What is the root cause of the garbled Japanese?
Most cases come from a mismatch between cp932, the default code page on Japanese Windows, and UTF-8, which AI tools and Python use. English Windows uses cp437 or cp1252, so the same problem does not appear or appears differently.
How can I check whether my output is actually correct?
The author recommends checking exit codes, byte sequences with hex(), and comparison results like 'same=' rather than trusting what the screen displays. A free script, repro-traps.ps1, reports which traps reproduce on your PC.
Does PowerShell 7 have the same problems?
The author notes that PowerShell 7 has different defaults, so some of the six traps do not occur there. The tests were run on Windows PowerShell 5.1, which ships with Windows.
Send on LINE

AI news that matters for your work, delivered every morning.

Pick your industry and the AI tools you use, and get news related to your work every day.

By signing up you agree to the Terms of Service and Privacy Policy.

Free · 30 seconds with Google · unsubscribe anytimeWhat is AIToday? →

Ask AI

Ask AI anything about this article. The AI reads this article, earlier AIToday articles, and Wikipedia, and cites its sources. Q&As are published on this page for other readers too.

Questions and answers are published on this page.

Related Articles

Next articleAmbient score: the AI failure mode that looks different