๐Ÿ”ง Karpathy AutoFix

A Self-Correcting Agent Loop for Fixing Bugs and Improving Codebases

When something is broken, this skill makes Claude investigate deeply, propose a fix, test it, self-correct on failure, and iterate โ€” until it works or it hits an honest hard stop.

๐Ÿค– Claude Code ๐Ÿ”„ Self-Correcting ๐Ÿ–ฅ๏ธ CLI-First ๐Ÿ› Debugging ๐Ÿ“… April 2026

The Core Loop

INVESTIGATE โ†’ PLAN โ†’ ACT โ†’ VERIFY โ†’ PASS โœ“ | FAIL โ†’ self-correct โ†’ repeat

Hard rule: Never claim a fix worked without verification. Never stop prematurely if the issue persists. If it can't reproduce or fix the issue, it says so โ€” no false confidence.

Step 1 โ€” Clarifying Questions (Ask First)

Before writing any code, Claude asks just enough to reproduce and verify the fix:

Q1
What is the exact error or broken behavior?
Q2
What did you do when it happened?
Q3
What platform / OS / environment are you on?
Q4
What does "fixed" look like to you?
Q5
Any recent changes โ€” new deps, config changes, git updates?
Why these questions matter: A vague "it doesn't work" is the #1 reason fixes fail. If Claude can't reproduce the error, it can't verify the fix. These 5 questions close that gap fast.

Step 2 โ€” Investigate

2
Investigate before acting
โš ๏ธ If you cannot reproduce the error, you cannot verify a fix. Reproduce first, always. If Thota gives a vague complaint ("it's broken"), ask the clarifying questions before assuming anything.

Step 3 โ€” Plan

3
Plan before touching code

Answer these before editing anything:

State the root cause and fix in one sentence. If you can't, go back to investigate more.

Step 4 โ€” Act

4
Make the minimal fix
# Revert a file cleanly git checkout -- path/to/file.js

Step 5 โ€” Verify

5
Run the exact failing command again

Run the exact command or input that produced the error. If it now succeeds โ†’ you're done. If it still fails โ†’ loop back to Step 2.

โœ… Fixed when: the same input that triggered the error now produces the correct output โ€” without any other changes to the system.

Self-Correction Rules

SignalResponse
Test fails after fixRe-read error, look at what changed, find the next failure point
Same error after changeWrong root cause โ€” go back to investigate
New error introducedRevert last change, re-diagnose before continuing
Build failsFix build errors one at a time, in order
Can't reproduceStop. Report what you tried. Ask Thota for more context
Fix works but reason is unclearDocument why it works before declaring done
3 attempts, none workedStop. List all attempts and ask for more context

What To Do When a Fix Fails

Hard Stops

Stop and report to Thota immediately when:

โš ๏ธ Stop is not failure. Reporting what you tried honestly is better than guessing. Thota would rather know it needs more context than have Claude spin in circles.

Fix Report Template

After every completed fix, Claude reports:

Problem: [what was broken] Root cause: [what caused it] Fix: [what changed] Verified: [how you confirmed it works]

On "Improve This Project" (Not a Specific Bug)

Why This Works โ€” Karpathy Philosophy

The key insight: Most debugging failures happen because the investigator stops too early. The AutoFix loop forces Claude to stay in investigation mode until the evidence is overwhelming โ€” not just until it has a hypothesis.