All symptoms日本語

T08

A .ps1 with non-ASCII text fails to parse or prints mojibake

Symptom

A .ps1 that looks right in your editor fails with a parse error such as "The string is missing the terminator", or runs and prints garbled text.

Check it in 30 seconds

Paste into Windows PowerShell 5.1. It only creates files under your %TEMP% folder. If the last line says REPRODUCED, it happens on your machine.

$d = Join-Path $env:TEMP ('cc-trap-' + (Get-Date -Format 'yyyyMMddHHmmss')); New-Item -ItemType Directory $d -Force | Out-Null
$want = [string][char]0x65E5 + [char]0x672C
[IO.File]::WriteAllText("$d\nobom.ps1", "Write-Output '$want'", (New-Object System.Text.UTF8Encoding $false))
$o = powershell -NoProfile -ExecutionPolicy Bypass -File "$d\nobom.ps1"
"got $o (want $want)"
if ($o -ne $want) { 'REPRODUCED' } else { 'NOT REPRODUCED' }

Why it happens

Windows PowerShell 5.1 reads a .ps1 without a BOM using the ANSI code page, not UTF-8. Most editors now save UTF-8 without a BOM.

Fix

Save .ps1 files that contain non-ASCII text as UTF-8 with BOM, or keep scripts ASCII-only and build characters with [char]0x00E9.

$t = [IO.File]::ReadAllText($path)
[IO.File]::WriteAllText($path, $t, (New-Object System.Text.UTF8Encoding $true))

On the author's machine

output differed from the source (Japanese Windows)

Author's machine: Windows 11 / Windows PowerShell 5.1.26100 / Python 3.13.7 / Claude Code 2.1.304, Japanese Windows (code page 932). Checked 2026-10-20 to 22.

If you searched for

Related

cc-win-kit bundles the parts that avoid these traps from the start: a write guard (with onFailure: block), an unattended runner, a doctor that scans your files and hook settings, CLAUDE.md templates and the full test suite.

cc-win-kit ($19 on Payhip)

Other symptoms