<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Hooks on Chen Kai Blog</title><link>https://www.chenk.top/en/tags/hooks/</link><description>Recent content in Hooks on Chen Kai Blog</description><generator>Hugo</generator><language>en</language><lastBuildDate>Fri, 24 Apr 2026 09:00:00 +0000</lastBuildDate><atom:link href="https://www.chenk.top/en/tags/hooks/index.xml" rel="self" type="application/rss+xml"/><item><title>Claude Code Hands-On (7): Ten Hooks I Actually Use, with the Code</title><link>https://www.chenk.top/en/claude-code-learn/07-hooks-deep-dive/</link><pubDate>Fri, 24 Apr 2026 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/claude-code-learn/07-hooks-deep-dive/</guid><description>&lt;p>&lt;a href="https://www.chenk.top/en/claude-code-learn/05-hooks/">Chapter 5&lt;/a>
 provided a conceptual tour of hooks. This chapter is the field guide. From the 100-script reference repo, ten scripts earn their place in every serious project I run. I&amp;rsquo;ll walk through these ten with code.&lt;/p>
&lt;p>All examples assume Node 18+, save scripts to &lt;code>./hooks/&lt;/code>, mark them &lt;code>chmod +x&lt;/code>, and wire them in &lt;code>.claude/settings.json&lt;/code> like:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;hooks&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;PreToolUse&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span> &lt;span class="nt">&amp;#34;matcher&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;Read|Grep&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nt">&amp;#34;hooks&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[{&lt;/span> &lt;span class="nt">&amp;#34;type&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;command&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nt">&amp;#34;command&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;node ./hooks/block-env-read.js&amp;#34;&lt;/span> &lt;span class="p">}]&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Before we dive in, here&amp;rsquo;s the hook lifecycle to make the following code clear:&lt;/p></description></item><item><title>Claude Code Hands-On (5): Hooks, or How to Stop Worrying About Yolo Mode</title><link>https://www.chenk.top/en/claude-code-learn/05-hooks/</link><pubDate>Wed, 22 Apr 2026 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/claude-code-learn/05-hooks/</guid><description>&lt;p>If MCP is how Claude reaches out, hooks are how you reach in. They enforce the rules you care about, not just what you hope for.&lt;/p>
&lt;p>&lt;figure class="article-figure">
 &lt;img src="https://blog-pic-ck.oss-cn-beijing.aliyuncs.com/posts/en/claude-code-learn/05-hooks/illustration_1.png" alt="Claude Code Hands-On (5): Hooks, or How to Stop Worrying About Yolo Mode — Chapter overview" loading="lazy" decoding="async" class="content-image">
 
&lt;/figure>
&lt;/p>
&lt;hr>
&lt;h2 id="the-model" class="heading-anchor">The model&lt;a href="#the-model" class="heading-link" aria-label="Permalink to this section" title="Copy link to this section">#&lt;/a>
&lt;/h2>&lt;p>A hook is a shell command that Claude Code runs at specific moments. The two you&amp;rsquo;ll use most are:&lt;/p></description></item></channel></rss>