Karpathy-Style CLAUDE.md Self-Check Protocol for Loops
A self-check protocol embedded in CLAUDE.md that every loop iteration obeys before ending a turn: re-read the goal, diff the changes against it, run the verification command, and state what remains — a ritual that catches drift between iterations.
Implementation note
When to use: loops that drift — iterations that wander off-goal, declare premature success, or lose track of remaining work — where you want a correcting ritual applied every single turn without re-prompting. How it works: preamble rules embedded in CLAUDE.md that every loop iteration obeys before ending a turn: re-read the goal, diff your changes against it, run the verification command, and explicitly state what remains. Because CLAUDE.md is loaded every session, the ritual survives fresh-context iterations for free — drift correction as standing configuration rather than per-run prompting. Safety: the run-the-verification-command step keeps self-assessment anchored to an objective check instead of the model's optimism. One attribution caution from the source: this is a community template descended from Karpathy's circulated CLAUDE.md rules, reported by a secondary source — verify the exact current rule text against the upstream repo before quoting or republishing specific rules. Hardened 2026-07-27: explicit stop/cap/verification guardrails appended; regraded D→A.
More quality loops
Clean up the slop
Review your recent diff for debug code, dead branches, and bad names, then fix with minimal edits until lint and tests pass.
Agent-Loop-Skills bundle — loop until it's better
Six verification-gated loops in one open-standard skill bundle — autoresearch, scientific writing, data analysis, code/SQL/prompt optimization, and red-teaming — portable across Claude Code, Codex, and Cursor. Use the red-teaming loop only against systems you own and are authorized to test.
Repair accessibility, highest-impact first
Confirm barriers against an agreed standard, fix the one with the greatest user impact, and rerun the same checks.