<?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: maxisbusy-beep</title>
    <description>The latest articles on DEV Community by maxisbusy-beep (@maxisbusybeep).</description>
    <link>https://dev.to/maxisbusybeep</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4257240%2Fb7ee15a9-8990-466f-8c55-6b53bc1a19f9.png</url>
      <title>DEV Community: maxisbusy-beep</title>
      <link>https://dev.to/maxisbusybeep</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/maxisbusybeep"/>
    <language>en</language>
    <item>
      <title>Your Claude Code hooks might not be firing on Windows. Here's the 10-second check.</title>
      <dc:creator>maxisbusy-beep</dc:creator>
      <pubDate>Sat, 21 Nov 2026 11:37:01 +0000</pubDate>
      <link>https://dev.to/maxisbusybeep/your-claude-code-hooks-might-not-be-firing-on-windows-heres-the-10-second-check-48m0</link>
      <guid>https://dev.to/maxisbusybeep/your-claude-code-hooks-might-not-be-firing-on-windows-heres-the-10-second-check-48m0</guid>
      <description>&lt;p&gt;Claude Code hooks are the only programmable stop between an agent and a destructive command. Permission prompts catch some of it, but hooks are the part you write yourself — which means they are also the part that can be quietly wrong.&lt;/p&gt;

&lt;p&gt;On Windows, quietly wrong is the normal failure mode. Not an error. Nothing. The hook never fires, or it fires under a shell that cannot run it, and Claude carries on exactly as if you had configured nothing. You find out when something gets deleted.&lt;/p&gt;

&lt;h2&gt;
  
  
  The 10-second check
&lt;/h2&gt;

&lt;p&gt;Before anything else, look at your matcher:&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="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Content&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;claude&lt;/span&gt;\&lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Raw&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nc"&gt;ConvertFrom&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Json&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="k"&gt;ForEach&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;$_&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hooks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PreToolUse&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nc"&gt;Select&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;matcher&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a matcher meant to guard shell commands says &lt;code&gt;Bash&lt;/code&gt; and not &lt;code&gt;Bash|PowerShell&lt;/code&gt;, keep reading — that one is live right now and doing less than you think.&lt;/p&gt;

&lt;p&gt;Three traps worth knowing about, whether or not you use any of this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 1: &lt;code&gt;"matcher": "Bash"&lt;/code&gt; does not cover the PowerShell tool
&lt;/h2&gt;

&lt;p&gt;On Windows, Claude Code can run commands through a &lt;strong&gt;separate PowerShell tool&lt;/strong&gt;, not only the Bash tool. The matcher is tested against the tool's name, so a &lt;code&gt;PreToolUse&lt;/code&gt; hook matched on &lt;code&gt;Bash&lt;/code&gt; never sees those calls.&lt;/p&gt;

&lt;p&gt;Which means this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"PreToolUse"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"matcher"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Bash"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"..."&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;…routes nothing to your hook when the agent reaches for PowerShell. Every rule you wrote for &lt;code&gt;Remove-Item -Recurse&lt;/code&gt;, &lt;code&gt;rd /s&lt;/code&gt;, &lt;code&gt;del&lt;/code&gt; or &lt;code&gt;format C:&lt;/code&gt; is unreachable. The script is fine. The regex is fine. Nothing ever calls it.&lt;/p&gt;

&lt;p&gt;The matcher takes a pipe-separated list of tool names, so the fix is one word longer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"matcher"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Bash|PowerShell"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This bug shipped in v1.0.0 of my own hook pack. The script had patterns for all four of those PowerShell commands, every one of them covered by a passing test, sitting behind a matcher that could never deliver a PowerShell call to them. The tests passed because they invoked the script directly. The wiring was never tested at all.&lt;/p&gt;

&lt;p&gt;That is the real lesson, and I will come back to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 2: shell form vs exec form
&lt;/h2&gt;

