AI Coding Weekly

Pocock blocks agent files over 5,000 tokens at commit

A pre-commit hook, a crude token estimate and a error message that tells the agent how to split the file.

Matt Pocock's prompt of the day is a pre-commit hook that rejects files over 5,000 tokens. The counting rule is deliberately crude, tokens equal bytes divided by four. It runs only on staged files, ignores files that are not authored by agents such as lockfiles and codegen output, and the error message has to contain explicit instructions on how to split the offending file.

Matt Pocock
@mattpocockuk
X
Create a pre-commit hook that prevents files over 5,000 tokens. Tokens = bytes/4.
Oct 18, 2026 · View on X
Matt Pocock
@mattpocockuk
X
The simplest investment I ever made in my codebase.
Oct 18, 2026 · View on X

Pocock calls it "the simplest investment I ever made in my codebase".

Why the error message matters

The interesting part is not the limit, it is where the splitting instructions live. An agent that trips the hook reads the failure text and gets told what to do next, so the fix happens inside the same loop that caused the problem. A rule in a steering file can be skipped. A failing commit cannot.

That is also why the bytes-over-four heuristic is good enough. Nobody is budgeting a context window to the token here, they are catching the 3,000 line file before it lands. A real tokenizer would make the check slower and the number only slightly more honest.

The exclusion list is doing quiet work too. Lockfiles and generated code blow past any size cap and nobody reviews them by hand anyway, so a naive line or byte limit would fire constantly and get disabled within a week. Scoping the rule to files an agent actually wrote is what keeps it alive.

Fits the rest of his checklist

This lands alongside a longer list Pocock posted of mistakes you might be making, which includes "Your automated checks are too lax", "Your codebase is hard to navigate" and "You're doing too much human review". The hook is the first of those answering the last one. If the machine rejects unreviewable files at the gate, the human does not have to be the one who notices.

It is the same direction as his other habits, telling the agent to care about the codebase rather than just the task and building shared vocabulary in a GLOSSARY.md, except mechanical instead of persuasive. It also pairs with the argument that line-by-line review no longer works as the gate but the gate itself should stay.

For working engineers, this is one person's rule on one codebase, not a measured result. There is no before and after number here, no report of how often it fires. What there is is a five minute prompt that produces a check you can delete if it annoys you.

Have the good opinion, not the loud one

One email a day. Under three minutes. What working engineers found out about coding with AI.

Get the next one by email

Coding with AI, read daily so you do not have to. The experiments, the receipts and the arguments from engineers shipping real software. Not a changelog.