<?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: Vladyslav Koshelyev</title>
    <description>The latest articles on DEV Community by Vladyslav Koshelyev (@kriatiz).</description>
    <link>https://dev.to/kriatiz</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%2F4265288%2Fa8d71e9d-c41c-47d9-8d27-5fdb06a24e45.jpg</url>
      <title>DEV Community: Vladyslav Koshelyev</title>
      <link>https://dev.to/kriatiz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kriatiz"/>
    <language>en</language>
    <item>
      <title>Claude Code Hooks: 10 Ready-Made Recipes — Guardrails, Auto-Format, Tests, Telegram Alerts</title>
      <dc:creator>Vladyslav Koshelyev</dc:creator>
      <pubDate>Wed, 25 Nov 2026 17:46:16 +0000</pubDate>
      <link>https://dev.to/kriatiz/claude-code-hooks-10-ready-made-recipes-guardrails-auto-format-tests-telegram-alerts-3j5g</link>
      <guid>https://dev.to/kriatiz/claude-code-hooks-10-ready-made-recipes-guardrails-auto-format-tests-telegram-alerts-3j5g</guid>
      <description>&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; a hook is your script that Claude Code runs on a specific event — before a command, after a file edit, when a turn ends. The key difference from CLAUDE.md instructions: hooks fire &lt;strong&gt;every time&lt;/strong&gt;. The model can forget “don’t touch .env”; a hook can’t. Here’s how hooks work and 10 recipes I’ve tested and use.&lt;/p&gt;

&lt;h2&gt;
  
  
  How hooks work
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5lohr2crju1flhkcm3vh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5lohr2crju1flhkcm3vh.png" alt="Claude Code hook events across a session" width="799" height="293"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Event&lt;/th&gt;
&lt;th&gt;When&lt;/th&gt;
&lt;th&gt;Typical use&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SessionStart&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;session starts or resumes&lt;/td&gt;
&lt;td&gt;inject git state, the current ticket&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;UserPromptSubmit&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;you send a prompt&lt;/td&gt;
&lt;td&gt;check for secrets, add context&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PreToolUse&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;before a tool call&lt;/td&gt;
&lt;td&gt;block danger, require confirmation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PostToolUse&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;after a tool call&lt;/td&gt;
&lt;td&gt;format, lint, log&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Notification&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Claude needs your input&lt;/td&gt;
&lt;td&gt;desktop or Telegram alert&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Stop&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Claude finishes its turn&lt;/td&gt;
&lt;td&gt;run tests, send a summary&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PreCompact&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;before context compaction&lt;/td&gt;
&lt;td&gt;back up the transcript&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;There are 30+ events in total — from subagent lifecycle to model switches — but these seven cover 90% of real use.&lt;/p&gt;

&lt;h2&gt;
  
  
  How a hook talks to Claude Code
&lt;/h2&gt;

&lt;p&gt;Claude Code sends event data as JSON on stdin: tool name, command, file path, your prompt. The hook answers with an exit code and, optionally, JSON on stdout.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foe319gw3y5fvktlcl6fx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foe319gw3y5fvktlcl6fx.png" alt="Claude Code hook exit codes" width="800" height="307"&gt;&lt;/a&gt;&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;"hook_event_name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"PreToolUse"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"tool_name"&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;"tool_input"&lt;/span&gt;&lt;span class="p"&gt;:&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;"git push origin main --force"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"cwd"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"/home/me/projects/app"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"session_id"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For fine-grained control, return JSON — for example, deny with an explanation:&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;"hookSpecificOutput"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"hookEventName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"PreToolUse"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"permissionDecision"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"deny"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"permissionDecisionReason"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Writes to the production database are not allowed"&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;Decisions: &lt;code&gt;allow&lt;/code&gt;, &lt;code&gt;deny&lt;/code&gt;, &lt;code&gt;ask&lt;/code&gt;. When several hooks disagree, the strictest wins.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Common mistake:&lt;/strong&gt; &lt;code&gt;additionalContext&lt;/code&gt; must sit inside &lt;code&gt;hookSpecificOutput&lt;/code&gt; — at the top level it’s silently ignored. And stdout must contain only the JSON; a stray debug &lt;code&gt;echo&lt;/code&gt; breaks parsing.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Where hooks are configured
&lt;/h2&gt;

