← Back to Insights

Insight

Rules That Run, Part 8: A History Worth Reading

Ariel Agor
Updated
The cover illustration with subtle ambient motion, for "Rules That Run, Part 8: A History Worth Reading".

Listen · Read by Ariel

0:00 / n/a

Rules That Run is a ten-part series on the rules that keep an AI agent setup honest. This is part 8.

An agent that writes code also writes history, and by default it writes the kind any hurried person writes. A feature commit, then a commit that fixes the feature, then one that fixes the fix, all pushed to main because main was the branch that happened to be checked out. Each commit is reasonable on its own. Read together they tell you very little about what changed and why.

On October 31, 2026, I adopted a set of git rules for every repo, taken from Johnny Ji's essay "Engineering Culture: Keeping a Clean Commit History" (Medium, 2021). The essay is written for human teams. The rules transfer to agents almost unchanged. What did not transfer was the tooling, because the standard way to clean up history is interactive, and an agent cannot use an interactive editor.

The rules

These are the rules as I run them:

  • Code goes on a typed branch, named <type>/<slug>, and lands by pull request.
  • Commits are atomic and conventional: type(scope): summary, with a body that says why.
  • A fix goes into the commit it fixes, using a fixup commit and autosquash. Never a "fix typo" commit stacked on top.
  • Force-push only your own branch, and only with --force-with-lease.
  • Land with a rebase merge.
  • Main is never rewritten.

The third rule is the one that changes history the most. A reviewer reading the branch sees each logical change once, in its final form. The record of how many attempts it took is gone, and nobody needs it. If the agent got the first version of a function wrong, the history shows the right version in the commit that introduced it.

Why agents need a helper

Folding a fix into an earlier commit normally means git rebase -i, which opens an editor with a todo list for a person to edit. Claude cannot drive that editor. Without a helper, the realistic options are to skip the cleanup or to reach for something blunter, like a reset and one squashed commit, which throws away the atomic commits the rules ask for.

So a helper CLI does each step non-interactively:

git-hygiene start feat/export-csv      # create the typed branch from fresh main
git-hygiene fixup <sha>                # commit staged changes as a fixup of <sha>
git-hygiene reword <sha> "<message>"   # change a message without an editor
git-hygiene tidy                       # fold every fixup into its target
git-hygiene pr                         # push the branch and open the pull request
git-hygiene land                       # wait for CI, rebase-merge, prove it landed

The core of tidy is one line:

git -c sequence.editor=true rebase -i --autosquash <base>

--autosquash arranges the todo list so each fixup! commit sits under its target. Setting sequence.editor to true replaces the editor with a command that does nothing and succeeds, so git accepts that list as written. The rebase is interactive in name only.

land matters most. It waits for CI, merges with a rebase, and then checks that the work actually arrived:

git fetch origin
git cherry origin/main <branch>

git cherry compares patches, not commit hashes, so it still works after a rebase merge gives every commit a new hash. A line starting with - means an equivalent patch is already on main. Any line starting with + means a patch did not land, and land reports failure instead of success. This is the same idea as part 5: "merged" is a claim, and git cherry is the evidence.

The gate

Rules in an instruction file drifted, as every rule in this series has. So a PreToolUse hook reads every git and gh command the agent is about to run and denies the ones that break the rules:

  • a code commit on main
  • any force-push to main
  • a bare --force, without lease
  • amending a commit on main that has already been pushed
  • a local merge into main
  • a PR merge without --rebase, or with fixup! or WIP commits still on the branch

Each denial comes with the reason and the command that does the job properly, usually a helper subcommand. As of November 18, 2026, the gate had logged 63 denials.

Like every gate in this setup, it has a logged override for the cases it gets wrong. Part 3 covers why overrides get counted.

The hole

Gates have holes, and the useful thing is to find them from evidence.

The commit check looked at what was staged when the commit command ran. An agent that wrote git add <code> && git commit -m "..." as a single shell command got through, because the hook ran before the shell did, and at that moment nothing was staged. The gate saw an empty commit on main and allowed it.

Between October 31 and November 3, 2026, 13 code commits reached main that way. The gate's own log could not have shown this, because from the gate's point of view each of those commands was allowed correctly.

The fix was to parse the whole command line. Each git add is now charged to the commit that follows it in the same command, so the gate judges what the commit will contain, not what the index holds before the command starts.

The lesson I took from it is narrow and practical. A gate that inspects state before a compound command runs is checking the wrong moment. Wherever an agent chains commands with &&, the gate has to reason about the chain.

The repos themselves

Rules on the agent are half of it. The other half is the hosting side, so that even a command that slips past the gate cannot do certain things.

On October 31, 2026, the same settings went onto 141 of 141 non-archived, non-fork repos:

gh api -X PATCH "repos/<owner>/<repo>" \
  -F allow_merge_commit=false \
  -F allow_rebase_merge=true \
  -F delete_branch_on_merge=true

Each repo also got a ruleset protecting its default branch, so a force-push to main is refused by GitHub even if the local gate is bypassed.

New repos do not inherit any of this. A repo created next week starts with the defaults. So a daily job re-applies the settings across every repo, because new repos drift, and nobody remembers to configure a repo they made in a hurry.

The ledger exception

Not everything belongs on a branch. Scheduled jobs in this setup commit content, data and handoff files, and those commits go straight to main. A daily post or an updated data file is a ledger entry. Putting it through a branch and a pull request would add a review step that nobody performs.

Bot pipelines may also squash a pull request that contains a single change. The rule exists to keep logical changes readable, and a one-change PR is already readable.

The exception is narrow on purpose. It covers content, data and handoff commits from scheduled jobs. Code from a person or an agent still goes on a branch.

What a clean history buys

The payoff is concrete. When something breaks, git log on main reads as a list of real changes, each with a reason. git bisect lands on a commit that does one thing. A reverted commit takes out one change and nothing else.

For agent-written code there is one more payoff. A fresh session has no memory of why the code looks the way it does. The commit bodies are where that reason survives. An agent that wrote "why" into each commit has left notes for the next agent, which is the same idea as the handoff in part 7, kept in a place that lasts as long as the code.

Build it yourself

  1. Write down your git rules as a short list: typed branches, conventional commits with a why, fixups folded in, lease-only force-push on your own branch, rebase merge, main never rewritten.
  2. Build a helper with start, fixup, reword, tidy, pr and land; implement tidy with git -c sequence.editor=true rebase -i --autosquash <base>.
  3. Make land wait for CI and check git cherry for any + line before it reports success.
  4. Add a PreToolUse hook that denies commits on main, force-pushes to main, bare --force, amended pushed commits, local merges into main and non-rebase PR merges.
  5. Parse compound commands, so a git add is charged to the commit that follows it.
  6. Apply the repo settings and a branch ruleset everywhere, and re-apply them on a schedule.
  7. Write down the ledger exception explicitly, so it stays narrow.

Part 7: Leave a Note Before You Forget

Want this kind of automation working for your business?

Agor AI designs and ships the systems these posts describe, scoped in weeks, not quarters.

Book a Free Strategy Call