<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: coding_j</title>
    <description>The latest articles on DEV Community by coding_j (@codingjhj).</description>
    <link>https://dev.to/codingjhj</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3970656%2F7678220e-9638-4aeb-be34-0de156d31380.png</url>
      <title>DEV Community: coding_j</title>
      <link>https://dev.to/codingjhj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codingjhj"/>
    <language>en</language>
    <item>
      <title>My Claude Code hook silently ate every Korean character, and it took me an hour to figure out why</title>
      <dc:creator>coding_j</dc:creator>
      <pubDate>Sat, 06 Jun 2026 03:48:06 +0000</pubDate>
      <link>https://dev.to/codingjhj/my-claude-code-hook-silently-ate-every-korean-character-and-it-took-me-an-hour-to-figure-out-why-3ii4</link>
      <guid>https://dev.to/codingjhj/my-claude-code-hook-silently-ate-every-korean-character-and-it-took-me-an-hour-to-figure-out-why-3ii4</guid>
      <description>&lt;p&gt;I spent an hour last week debugging a hook that wasn't broken.&lt;/p&gt;

&lt;p&gt;Here's the setup: I run Claude Code on Windows, and I'd written a little &lt;code&gt;UserPromptSubmit&lt;/code&gt; hook in PowerShell — a keyword router that reads my prompt and, if it sees something like &lt;code&gt;mcp 서버&lt;/code&gt; or &lt;code&gt;코드 리뷰&lt;/code&gt;, 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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;Write-Host&lt;/code&gt; debugging everywhere. Nothing.&lt;/p&gt;

&lt;p&gt;The actual problem had nothing to do with my code. It was the &lt;strong&gt;file encoding&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Windows PowerShell 5.1 (the default &lt;code&gt;powershell.exe&lt;/code&gt;, not &lt;code&gt;pwsh&lt;/code&gt;) does not assume UTF-8 when it reads a &lt;code&gt;.ps1&lt;/code&gt; 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 &lt;em&gt;at parse time&lt;/em&gt;, before a single line ran. The regex literal that was supposed to be &lt;code&gt;코드.?리뷰&lt;/code&gt; 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.&lt;/p&gt;

&lt;p&gt;The fix is one line, once you know:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="kr"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;Add-Bom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nv"&gt;$text&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;System.IO.File&lt;/span&gt;&lt;span class="p"&gt;]::&lt;/span&gt;&lt;span class="n"&gt;ReadAllText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nv"&gt;$enc&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;New-Object&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;System.Text.UTF8Encoding&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;$true&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="c"&gt;# $true = write the BOM&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;System.IO.File&lt;/span&gt;&lt;span class="p"&gt;]::&lt;/span&gt;&lt;span class="n"&gt;WriteAllText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$enc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;Add-Bom&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$&lt;/span&gt;&lt;span class="nn"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;USERPROFILE&lt;/span&gt;&lt;span class="s2"&gt;\.claude\skill-router.ps1"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;PreToolUse safety hook&lt;/strong&gt; that stops Claude before it runs &lt;code&gt;rm -rf /&lt;/code&gt;, &lt;code&gt;DROP TABLE&lt;/code&gt;, &lt;code&gt;git push --force&lt;/code&gt;, &lt;code&gt;taskkill&lt;/code&gt;, 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 &lt;code&gt;--hard&lt;/code&gt; reset I didn't mean to approve.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;keyword router&lt;/strong&gt; above, but as a documented template instead of my personal 400-line wall of rules. The value isn't my rules — you'll never have my skills installed — it's the pattern plus the encoding gotchas already solved.&lt;/li&gt;
&lt;li&gt;A tiny &lt;strong&gt;regression test harness&lt;/strong&gt; for the router, because the day you add one rule above another and quietly break three existing ones is a bad day. It also has the one reliable way I found to pipe non-ASCII JSON into a child PowerShell without mojibake (&lt;code&gt;chcp 65001&lt;/code&gt; + a temp file + stdin redirect — don't ask how long that took either).&lt;/li&gt;
&lt;li&gt;A handful of subagent definitions I actually use (reviewer, tester, a couple of stack-specific ones).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I put it all up here, MIT, free: &lt;strong&gt;&lt;a href="https://github.com/coding-jhj/claude-pwsh-kit" rel="noopener noreferrer"&gt;https://github.com/coding-jhj/claude-pwsh-kit&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

</description>
      <category>claude</category>
      <category>powershell</category>
      <category>windows</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