&lt;p&gt;In the same settings files as permissions: &lt;code&gt;~/.claude/settings.json&lt;/code&gt;, &lt;code&gt;.claude/settings.json&lt;/code&gt; or &lt;code&gt;.claude/settings.local.json&lt;/code&gt;. Three levels: event → matcher → handlers.&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;"${CLAUDE_PROJECT_DIR}/.claude/hooks/block-dangerous.sh"&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;&lt;strong&gt;matcher&lt;/strong&gt; targets tools: &lt;code&gt;Bash&lt;/code&gt;, &lt;code&gt;Edit|Write&lt;/code&gt;, &lt;code&gt;mcp__github__.*&lt;/code&gt; (every tool of an MCP server — the &lt;code&gt;.*&lt;/code&gt; is required). Empty or &lt;code&gt;"*"&lt;/code&gt; matches all. Check what’s active with &lt;code&gt;/hooks&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  10 ready-made recipes
&lt;/h2&gt;

&lt;p&gt;All scripts are in my open-source &lt;a href="https://github.com/Gunner91/claude-code-kit" rel="noopener noreferrer"&gt;claude-code-kit on GitHub&lt;/a&gt; with a ready &lt;code&gt;settings.hooks.example.json&lt;/code&gt;. I tested each against real inputs: it blocks what it should and stays out of the way otherwise. They use &lt;code&gt;jq&lt;/code&gt;, falling back to Python if it’s missing.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Block dangerous commands (PreToolUse · Bash)
&lt;/h3&gt;

&lt;p&gt;Stops &lt;code&gt;rm -rf /&lt;/code&gt;, &lt;code&gt;git push --force&lt;/code&gt;, &lt;code&gt;git reset --hard&lt;/code&gt;, &lt;code&gt;DROP TABLE&lt;/code&gt; and &lt;code&gt;curl | bash&lt;/code&gt; installs. Claude sees the stderr message and proposes a safer alternative.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;cmd&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$(j .tool_input.command)"&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s'&lt;/span&gt; &lt;span class="s2"&gt;"$cmd"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; grep -Eiq &lt;span class="s1"&gt;'git[[:space:]]+push[[:space:]].*--force'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Blocked: force push is not allowed. Ask the user."&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
  &lt;span class="nb"&gt;exit&lt;/span&gt; 2
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Protect files (PreToolUse · Edit|Write)
&lt;/h3&gt;

&lt;p&gt;Prevents edits to &lt;code&gt;.env&lt;/code&gt;, lock files, &lt;code&gt;.git/&lt;/code&gt; and keys, including Windows-style paths. This guards the edit tools — also deny secret paths in your permission rules.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Auto-format (PostToolUse · Edit|Write)
&lt;/h3&gt;

&lt;p&gt;Runs Prettier, Black, gofmt or php-cs-fixer — whichever is installed — after every edit. Never fails the edit.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Command audit log (PostToolUse · Bash)
&lt;/h3&gt;

&lt;p&gt;Appends every command the agent runs, with time and folder, to &lt;code&gt;~/.claude/command-log.txt&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Desktop notification (Notification)
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;osascript&lt;/code&gt; on macOS, &lt;code&gt;notify-send&lt;/code&gt; on Linux, and a separate &lt;code&gt;.ps1&lt;/code&gt; for Windows — so you can step away while Claude works.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Telegram alerts (Notification + Stop)
&lt;/h3&gt;

&lt;p&gt;My favourite: long task running, and Telegram pings you with “needs your input” or “✅ done” plus a short summary. Two environment variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;CLAUDE_TG_TOKEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"123456:ABC..."&lt;/span&gt;   &lt;span class="c"&gt;# bot token from @BotFather&lt;/span&gt;
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;CLAUDE_TG_CHAT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"123456789"&lt;/span&gt;        &lt;span class="c"&gt;# your chat id (ask @userinfobot)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  7. Git context at start (SessionStart)
&lt;/h3&gt;

&lt;p&gt;Claude immediately knows the branch, uncommitted files and recent commits. For &lt;code&gt;SessionStart&lt;/code&gt;, plain stdout is added to the context.&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Secret-leak guard (UserPromptSubmit)
&lt;/h3&gt;

