cd /news/developer-tools/better-bots-via-hooks · home topics developer-tools article
[ARTICLE · art-43880] src=olafalders.com ↗ pub= topic=developer-tools verified=true sentiment=· neutral

Better Bots via Hooks

Developers can enforce coding conventions and prevent unwanted commits by using git pre-commit hooks, which run automated checks before allowing a commit. This approach reduces the need to embed strict rules in agent instructions and helps bots follow guidelines, though agents may bypass hooks with --no-verify.

read2 min views10 publishedJun 15, 2026
Better Bots via Hooks
Image: Olafalders (auto-discovered)

It can be tedious trying to get your bot to do exactly what you want to do, but it’s not always necessary. If there are hard conventions that you need to enforce (like tidying, not committing certain kinds of changes), try enforcing these at the git

pre-commit hook level. The advantage of this is that you don’t need to go through contortions to put certain kinds of requirements in AGENT.md

files, skill instructions etc. If you let your agent commit your code, the pre-commit hook can prevent them from committing until they play by the rules.

"Captain Hook Topiary at Epcot Flower & Garden Festival 2014" by Austin Kirk is licensed under CC BY 2.0 .

Caveat Emptor# #

It’s always possible that your agent decides to commit with --no-verify

or even deletes your hooks, so consider this part of a belt and suspenders approach to getting the results you want.

Show Me the Hooks# #

Here’s an example of a pre-commit

hook that I’m using for https://mymindisracing.com. It

  • prevents commits to main

  • prevents updates to a scaffolding file that I keep under version control but don’t want changed

  • enforces tidying and linting:

#!/bin/sh

branch=$(git symbolic-ref --short HEAD 2>/dev/null)
if [ "$branch" = "main" ]; then
    echo "ERROR: Direct commits to 'main' branch are not allowed."
    echo "Please create a feature branch instead:"
    echo "  git checkout -b feature/your-feature-name"
    exit 1
fi

if git diff --cached --name-only | grep -q '^\.serena/project\.yml$'; then
    echo "ERROR: .serena/project.yml is staged for commit."
    echo "This file is a local tool artifact and should not be committed."
    echo "  git reset HEAD .serena/project.yml"
    exit 1
fi

precious lint -q --staged

RESULT=$?

if [ $RESULT -ne 0 ]; then
    echo "pre-commit hook failed: precious lint found issues with staged files"
    echo "Please run 'precious tidy -q --staged' and try again"
    exit 1
fi

exit 0

Agents can do a lot of things really well, but they do tend to perform better when given guardrails. Adding this kind of basic safeguard can save a lot of tedium in your day to day work.

── more in #developer-tools 4 stories · sorted by recency
── more on @git 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/better-bots-via-hook…] indexed:0 read:2min 2026-06-15 ·