revert_guard.py Stops AI Agents From Re-adding Reverted Code
revert_guard.py reads a repo's own git revert history to block AI agents from re-adding previously reverted code, like a card_token column, before it gets committed—offline and keyless.
AI coding agents start each session with no memory of past decisions, so they can unknowingly re-propose changes a team deliberately reverted—like a card_token column removed for PCI-DSS reasons. The reasoning behind that decision disappears with the session, but the revert itself remains in git log; the gap is that this information exists yet nothing enforces it.
revert_guard.py closes that gap with an offline, keyless, standard-library-only pre-commit tool. It reads the repo's revert commits, extracts what each one removed, and checks whether a proposed diff re-adds the same entity—matched by table-qualified name rather than file path. A match blocks the commit with exit code 1; no match ships with exit code 0; an ambiguous, unqualified match warns and defers to a human via exit code 2.
The tool was built after the author read an incident @masondelan documented on Dev.to, where a fresh Claude Code session re-added a previously reverted card_token column months later. The original story and numbers belong to that post; this project borrows only the shape of the problem. For engineers, it's a reminder that AI-generated diffs can look perfectly reasonable while ignoring a team's past rejections—and that a small, deterministic, offline check reading existing git history can plug that hole cheaply in CI.