&lt;p&gt;Paste an API key (OpenAI, AWS, GitHub, Slack, Telegram bot) or a private key into a prompt by accident, and the hook blocks it before it reaches the model or the transcript:&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;"decision"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"block"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"reason"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Your prompt looks like it contains a secret key..."&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  9. Tests before stopping (Stop)
&lt;/h3&gt;

&lt;p&gt;When Claude is about to finish, the hook runs your tests (&lt;code&gt;TEST_CMD&lt;/code&gt;, default &lt;code&gt;npm test&lt;/code&gt;). If they fail it returns &lt;code&gt;"decision": "block"&lt;/code&gt; with the failure output, and Claude keeps fixing. It checks &lt;code&gt;stop_hook_active&lt;/code&gt; to avoid infinite loops and only runs when the repo has changes.&lt;/p&gt;

&lt;h3&gt;
  
  
  10. Backup before compaction (PreCompact)
&lt;/h3&gt;

&lt;p&gt;Saves the full transcript to &lt;code&gt;~/.claude/transcript-backups/&lt;/code&gt; before &lt;code&gt;/compact&lt;/code&gt; — handy if a detail gets lost in the summary.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install the pack
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cp -r claude-code-hooks/.claude/hooks .claude/
chmod +x .claude/hooks/*.sh
&lt;span class="c"&gt;# merge the blocks you want from settings.hooks.example.json into .claude/settings.json&lt;/span&gt;
/hooks
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Start with three:&lt;/strong&gt; dangerous-command blocking, file protection and notifications. Enable tests-before-stop once your test suite is fast. The default command timeout is 10 minutes; set &lt;code&gt;timeout&lt;/code&gt; (seconds) per hook.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Debugging hooks
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Symptom&lt;/th&gt;
&lt;th&gt;Check&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Hook doesn’t fire&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;/hooks&lt;/code&gt;; the &lt;code&gt;matcher&lt;/code&gt;; &lt;code&gt;chmod +x&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;“JSON validation failed”&lt;/td&gt;
&lt;td&gt;stdout must contain only JSON; send debug output to stderr.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Block doesn’t block&lt;/td&gt;
&lt;td&gt;Use exit code 2. Exit 1 is a non-blocking hook error.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Stop hook loops&lt;/td&gt;
&lt;td&gt;Exit early when &lt;code&gt;stop_hook_active&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Nothing works on Windows&lt;/td&gt;
&lt;td&gt;Install Git for Windows (Git Bash) or use the &lt;code&gt;.ps1&lt;/code&gt; variants via &lt;code&gt;powershell.exe -File&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;p&gt;Hooks turn wishes into guarantees: safety, formatting and alerts stop depending on whether the model remembers. Set up 3–4 once and reuse them everywhere. See also &lt;a href="https://kriatiz.com/en/blog/claude-code-subagents/" rel="noopener noreferrer"&gt;subagents&lt;/a&gt; and &lt;a href="https://kriatiz.com/en/blog/claude-code-skills/" rel="noopener noreferrer"&gt;skills&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What are hooks in Claude Code?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Scripts Claude Code runs automatically on events: before a tool call (PreToolUse), after it (PostToolUse), at session start, when a turn ends (Stop) and more. Unlike instructions, hooks always run.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How do I block an action with a hook?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Exit with code 2 and write the reason to stderr, or return JSON with permissionDecision: "deny". Exit code 1 does not block.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where are hooks configured?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the hooks section of ~/.claude/settings.json, .claude/settings.json or .claude/settings.local.json. List active hooks with /hooks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do hooks work on Windows?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes — easiest with Git for Windows (Git Bash). You can also write hooks in PowerShell and call them with powershell.exe -File.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on my blog at &lt;a href="https://kriatiz.com/en/blog/claude-code-hooks/" rel="noopener noreferrer"&gt;kriatiz.com&lt;/a&gt;. This article was written with the help of AI and reviewed by me; the hook scripts were tested against real inputs.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>ai</category>
      <category>productivity</category>
      <category>devtools</category>
    </item>
  </channel>
</rss>