&lt;p&gt;The usual way to write a PowerShell hook is shell form — one command string:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"powershell -NoProfile -ExecutionPolicy Bypass -File \"${CLAUDE_PROJECT_DIR}/.claude/hooks/block.ps1\""&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That works, but it has two sharp edges: it goes through a shell — Git Bash on Windows, or PowerShell when Git Bash is not installed — so you have taken on a dependency you did not ask for, and you are trusting quoting to survive a project path with a space in it.&lt;/p&gt;

&lt;p&gt;Exec form avoids both. Set &lt;code&gt;args&lt;/code&gt;, and each element is passed as one argument with no shell quoting at all:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"powershell.exe"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"args"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s2"&gt;"-NoProfile"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"-ExecutionPolicy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"Bypass"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"-File"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"${CLAUDE_PROJECT_DIR}/.claude/hooks/block.ps1"&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"timeout"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;${CLAUDE_PROJECT_DIR}&lt;/code&gt; is substituted into each &lt;code&gt;args&lt;/code&gt; element before launch, so &lt;code&gt;C:\My Projects\thing&lt;/code&gt; cannot split into two arguments. No shell involved, and no Git Bash requirement for the hook.&lt;/p&gt;

&lt;p&gt;One gotcha: if you set &lt;code&gt;args&lt;/code&gt;, the &lt;code&gt;shell&lt;/code&gt; key is ignored. Pick one form and commit to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 3: the contract is exit codes, and nothing reminds you
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;PreToolUse&lt;/code&gt; hook speaks by exiting:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Exit&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Block.&lt;/strong&gt; Your stderr becomes the message Claude sees.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;0&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;No verdict. Normal permission flow continues — &lt;code&gt;0&lt;/code&gt; does &lt;em&gt;not&lt;/em&gt; approve the call.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;anything else&lt;/td&gt;
&lt;td&gt;Non-blocking error. &lt;strong&gt;The action goes ahead.&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That last row is the trap. A PowerShell script that throws an unhandled exception exits non-zero-and-not-2, and the dangerous command &lt;strong&gt;proceeds&lt;/strong&gt;. Your safety hook fails open at precisely the moment you needed it.&lt;/p&gt;

&lt;p&gt;Which means the whole body belongs inside the guard, not just the parsing. An exception thrown &lt;em&gt;after&lt;/em&gt; a &lt;code&gt;try&lt;/code&gt;/&lt;code&gt;catch&lt;/code&gt; that only wraps &lt;code&gt;ConvertFrom-Json&lt;/code&gt; puts you right back in the fail-open case:&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="nv"&gt;$ErrorActionPreference&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Stop'&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$raw&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;In&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReadToEnd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nv"&gt;$data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$raw&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nc"&gt;ConvertFrom&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Json&lt;/span&gt;
    &lt;span class="nv"&gt;$command&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tool_input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;command&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;IsNullOrWhiteSpace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$command&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;# Deliberately spares --force-with-lease: it is the safe one,&lt;/span&gt;
        &lt;span class="c1"&gt;# and blocking it is how you get your own hook deleted.&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$command&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt; &lt;span class="s1"&gt;'(?i)\bgit\s+push\b.*\s(--force|-f)(\s|$)'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"BLOCKED by hook: force push. Command: $command"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;exit&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;# Unreadable payload, or any unexpected throw: exit 0 rather than a&lt;/span&gt;
    &lt;span class="c1"&gt;# random code. A broken hook must not freeze your work -- but know&lt;/span&gt;
    &lt;span class="c1"&gt;# this means it fails OPEN. Choose it on purpose.&lt;/span&gt;
    &lt;span class="k"&gt;exit&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;exit&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fail-open versus fail-closed is a real decision with no free answer. Fail-closed on a malformed payload means one bad message bricks your session; fail-open means a crash disarms your guardrail. This pack fails open, and says so in its README. The point is choosing, not the choice.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to actually test this
&lt;/h2&gt;

