<?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 Simon Shine</title><link>https://simonshine.dk/tags/hooks/</link><description>Recent content in Hooks on Simon Shine</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Thu, 05 Nov 2026 11:19:29 +0200</lastBuildDate><atom:link href="https://simonshine.dk/tags/hooks/index.xml" rel="self" type="application/rss+xml"/><item><title>A gallery of hk-nix git hooks</title><link>https://simonshine.dk/articles/a-gallery-of-hk-nix-git-hooks/</link><pubDate>Thu, 05 Nov 2026 11:19:29 +0200</pubDate><guid>https://simonshine.dk/articles/a-gallery-of-hk-nix-git-hooks/</guid><description>&lt;p&gt;I&amp;rsquo;ve been obsessed with git commit hooks this year. Since discovering &lt;a href="https://simonshine.dk/articles/lefthook-treefmt-direnv-nix/"&gt;lefthook.nix&lt;/a&gt;
this year, and later replacing it with my own &lt;a href="https://simonshine.dk/articles/git-config-based-hooks-with-hk-nix/"&gt;hk-nix&lt;/a&gt; wrapper around hk, I&amp;rsquo;ve been enjoying
faster and less buggy commit hooks with support for git 2.54&amp;rsquo;s config-based hooks.&lt;/p&gt;
&lt;p&gt;This is a walkthrough of all the git hooks I&amp;rsquo;ve made this year. 36 of my repositories have a
&lt;code&gt;nix/hooks.nix&lt;/code&gt;. Every one of them started as a copy of the previous one, and then grew whatever
that project turned out to need.&lt;/p&gt;</description></item><item><title>hk-nix + ast-grep: Remove all comments</title><link>https://simonshine.dk/articles/hk-nix-ast-grep-remove-all-comments/</link><pubDate>Wed, 21 Oct 2026 14:10:00 +0200</pubDate><guid>https://simonshine.dk/articles/hk-nix-ast-grep-remove-all-comments/</guid><description>&lt;p&gt;Here&amp;rsquo;s a git pre-commit hook for removing all comments that relies on &lt;a href="https://simonshine.dk/articles/git-config-based-hooks-with-hk-nix/"&gt;hk-nix&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It enforces the removal of all source code comments besides certain doc comments, plus the one YAML
exception described below.&lt;/p&gt;
&lt;p&gt;In Rust, comments that begin with &lt;code&gt;///&lt;/code&gt; or &lt;code&gt;//!&lt;/code&gt;, for example.&lt;/p&gt;
&lt;p&gt;For a particular project, this addresses source code in Rust, Nix, YAML and shell scripts.&lt;/p&gt;
&lt;p&gt;The reason is that recent AI coding models obnoxiously litter all source code with excessive
thinking. One may wonder: Are these comments here to improve the context for when the coding agent
comes around another time, or do they only serve &lt;a href="https://www.anthropic.com/news/claude-text-watermark"&gt;watermarking mandated by the EU AI Act&lt;/a&gt;?&lt;/p&gt;</description></item><item><title>hk-nix and mdformat gotchas</title><link>https://simonshine.dk/articles/hk-nix-mdformat-gotchas/</link><pubDate>Sun, 27 Sep 2026 21:31:10 +0200</pubDate><guid>https://simonshine.dk/articles/hk-nix-mdformat-gotchas/</guid><description>&lt;p&gt;I run &lt;a href="https://mdformat.readthedocs.io/"&gt;mdformat&lt;/a&gt; as a pre-commit hook via &lt;a href="https://github.com/nix-tools/hk-nix"&gt;hk-nix&lt;/a&gt; and &lt;a href="https://github.com/numtide/treefmt-nix"&gt;treefmt-nix&lt;/a&gt;.
treefmt-nix runs over every markdown file in the tree and applies mdformat when it encounters .md
files.&lt;/p&gt;
&lt;p&gt;This is a collection of small gotchas.&lt;/p&gt;
&lt;p&gt;So far I&amp;rsquo;ve just got two.&lt;/p&gt;
&lt;h2 id="mdformat-destroys-yaml-frontmatter-by-default"&gt;
 mdformat destroys YAML frontmatter by default
 &lt;a class="heading-anchor" href="#mdformat-destroys-yaml-frontmatter-by-default" aria-label="Link to this section"&gt;&amp;para;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Both &lt;code&gt;SKILL.md&lt;/code&gt; files and Hugo static website content open with YAML frontmatter.&lt;/p&gt;
