Skip to content
AI Primer
workflow

Matt Pocock's pre-commit hook caps agent-written files at roughly 5,000 tokens

Matt Pocock's pre-commit hook rejects staged files above roughly 5,000 tokens, with generated-file exclusions and split instructions. A related skill requires existing oversized files to shrink with each commit.

3 min read
Matt Pocock's pre-commit hook caps agent-written files at roughly 5,000 tokens
Matt Pocock's pre-commit hook caps agent-written files at roughly 5,000 tokens

TL;DR

  • Staged files get a roughly 5,000-token ceiling in Matt Pocock's pre-commit prompt, with generated-file exclusions and explicit splitting instructions.
  • Git enforces the rule at commit time, following his argument for deterministic enforcement.
  • Existing oversized files can shrink gradually: a related skill requires offending files to get smaller with each commit until they pass.

Git's hook documentation includes an escape hatch: git commit --no-verify skips the check. A normal commit records the staged index, which can differ from a file's current working-tree contents.

Staged files and exclusions

Pocock posted a prompt asking an agent to build a pre-commit hook with four requirements:

  1. Reject files above 5,000 estimated tokens, calculated as bytes / 4.
  2. Check only staged files.
  3. Exclude files not authored by agents, such as lockfiles and generated code.
  4. Include explicit instructions for splitting files in the rejection message.

A 20,000-byte ceiling

The requested calculation puts the cutoff at 20,000 bytes, about 19.5 KiB. It measures file size without requiring a model-specific tokenizer.

Pocock called 5,000 an arbitrary choice that had worked for him. His stated motivation was reducing the amount of code an agent has to search through:

He also dismissed exact tokenization as wasted precision, emphasizing execution speed in a pre-commit hook.

Three-second Git hooks

Git aborts a commit when a hook exits nonzero, a refreshingly boring control point for an agent. Pocock also supports telling agents about the rule beforehand, alongside enforcing it.

His latency target is under three seconds. He acknowledged the historical friction of pre-commit hooks, but said fast ones fit agent workflows:

Commit-time feedback is a deliberate cadence, too. Pocock argued that more frequent feedback is less token-efficient.

Ratcheting oversized files

For repositories with existing oversized files, dzhng made a related skill that prompts the agent to make offending files smaller with every commit until they fall below the size limit. The stated purpose is adoption without forcing a large immediate refactor.

In an update, dzhng reported merging the open pull requests and making the tool faster and cheaper. The accompanying terminal demonstration follows an agent through repeated refactoring and size checks:

An agent iteratively refactors a file to satisfy the size check

Further reading

Discussion across the web

Where this story is being discussed, in original context.

On X· 4 threads
Staged files and exclusions1 post
A 20,000-byte ceiling2 posts
Three-second Git hooks2 posts
Ratcheting oversized files1 post
Share on X