&lt;p&gt;The payload arrives on &lt;strong&gt;stdin as JSON&lt;/strong&gt;, which means you can test a hook properly with no agent involved:&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="s1"&gt;'{"tool_name":"Bash","tool_input":{"command":"git push --force origin main"}}'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="n"&gt;powershell&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;NoProfile&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ExecutionPolicy&lt;/span&gt; &lt;span class="nc"&gt;Bypass&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;File&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;claude&lt;/span&gt;\&lt;span class="n"&gt;hooks&lt;/span&gt;\&lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;span class="s2"&gt;"exit=$LASTEXITCODE"&lt;/span&gt;   &lt;span class="c1"&gt;# expect 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wrap that in a loop over a table of cases and you have a real suite. Two things most people miss:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test the allows, not just the blocks.&lt;/strong&gt; A rule that blocks &lt;code&gt;git push --force-with-lease&lt;/code&gt;, or &lt;code&gt;rm -rf ./dist&lt;/code&gt;, is worse than no rule — the first time it gets in your way you will disable the whole file, and then you have nothing. Assert exit 0 on everything that must be permitted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test the wiring, not just the scripts.&lt;/strong&gt; This is Trap 1 again. Read your own &lt;code&gt;settings.json&lt;/code&gt; in the suite and assert properties of it:&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="nv"&gt;$settings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Content&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;claude&lt;/span&gt;\&lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Raw&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nc"&gt;ConvertFrom&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Json&lt;/span&gt;
&lt;span class="nv"&gt;$cmdGroup&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; @&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$settings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hooks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PreToolUse&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
    &lt;span class="nc"&gt;Where&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;$_&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;matcher&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt; &lt;span class="s1"&gt;'Bash'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nc"&gt;Select&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;First&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="c1"&gt;# The case that would have caught my bug:&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$cmdGroup&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;matcher&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;notmatch&lt;/span&gt; &lt;span class="s1"&gt;'PowerShell'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="s2"&gt;"matcher does not cover the PowerShell tool"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;# And: every referenced script exists, every handler sets a timeout,&lt;/span&gt;
&lt;span class="c1"&gt;# every handler uses exec form.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A passing script behind a broken matcher is the failure mode that looks most like success. That is the one worth a test.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checklist
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Every command matcher is &lt;code&gt;Bash|PowerShell&lt;/code&gt;, not &lt;code&gt;Bash&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Hooks use exec form — &lt;code&gt;command&lt;/code&gt; plus &lt;code&gt;args&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Every hook sets a &lt;code&gt;timeout&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Every code path exits 0 or 2 deliberately, error paths included.&lt;/li&gt;
&lt;li&gt;Tests cover blocks, allows, &lt;strong&gt;and&lt;/strong&gt; the &lt;code&gt;settings.json&lt;/code&gt; wiring.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/hooks&lt;/code&gt; in a live session lists every matcher you expect to see. If one is missing, it is not loaded.&lt;/li&gt;
&lt;li&gt;Then actually trigger one. Ask Claude to run something your hook should block and watch for your own &lt;code&gt;BLOCKED&lt;/code&gt; message. A hook that has never fired in anger is a hypothesis.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Trap 1 takes ten seconds to check and it is the one that silently voids everything else.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;The hook and self-test from this article are on GitHub under MIT, free: &lt;a href="https://github.com/maxisbusy-beep/claude-code-windows-guardrails-lite" rel="noopener noreferrer"&gt;https://github.com/maxisbusy-beep/claude-code-windows-guardrails-lite&lt;/a&gt; — clone it and run the suite in a minute. I also sell a fuller Windows pack (three hooks, two subagents, two skills, an installer, a 74-case suite) for $29: &lt;a href="https://maxibee4.gumroad.com/l/claude-code-windows-guardrails" rel="noopener noreferrer"&gt;https://maxibee4.gumroad.com/l/claude-code-windows-guardrails&lt;/a&gt;. Everything in this article works without it.&lt;/em&gt;&lt;/p&gt;

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