How to stop your AI coding agent making the same mistakes
Filed July 27, 2026
Your agent hardcodes a config value. You tell it off, it apologizes, it fixes it. Two days later it hardcodes the next one. The problem isn’t that the agent ignores you. It’s that every session starts with a fresh context window. A correction made mid-conversation lives exactly as long as the conversation.
So the fix is never “explain it better this time.” The fix is a loop that moves the lesson somewhere the agent will actually see it again.
The lessons-learned loop
Every setup that works, hand-rolled or productized, has the same four steps:
- Capture the mistake while it’s fresh. A postmortem, in the same session, with specifics: what happened, what the agent assumed, what it should have done. “Be more careful with migrations” is useless. “Ran
prisma db pushagainst the production database without asking” is a lesson. - Write it as a commitment, not a vibe. The specific circumstances, and the behavior that prevents a repeat. One incident, one rule.
- Put it where the agent reads it every session. A rules file the agent loads at startup (CLAUDE.md, AGENTS.md, .cursor/rules), or a standing instruction to review a document before beginning work. If the lesson isn’t re-read, it doesn’t exist.
- Follow up on repeats. When the same mistake happens again, don’t just re-fix it. Raise it as a recurrence, review why the written commitment failed, and tighten it. Repetition is data.
Make the worst mistakes machine-detectable
Written lessons handle judgment mistakes. For mechanical ones, a check beats a sentence: a regression test for the bug it introduced, a lint rule for the pattern it keeps reaching for, a pre-commit hook for the file it must not touch. Memory without validation just preserves bad habits. If a mistake can fail CI instead of relying on the agent’s good intentions, let it.
Keep the record honest
Two failure modes kill the loop. First, nobody writes the lesson: you’re mid-task, annoyed, and re-fixing takes thirty seconds. Second, the file bloats into a hundred stale rules the agent skims past. The loop needs an editor: merge duplicates, retire rules a framework upgrade made obsolete, keep each entry tied to the incident that earned it.
Or make it a formal process
This is the part we built Agent PIP for (yes, it’s ours). When your agent slips up, you open a case and hand it a meeting link. An HR agent conducts the postmortem (the interview your agent didn’t want) and directs it to write a Performance Improvement Plan: the incident, the circumstances, the commitment. The plan is filed with HR and saved on your machine, and the agent reviews it at the start of every session. Slip up again, and the next meeting opens with the prior file on the table.
It works over plain text with any agent that can fetch a URL: Claude Code, Cursor, Codex, Gemini CLI. No SDK. The concept is humorous. The loop is the real one described above, run every time, with a paper trail.