Why Your AI Coding Agent Repeats the Same Mistake
The correction lived only in that one conversation. Here is why AI coding agents forget fixes across sessions, and the three durable places to put a correction so it actually sticks.
Why Your AI Coding Agent Repeats the Same Mistake
An AI coding agent repeats a mistake you already corrected because the correction lived only in that conversation's chat history, not in anything the agent reads at the start of the next session. Once that conversation ends, gets compacted, or simply scrolls past the model's context window, the correction is gone. The fix is not a smarter prompt in the moment, it is moving the correction somewhere durable the agent actually reads every time.
Where the correction actually goes when you fix something
When you tell an agent "do not use that deprecated function, use this one instead" mid-session, that instruction becomes part of the current conversation's context, nothing more. It is not saved to a project file, not added to any persistent memory, and not available to a fresh session started tomorrow, or even to a long-running session once older messages get compacted or trimmed to make room for new context. The agent is not being careless. It genuinely does not have access to a correction that exists only as one message in a conversation it can no longer see.
The three places a correction needs to live to actually stick
1. A rules file the agent reads at the start of every session
Most coding agents support a project-level instructions file (commonly named something like AGENTS.md, CLAUDE.md, or a tool-specific equivalent) that gets loaded automatically at the start of every session, not just the one where you made the correction. A recurring mistake belongs there, as a short, specific rule, not buried in a long conversation.
## Known mistakes to avoid
- Do not use the `legacyFormatDate()` helper, it was removed. Use
`formatDate()` from `lib/dates.ts` instead.
- Do not add a new database migration without also updating the
seed script in `db/seed.ts`, they must stay in sync.
- Tests in `__tests__/integration` require the local Postgres
container to be running; do not skip them or mark them as
expected-failure to make a run pass.2. The commit or PR description, for mistakes tied to a specific decision
If the mistake was a one-time architectural choice rather than a recurring pattern, a clear note in the commit message or PR description that an agent might read when working nearby code ("chose X over Y here because Z") gives future sessions the reasoning without needing a permanent rule file entry for something that will not recur elsewhere.
3. Tests that fail if the mistake happens again
The most durable fix of all is not documentation, it is a test. If a mistake is the kind that can be caught mechanically (using the wrong function, skipping a required step, violating a naming convention), a test or a lint rule that fails when it recurs does not depend on the agent remembering anything. It depends on the test suite catching the regression, which is a stronger guarantee than any instruction.
Why simply repeating the correction more forcefully does not help
A common reaction is to restate the correction more emphatically, in capital letters, or multiple times in the same conversation. This can work within that single session, but it does nothing for the next one, because the problem was never that the instruction was unclear, it was that the instruction had nowhere permanent to live. Emphasis fixes a clarity problem. This is a persistence problem.
A related but different failure: context window exhaustion
Sometimes what looks like "the agent forgot" is actually the correction scrolling out of an active session's context window during a long task, a related but distinct problem covered in how to keep an AI coding agent from losing context. The rules-file fix above solves the cross-session version of this problem; that post covers the within-session version.
What this looks like for two common recurring mistakes
An agent that keeps suggesting deprecated packages: add the specific package and its replacement to the rules file, rather than re-explaining it each time. See the dedicated breakdown in why your AI coding agent keeps suggesting old packages for the deprecation-specific version of this pattern.
An agent that ignores your style guide: a rules file entry naming the specific convention (not a link to an external style guide document, which agents read inconsistently) tends to work far better than repasting the whole guide into a fresh conversation each time. See why does my AI coding agent ignore my style guide for the deeper version of that fix.
Frequently asked questions
Do I need to add every correction to the rules file?
No, only ones that recur or are likely to recur, a genuinely one-off mistake does not need a permanent entry. A rules file that grows without limit becomes as hard for an agent to fully apply as no rules file at all, prune entries that have not mattered in weeks.
Will the agent actually read a long rules file in full?
Most agents load it into context at session start, but a very long file competes with the actual task for context space. Keep entries short and specific rather than exhaustive, a bulleted list of concrete rules beats a paragraph of general philosophy.
Does this happen with every AI coding agent, or just some?
It happens with any agent whose memory is scoped to the current conversation, which describes most of them by default. Some tools are adding longer-term memory features that persist facts across sessions automatically, but even then, an explicit rules file remains the more reliable and auditable place to put anything you actually depend on.
Should I just start a new conversation whenever this happens?
Starting fresh does not fix the underlying issue, since a new conversation has no more access to the correction than the old one did after compaction. Fix it at the source, the rules file, the test suite, or the code itself, rather than treating a new session as a reset that solves anything.
How did this land?
About the author

Staff Engineer, Platform
Carlo works on the platform that turns prompts into running apps. He writes the engineering deep dives and the changelog notes worth reading.