&lt;p&gt;It might look like:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-markdown" data-lang="markdown"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;---
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;name: email-admin
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;description: &amp;gt;-
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Administers MXroute email hosting through the mxroute MCP tools. [...]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;allowed-tools:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;-&lt;/span&gt; mcp__plugin_mxroute_mxroute__mxroute_list_domains
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;-&lt;/span&gt; mcp__plugin_mxroute_mxroute__mxroute_get_domain
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;license: MIT OR Apache-2.0
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;---
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Or like:&lt;/p&gt;</description></item><item><title>Git config-based hooks with hk-nix</title><link>https://simonshine.dk/articles/git-config-based-hooks-with-hk-nix/</link><pubDate>Sat, 01 Aug 2026 00:00:00 +0100</pubDate><guid>https://simonshine.dk/articles/git-config-based-hooks-with-hk-nix/</guid><description>&lt;p&gt;&lt;a href="https://hk.jdx.dev/"&gt;hk&lt;/a&gt; is a fast, modern git hook manager and project linter configured in &lt;a href="https://pkl-lang.org/"&gt;Pkl&lt;/a&gt;.
&lt;a href="https://github.com/nix-tools/hk-nix"&gt;&lt;code&gt;hk-nix&lt;/code&gt;&lt;/a&gt; is to hk what &lt;a href="https://github.com/sudosubin/lefthook.nix"&gt;lefthook-nix&lt;/a&gt; is to lefthook: you install hk with
Nixpkgs, declare your hooks in Nix, pin every tool with Nix, and the hooks install themselves
whenever you enter the &lt;a href="https://github.com/numtide/devshell"&gt;devshell&lt;/a&gt;. It is the same stack I &lt;a href="https://simonshine.dk/articles/lefthook-treefmt-direnv-nix/"&gt;previously built with
lefthook&lt;/a&gt;, with a nicer configuration language and one fewer workaround.&lt;/p&gt;
&lt;h2 id="synergies"&gt;
 Synergies
 &lt;a class="heading-anchor" href="#synergies" aria-label="Link to this section"&gt;&amp;para;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Nix + direnv:&lt;/strong&gt; You only ever need to install these two manually: Nix being the package manager,
and direnv being the thing that activates the Nix devshell. All other tooling is derived, pinned and
installed for you.&lt;/p&gt;</description></item><item><title>Using lefthook and treefmt with Nix</title><link>https://simonshine.dk/articles/lefthook-treefmt-direnv-nix/</link><pubDate>Sat, 07 Mar 2026 21:47:14 +0100</pubDate><guid>https://simonshine.dk/articles/lefthook-treefmt-direnv-nix/</guid><description>&lt;p&gt;In my recent attempts to modernize my CI pipelines, I&amp;rsquo;ve experimented with and subsequently let go
of &lt;a href="https://pre-commit.com/"&gt;pre-commit&lt;/a&gt;. The reason why I didn&amp;rsquo;t stick with pre-commit is that &lt;a href="https://simonshine.dk/articles/speeding-up-ci-with-nix/#letting-go-of-pre-commit"&gt;pre-commit drags
in several software runtimes and toolchains&lt;/a&gt; when building it from scratch. When
Nix fails to build something from nixpkgs, it&amp;rsquo;s an omen of &lt;a href="https://www.youtube.com/watch?v=QrGrOK8oZG8"&gt;too many chefs&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Alternatives I&amp;rsquo;m aware of:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://lefthook.dev/"&gt;lefthook&lt;/a&gt;: A generic tool written in Go; defines hooks in a lefthook.yml file.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/typicode/husky"&gt;husky&lt;/a&gt;: A generic tool written in JavaScript; enough said.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/rhysd/cargo-husky"&gt;cargo-husky&lt;/a&gt;: A tool specialized to Rust/Cargo; very nice, but not generic enough.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I initially disregarded lefthook because of its special lefthook.yml.&lt;/p&gt;</description></item></channel></rss>