Independent directory of the Claude Code skills, MCP servers & marketplaces worth installing. 86,000+ tools indexed daily, ranked by real installs. Not affiliated with Anthropic.
Replaying the rules over 24,374 old commands before trusting them is the step most hook write-ups skip, and the drop from 587 hits to 181 shows why it matters. You say the hook returns the reason and the fix. Is that exit code 2 with the text on stderr? For a PreToolUse hook, Claude Code feeds that stderr back to the model, so the agent can retry with single quotes or a file for the py -3 -c body instead of stopping cold. We would be curious how many of the 7 got a working retry on the next turn and how many needed you.
Yes. Both hooks write the reason and the fix to stderr and exit with code 2, and Claude Code passes that text back to the model as the result of the blocked call.
I hadn't counted the retries, so I went back to the session logs for those 7 blocks. Every one was followed by a working command within 3 to 12 seconds, with no message from me in between:
6 of 7 worked on the very next call, mostly by doing what the message suggested: the backtick cases moved the Python into a file, and the PowerShell $_ case moved the command into a .ps1 file.
1 took two tries. It first switched to single quotes, which broke the WMI filter's own quoting, and then wrote a .ps1 file, which worked.
So none of the 7 needed me. "Working" here means the next command ran and returned the output it was after; I read each pair, but it's 7 cases on one PC, so I wouldn't read much into the rate.
I build VibeDesk, a free, open-source Windows app around Claude Code that shows which session needs you. I write about hooks, canvas and the bugs I measure on the way.
Replaying the rules over old commands before trusting them is the part I'd copy. A related trap sits on the hook entry itself rather than the commands it checks: if a hook runs inline PowerShell, Git Bash expands the $ before PowerShell sees it, same family as your ps-dollar-in-bash-dq rule. The exec form (command plus an args array, pointing at a .ps1 file) skips the shell entirely. I also keep those scripts ASCII-only, because Windows PowerShell 5.1 reads a file without a BOM as ANSI, and one typographic dash inside a string was enough to break the parse for me. Are your hooks in shell form or exec form?
Shell form, but nothing in the hook entry gets expanded. Each entry is just node with a quoted path to a .mjs file, e.g. node "C:/Users//.claude/hooks/pitfall-guard.mjs", and the command to check arrives as JSON on stdin. So no inline PowerShell, and no $ for Git Bash to touch. Thanks for the BOM tip; my scripts are JavaScript with Japanese text in them, which Node reads as UTF-8 without trouble, but it's worth keeping in mind for any .ps1.
I build VibeDesk, a free, open-source Windows app around Claude Code that shows which session needs you. I write about hooks, canvas and the bugs I measure on the way.
That's the safe version, nothing left for Bash to expand. The part I didn't expect is what the shell itself costs per call. I timed one hook on Windows: the program alone took 16 ms, through Git Bash 42 ms, through cmd /c 45 ms, and through PowerShell 418 ms. Shell form goes through Git Bash every time, so the exec form ("command": "node" plus the .mjs path in "args") would drop roughly 25 ms from each of your 8,522 calls. Node's own startup is probably most of your 0.1 s, though.
Thanks for timing it. All I have is the total, about 0.1 s per check, so I can't say how much of it is Node's startup and how much is the shell. That's worth timing before I change anything.
Running the rules against commands from past sessions is the part worth copying. Going from 587 hits to 181 shows that a hook is only as useful as its false-positive rate, since noisy blocks tend to get switched off. One addition: keep the replayed commands as a small must-block and must-allow list and re-run it whenever you edit a rule, so a tweak that quiets a noisy pattern doesn't quietly reopen the original hole.
Agreed, and that's roughly what I ended up with. The forms the replay showed didn't need blocking (heredoc bodies, git stash push, a for-loop variable passed to wsl) became must-allow cases, next to the must-block ones. There are 77 examples now, and I run them before installing any rule change. The full replay is a separate option on the same test script.
I research AI tools, APIs & agents — comparing specs, pricing and real user reports — then publish honest rankings so you don't waste money. Research-first, never sponsored fluff.
1,123 nested bash processes is the kind of number that makes you laugh and then immediately check your own setup. The line that stuck with me is 'writing a rule down isn't enough when someone's in a hurry' — that's true of humans too, not just agents, and it's why the hook-before-execution approach feels right. The replay tuning is the part I'd copy though: 587 hits down to 181 by letting through the forms that didn't need blocking. Did the 10-second timeout blocks ever bite you on a legitimately slow command, or has that been quiet so far?
The 10 seconds is a limit on the hook, not on the command, so a slow command never runs into it: the hook only reads the command string and answers before the command starts. It has fired 5 times in those 13 days, each time because the hook itself didn't finish within 10 seconds. I haven't looked into why those particular calls were slow. The command was blocked without running. In 4 of the 5 the session ran it again, or a simpler version of it, on its next call and it went through; in the other it moved on to a different check. Since the article's 13 days it has happened twice more, back to back in one session: the second call was a smaller command, and when it was blocked too, the same smaller command went through on the next call. So it has cost a retry now and then, but nothing has been lost so far.
I measure AI coding claims in public. LGTM — Let's Get the Measurements: real runs, real numbers, receipts. Every article is an experiment I actually ran. Books & packs: aheadkit.gumroad.com
The notes part is what got me. You had the mistake written down, the list was right there for every one of them to read, and it still happened, because reading is not the same as stopping. I hit the same wall from the other side: my agent kept fixing things nobody asked it to fix, renaming a function here, rewriting a file to fix one line there, and I spent the afternoon undoing the extra work. Writing the rule down helped, but only once the rule said exactly what "done" means. The one I reach for first says change the smallest amount of code that fixes the problem properly, not the smallest amount that makes the test pass. One change, one reason. A bug fix does not also rename variables. I tried it on three small demo projects before trusting it, and the clearest before and after was a Node program that used to die on a missing config file with a raw stack dump and now exits with one plain sentence naming the problem and the fix. The full rule is free to read if it helps: aheadkit.me/free-samples/lean-code...
Which of your nine rules was the hardest to tune without it blocking real work? The listening-port one at 129 hits looks like the one that would have driven me mad.
I never changed the listen-state rule itself. Its 129 hits weren't false alarms: they were sessions really checking a server with the method that comes back empty on this PC. In the 13 days I counted, sessions let it through 3 times with # pitfall-ok, when they meant to use it. The tuning was about forms that didn't need blocking at all, across the rules: heredoc bodies, git stash push, rm -rf with a variable assigned just before it, and a for variable passed to wsl. It's ten rules now; the tenth blocks Windows paths with backslashes inside sed or Python strings.
Moving known mistakes out of the notes and into something that runs before the command is the step most people never take: a note is advice the agent can skip. "I can't count how often a session avoided a mistake because it had read the rule" is honest, and it's the right limit to name. The next thing we'd want is for the list to travel. In Halfcycle the cause and the fix from one project reach every other project automatically, so most of these never show up again and the rest arrive with the answer attached. If you try npx halfcycle on a Windows project, we'd like to know what it misses that your ten rules catch.
Agreed. Mine are four lines each: what matched and why it's a problem, the fix, and then either the # pitfall-ok way through or, in the backtick hook, a line about the original accident. That last one I could probably drop.
Replaying the rules over 24,374 old commands before trusting them is the step most hook write-ups skip, and the drop from 587 hits to 181 shows why it matters. You say the hook returns the reason and the fix. Is that exit code 2 with the text on stderr? For a PreToolUse hook, Claude Code feeds that stderr back to the model, so the agent can retry with single quotes or a file for the
py -3 -cbody instead of stopping cold. We would be curious how many of the 7 got a working retry on the next turn and how many needed you.Yes. Both hooks write the reason and the fix to stderr and exit with code 2, and Claude Code passes that text back to the model as the result of the blocked call.
I hadn't counted the retries, so I went back to the session logs for those 7 blocks. Every one was followed by a working command within 3 to 12 seconds, with no message from me in between:
$_case moved the command into a .ps1 file.So none of the 7 needed me. "Working" here means the next command ran and returned the output it was after; I read each pair, but it's 7 cases on one PC, so I wouldn't read much into the rate.
Replaying the rules over old commands before trusting them is the part I'd copy. A related trap sits on the hook entry itself rather than the commands it checks: if a hook runs inline PowerShell, Git Bash expands the $ before PowerShell sees it, same family as your ps-dollar-in-bash-dq rule. The exec form (command plus an args array, pointing at a .ps1 file) skips the shell entirely. I also keep those scripts ASCII-only, because Windows PowerShell 5.1 reads a file without a BOM as ANSI, and one typographic dash inside a string was enough to break the parse for me. Are your hooks in shell form or exec form?
Shell form, but nothing in the hook entry gets expanded. Each entry is just node with a quoted path to a .mjs file, e.g. node "C:/Users//.claude/hooks/pitfall-guard.mjs", and the command to check arrives as JSON on stdin. So no inline PowerShell, and no $ for Git Bash to touch. Thanks for the BOM tip; my scripts are JavaScript with Japanese text in them, which Node reads as UTF-8 without trouble, but it's worth keeping in mind for any .ps1.
That's the safe version, nothing left for Bash to expand. The part I didn't expect is what the shell itself costs per call. I timed one hook on Windows: the program alone took 16 ms, through Git Bash 42 ms, through cmd /c 45 ms, and through PowerShell 418 ms. Shell form goes through Git Bash every time, so the exec form ("command": "node" plus the .mjs path in "args") would drop roughly 25 ms from each of your 8,522 calls. Node's own startup is probably most of your 0.1 s, though.
Thanks for timing it. All I have is the total, about 0.1 s per check, so I can't say how much of it is Node's startup and how much is the shell. That's worth timing before I change anything.
Running the rules against commands from past sessions is the part worth copying. Going from 587 hits to 181 shows that a hook is only as useful as its false-positive rate, since noisy blocks tend to get switched off. One addition: keep the replayed commands as a small must-block and must-allow list and re-run it whenever you edit a rule, so a tweak that quiets a noisy pattern doesn't quietly reopen the original hole.
Agreed, and that's roughly what I ended up with. The forms the replay showed didn't need blocking (heredoc bodies, git stash push, a for-loop variable passed to wsl) became must-allow cases, next to the must-block ones. There are 77 examples now, and I run them before installing any rule change. The full replay is a separate option on the same test script.
1,123 nested bash processes is the kind of number that makes you laugh and then immediately check your own setup. The line that stuck with me is 'writing a rule down isn't enough when someone's in a hurry' — that's true of humans too, not just agents, and it's why the hook-before-execution approach feels right. The replay tuning is the part I'd copy though: 587 hits down to 181 by letting through the forms that didn't need blocking. Did the 10-second timeout blocks ever bite you on a legitimately slow command, or has that been quiet so far?
The 10 seconds is a limit on the hook, not on the command, so a slow command never runs into it: the hook only reads the command string and answers before the command starts. It has fired 5 times in those 13 days, each time because the hook itself didn't finish within 10 seconds. I haven't looked into why those particular calls were slow. The command was blocked without running. In 4 of the 5 the session ran it again, or a simpler version of it, on its next call and it went through; in the other it moved on to a different check. Since the article's 13 days it has happened twice more, back to back in one session: the second call was a smaller command, and when it was blocked too, the same smaller command went through on the next call. So it has cost a retry now and then, but nothing has been lost so far.
The notes part is what got me. You had the mistake written down, the list was right there for every one of them to read, and it still happened, because reading is not the same as stopping. I hit the same wall from the other side: my agent kept fixing things nobody asked it to fix, renaming a function here, rewriting a file to fix one line there, and I spent the afternoon undoing the extra work. Writing the rule down helped, but only once the rule said exactly what "done" means. The one I reach for first says change the smallest amount of code that fixes the problem properly, not the smallest amount that makes the test pass. One change, one reason. A bug fix does not also rename variables. I tried it on three small demo projects before trusting it, and the clearest before and after was a Node program that used to die on a missing config file with a raw stack dump and now exits with one plain sentence naming the problem and the fix. The full rule is free to read if it helps: aheadkit.me/free-samples/lean-code...
Which of your nine rules was the hardest to tune without it blocking real work? The listening-port one at 129 hits looks like the one that would have driven me mad.
I never changed the listen-state rule itself. Its 129 hits weren't false alarms: they were sessions really checking a server with the method that comes back empty on this PC. In the 13 days I counted, sessions let it through 3 times with # pitfall-ok, when they meant to use it. The tuning was about forms that didn't need blocking at all, across the rules: heredoc bodies, git stash push, rm -rf with a variable assigned just before it, and a for variable passed to wsl. It's ten rules now; the tenth blocks Windows paths with backslashes inside sed or Python strings.
Moving known mistakes out of the notes and into something that runs before the command is the step most people never take: a note is advice the agent can skip. "I can't count how often a session avoided a mistake because it had read the rule" is honest, and it's the right limit to name. The next thing we'd want is for the list to travel. In Halfcycle the cause and the fix from one project reach every other project automatically, so most of these never show up again and the rest arrive with the answer attached. If you try npx halfcycle on a Windows project, we'd like to know what it misses that your ten rules catch.
A PreToolUse hook is a local check, so the rule itself costs no model tokens. What it prints back is what the model reads, so keep the message short.
Agreed. Mine are four lines each: what matched and why it's a problem, the fix, and then either the
# pitfall-okway through or, in the backtick hook, a line about the original accident. That last one I could probably drop.1,123 nested bash processes would have left my own PC with no memory to spare.