cd /news/ai-tools/my-claude-code-hook-silently-ate-eve… · home topics ai-tools article
[ARTICLE · art-23111] src=dev.to pub= topic=ai-tools verified=true sentiment=↓ negative

My Claude Code hook silently ate every Korean character, and it took me an hour to figure out why

A developer spent an hour debugging a Claude Code hook on Windows that silently failed to match Korean-language prompts. The issue was not in the code logic but in Windows PowerShell 5.1's file encoding: the `.ps1` script, saved as plain UTF-8 without a byte-order mark, reinterpreted Korean characters as garbage at parse time, causing regex patterns to silently fail without errors. The fix required re-saving the script with a UTF-8 BOM, a problem that pure-ASCII scripts never trigger.

read3 min publishedJun 6, 2026

I spent an hour last week debugging a hook that wasn't broken.

Here's the setup: I run Claude Code on Windows, and I'd written a little UserPromptSubmit

hook in PowerShell — a keyword router that reads my prompt and, if it sees something like mcp 서버

or 코드 리뷰

, injects a hint so Claude pulls up the right skill. Half my prompts are in Korean, so a bunch of the regex patterns had Korean in them.

It worked perfectly for the English rules. The Korean ones? Dead. No match, no error, no log line. The script ran, exited 0, and just... did nothing for half my inputs.

I did all the dumb things first. Echoed the prompt — looked fine. Tested the regex in a PowerShell console — matched fine. Re-read the JSON parsing five times. Added Write-Host

debugging everywhere. Nothing.

The actual problem had nothing to do with my code. It was the file encoding.

Windows PowerShell 5.1 (the default powershell.exe

, not pwsh

) does not assume UTF-8 when it reads a .ps1

file. If there's no byte-order mark, it falls back to the legacy system code page. So my script — saved as plain UTF-8 by my editor — got its Korean bytes reinterpreted as garbage at parse time, before a single line ran. The regex literal that was supposed to be 코드.?리뷰

became mojibake, which of course never matches anything real. And because it's a parse-level reinterpretation, you don't get an error. You get silence.

The fix is one line, once you know:

function Add-Bom($path) {
  $text = [System.IO.File]::ReadAllText($path)
  $enc  = New-Object System.Text.UTF8Encoding $true   # $true = write the BOM
  [System.IO.File]::WriteAllText($path, $text, $enc)
}
Add-Bom "$env:USERPROFILE\.claude\skill-router.ps1"

Re-save with a BOM and everything lights up. Pure-ASCII scripts don't care, which is exactly why every example you find online "works" — almost all of them are bash on macOS, and the handful of PowerShell ones never have a non-ASCII character to trip over.

That bug annoyed me enough that I went and cleaned up my whole Claude Code setup so I'd never have to rediscover this stuff. A few things that were worth keeping:

rm -rf /

, DROP TABLE

, git push --force

, taskkill

, a disk format, etc. It doesn't hard-block — it injects a "show this to the user and confirm first" instruction. Saved me from a --hard

reset I didn't mean to approve.chcp 65001

It's not magic and it won't make Claude smarter. It's plumbing — guardrails, routing, and a setup guide that tells you about the BOM thing on page one so you don't lose the hour I lost.

If you're on Windows and your hooks are misbehaving in ways that make no sense, check your encoding before you check your logic. And if you've hit other PowerShell-specific Claude Code papercuts, tell me — I'd rather fix them in the repo than rediscover them at 1am.

── more in #ai-tools 4 stories · sorted by recency
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/my-claude-code-hook-…] indexed:0 read:3min 2026-06-06 ·