GuidesGuideSame mistake after correctingDirectory

Why does my AI keep making the same mistake after I correct it?

Updated

A correction doesn’t change the model. It only helps later if it’s written somewhere that loads when the mistake is about to happen, and even then the model reads it as context, which it usually follows and sometimes doesn’t. So the fix depends on the mistake: a line in CLAUDE.md or AGENTS.md for what it didn’t know, a hook for what must never happen, a test for what can be checked, and a memory note for how you like to work. In ChatGPT or Claude chats, it’s instructions or memory: see chats.

This page is built from Anthropic’s, OpenAI’s and Cursor’s docs and from what people report on Reddit and GitHub.

An AI drafted this page from the sources below and another AI checked it. No person has run these steps. An AI ran the example hook script on made-up input only, not inside Claude Code, Codex or Cursor. Counterparts is ours: Mike LaPeter runs Counterparts.

Why corrections don’t stick

There are four ways a correction gets lost, and each has a different fix.

  1. It was only said in chat. A new session starts with a fresh context window, so what you said in the last one is gone unless something wrote it down. In a long session, compaction replaces the conversation with a summary, so a correction made only in chat may not survive it (for what reloads after /compact, see Claude Code memory).
  2. It was written down, but wasn’t loaded when it mattered. Claude Code loads only the first 200 lines or 25KB of auto memory’s MEMORY.md at the start, and reads the topic files behind it only when it decides to. Rules with a paths field load only when Claude works on matching files. Subagents, other than a fork of the conversation, don’t get the main conversation’s auto memory. One r/ClaudeCode user kept a MISTAKES.md log for two months and wrote that the agent “made the same mistakes again, because the file was never in its context when it mattered” (comment).
  3. It was loaded and still not followed. Anthropic says Claude treats CLAUDE.md and auto memory “as context. They aren’t enforced configuration.” CLAUDE.md arrives as a user message after the system prompt (--append-system-prompt puts a rule in the system prompt itself, for scripted runs). It “tries to follow it, but there’s no guarantee of strict compliance, especially for vague or conflicting instructions.” Long files make this worse: Anthropic says files over 200 lines “reduce adherence”. So do sessions full of failed attempts.
  4. It was over-learned. A remark meant for one day gets saved as a standing rule. One user mentioned once that they were close to their usage limit, and Claude Code’s memory turned it into “a blanket rule applied on every conversation in every project” (post).

Which fix fits which mistake

The mistakeExampleThe fixWhy this one
It didn’t know something about the project

Uses npm in a pnpm repo; calls the old error helper

One concrete line in CLAUDE.md, AGENTS.md or a Cursor rule

It loads every session. This is what Anthropic says the file is for: add a line when “Claude makes the same mistake a second time”

It does something that must never happen

Edits generated code, runs pytest instead of make test, touches .env

A hook that blocks the call (PreToolUse, exit code 2)

The harness runs it every time, whatever the model decides

It skips a step that must always happen

Forgets the formatter or the license header

A hook that runs the step itself (PostToolUse)

Claude doesn’t have to remember it

The result is wrong in a way a program can catch

Type errors, a bug coming back, broken lint

A test, typecheck or linter, and the command in CLAUDE.md; a Stop hook to make it binding

Claude runs the check, reads the failure, and fixes it before stopping

It keeps re-solving a bug it solved last week

Spends 20 minutes rediscovering the same database fix

A test that reproduces the bug, plus a one-line gotcha in CLAUDE.md naming the cause

The test catches the bug if it comes back; the line saves the rediscovery

It forgets how you like to work

Too long, too many questions, adds dependencies without asking

~/.claude/CLAUDE.md (every project), auto memory (one repo), or a memory that follows you across projects, such as Counterparts (ours)

It’s a preference, so it needs to be read, and it has exceptions

A judgment slip

Says something is gone without searching, says it’s tested when it isn’t

A narrow rule written around the moment, a request for evidence, a review by a fresh agent

No script can see these in the command; see what no memory fixes

A rule that gets followed

Where the line goes, by tool:

  • Claude Code: CLAUDE.md in the project (shared through git), ~/.claude/CLAUDE.md for you in every project, CLAUDE.local.md for your own project notes, and .claude/rules/ for rules scoped to some files. Claude Code reads AGENTS.md too, but by default only when there’s no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in the folder or above it, so a correction added to AGENTS.md in a repo that has one of those isn’t read; import it from CLAUDE.md (@AGENTS.md) or set Project instructions in /config to read both. Carrying your preferences into every project goes through the layers one by one.
  • Codex: AGENTS.md in the repository, and ~/.codex/AGENTS.md for every repository. Files closer to your working directory come later and override earlier guidance. They stop loading past 32 KiB combined by default. An AGENTS.override.md in the same folder is read instead of AGENTS.md.
  • Cursor: project rules as .mdc files in .cursor/rules/ (a plain .md file there “is ignored”), AGENTS.md in the root or subfolders, user rules in Customize → Rules, and team rules. A rule set to Always Apply goes into every chat; others load when the agent judges them relevant, match a file pattern, or are @-mentioned.

How to write it, from Anthropic’s guidance and what users report:

  • Concrete enough to check. Anthropic’s examples: “Use 2-space indentation” over “Format code properly”, “Run npm test before committing” over “Test your changes”.
  • Narrow. One commenter warns that agents “take a loose instruction and apply it as a hard rule”, and rewrites the line when a mistake comes back instead of adding another (comment).
  • With its reason. Another adds “Why:” and “How to apply:” to every memory entry, so the model can tell when a rule doesn’t apply (comment).
  • Short, and consistent. Under 200 lines per CLAUDE.md, and no two lines that contradict each other: Anthropic says Claude “may pick one arbitrarily”. /doctor prompt-audit (v2.1.283 or later) looks for outdated and conflicting instructions across your files and proposes edits without making them.
  • Procedures with several steps go in a skill, which loads only when needed.

To check a rule is loading at all, run /context all in Claude Code and look under Memory files. In Codex, OpenAI suggests asking it to list “the instruction sources you loaded.”

A hook for what must never happen

A hook is a script the tool runs at a fixed point, such as before every shell command. If it exits with code 2, Claude Code blocks the call and passes the script’s message to Claude, so the correction arrives at the moment of the mistake.

Here’s the “runs pytest instead of make test” case from the table. Save it as .claude/hooks/use-make-test.sh and run chmod +x on it:

#!/bin/bash
# Block running pytest directly; this repo runs tests with `make test`.
CMD=$(jq -r '.tool_input.command // empty')
RE='(^|[;&|])[[:space:]]*(python3?[[:space:]]+-m[[:space:]]+)?pytest([[:space:]]|$)'
if [[ "$CMD" =~ $RE ]]; then
  echo "Blocked: run the tests with 'make test', not pytest directly." >&2
  exit 2
fi
exit 0

Then add it under hooks in .claude/settings.json. If the file already exists, merge this into it rather than replacing it; if it has a PreToolUse list already, add this entry to that list:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/use-make-test.sh"
          }
        ]
      }
    ]
  }
}

It needs jq; without it the script lets everything through. An AI fed the script made-up hook input on a Mac. It lets through wrappers such as uv run pytest, FOO=1 pytest and bash -c "pytest", and a pytest on a second line, and it blocks a commit message that contains ; pytest. Adjust the pattern for the forms your agent uses. You can also ask Claude to write one (“write a hook that blocks edits to the migrations folder”, in Anthropic’s example) and check it with /hooks.

What a hook doesn’t cover:

  • Only what it matches. Anthropic’s example that blocks Edit and Write on .env doesn’t stop Claude changing the file with a shell command; the docs add permissions.deny rules and the sandbox for that.
  • Exceptions. “A hook is for a rule with *zero* exceptions,” Anthropic says, and “Prefer named exports” isn’t one.

Codex hooks go in .codex/hooks.json in the project (or ~/.codex/hooks.json for every project), and Codex skips a new or changed hook until you review and trust it (/hooks in the CLI). Save the script as .codex/hooks/use-make-test.sh. Codex doesn’t set $CLAUDE_PROJECT_DIR, so the command finds the script from the git root, as OpenAI’s examples do:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "\"$(git rev-parse --show-toplevel)/.codex/hooks/use-make-test.sh\""
          }
        ]
      }
    ]
  }
}

As in Claude Code, a PreToolUse hook can deny a shell command, an apply_patch edit or an MCP call with exit code 2, and Codex passes a shell command to the script as tool_input.command, so the script above reads it the same way. Hosted tools such as web search don’t pass through hooks, and OpenAI says to treat tool hooks as “a useful guardrail, not a complete enforcement boundary.”

Cursor hooks go in .cursor/hooks.json, and a project’s hook scripts run from the project root. Save a Cursor version of the script as .cursor/hooks/use-make-test.sh with two changes. Cursor documents exit code 2 as a deny but doesn’t say the script’s stderr reaches the agent, so print the reason as JSON: replace the echo ... >&2 and exit 2 lines with echo '{"permission":"deny","agent_message":"Run the tests with make test, not pytest directly."}' and exit 0. And when a hook exits 0 with no valid JSON, Cursor blocks the action, so print {"permission":"allow"} on the allowed path, just before the final exit 0. Register it as a preToolUse hook:

{
  "version": 1,
  "hooks": {
    "preToolUse": [
      { "command": ".cursor/hooks/use-make-test.sh", "matcher": "Shell" }
    ]
  }
}

Its input has the command at tool_input.command, as in the script (beforeShellExecution sends it as command instead). Cursor also runs hooks from .claude/settings.json by default (Settings → Agents → Third-Party Imports), so if you already added the Claude Code hook, check whether Cursor blocks pytest before adding this one. An AI ran the changed script on made-up input only.

A check it has to pass

Anthropic’s best-practices page: “Claude stops when the work looks done. If it has nothing to run that tells it whether the work actually *is* done, ‘looks done’ is all it has to go on.” A test, a build’s exit code or a linter lets Claude find its own mistake, and “the single most useful line in your CLAUDE.md is the command that runs it.”

To make the check binding, a Stop hook runs whenever Claude tries to end its turn and sends it back with the output when the check fails. Anthropic’s example, to add under hooks in .claude/settings.json (merge it into the file if it exists):

{
  "hooks": {
    "Stop": [
      {
        "hooks": [
          { "type": "command", "command": "pnpm tsc --noEmit 1>&2 || exit 2" }
        ]
      }
    ]
  }
}

Some things to know. A Stop hook fires every time Claude finishes responding, not only at the end of a task. And after eight blocks in a row with no tool call in between, Claude Code lets the turn end (CLAUDE_CODE_STOP_HOOK_BLOCK_CAP raises the cap). A hook script that re-runs work should exit early when its input says stop_hook_active is true. Add the hook only once the check passes on your current code, and use the command your repo really has: with || exit 2, a missing pnpm, a non-TypeScript repo or errors that were already there send Claude back after every reply, even an answer to a question. One user on #106546 reports a Stop hook that kept Claude going after they said stop.

Codex has a Stop event too: returning "decision": "block" with a reason makes Codex continue with that reason as its next prompt. Cursor’s stop hook can return a followup_message that’s sent as the next user message, up to 5 times by default.

When it says “done” and it isn’t

A false “done” is the mistake a note helps least with, because the agent usually knows the rule; what helps is a check and evidence.

The best measurement we found is one team’s: they labelled 357 “tests pass” claims from 150 of their Claude Code sessions against the session logs (#104504). 178 were backed by a matching run, 80 weren’t, 92 couldn’t be checked either way, and 5 were contradicted by the record. Of 36 unbacked claims in the development set they built their labels on, 32 were stale: the tests passed, Claude edited the code again, then reported the old pass. And 1,514 of 2,084 test runs (73%) were piped through tail or head, so a failing run could exit 0.

What to do about it:

  1. Ask for evidence with every “done”: the command it ran and its output. Anthropic: “‘All tests pass’ on its own tells you very little.”
  2. Have it re-run after any edit since the last run, and say so when it only ran some tests. One line in CLAUDE.md can say this; a commenter on #104504 found it “helped a bit” but “still forgets sometimes”.
  3. Put set -o pipefail in front of piped test commands, or don’t pipe them, so the exit code is the test runner’s.
  4. Make a Stop hook run the tests, as above. Commenters on #104504 have published Stop hooks that check claims against the session (they’re the tools’ authors); we haven’t tried them.
  5. Have someone else check. In Claude Code, /code-review reviews the diff in a fresh subagent that “never saw your conversation”, and /verify builds and runs the app and looks at the result.

In ChatGPT or Claude chats

You can’t add hooks or tests there, so the choice is between instructions and memory.

  • A correction that should always apply goes in instructions, not in one chat. In ChatGPT, that’s Settings → Personalization → Custom Instructions (Customize ChatGPT in the apps), with Enable customization on; OpenAI calls them “direct guidance that you provide”, and they apply to all chats. In Claude, it’s Settings → Your Claude → Instructions for all your conversations, or a Project’s instructions (“Set project instructions”) for chats inside that project.
  • A wrong memory is better fixed or deleted than added to. Tell ChatGPT the memory is “incorrect or outdated”, or edit it. Tell Claude what you’d like it to “remember, change, or forget”, or use Settings → Your Claude → Manage.
  • After two failed corrections in one chat, start a new chat and put the lesson in the first message. Anthropic gives the same advice for Claude Code, because a third correction adds to a conversation that already holds two failed attempts.
  • When it says “done,” ask what it ran and what it printed, as in the section above.

Memory notes: what they can and can’t do

A memory note is for things with exceptions, the ones you’d tell a colleague. Claude Code’s auto memory saves corrections under a feedback type (“corrections you give Claude and approaches you confirm”), one folder per repository, on your machine. Say “remember that the API tests require a local Redis instance” (Anthropic’s example) to save one, and run /memory to open the folder and edit or delete notes. It’s per repository, so a correction about how you work doesn’t reach your other projects unless it’s in ~/.claude/CLAUDE.md or a memory that reaches every project (Counterparts is ours) (CLAUDE.md vs auto memory compares the two).

Codex memories are off by default; OpenAI says to keep required guidance in AGENTS.md and treat memories as “a helpful recall layer, not as the only source for rules that must always apply.”

What a note can’t do is make itself read at the right moment. An agent on r/ClaudeCode found that a correction added to shared notes lost to the old text it contradicted: “a correction appended at the bottom loses to the stale paragraph at the top” (post, written by an AI, labelled as one). Edit or delete the wrong note when you correct it, rather than adding a new one. Why AI memory goes stale covers that system by system.

Of the 22 systems in our directory on November 21, 6 are rated as both correcting a contradicted memory and keeping what it used to say, Counterparts among them; 14 do part of it and 2 don’t. For Claude Code’s auto memory, Claude edits the note in place and the docs describe no history of what it said before.

What no memory fixes

  • Judgment mistakes. A script can see pytest in a command. It can’t see what one commenter calls a judgment mistake, such as “claimed X was gone without searching”. The commenter with the MISTAKES.md log built 142 hook rules; mechanical repeats “have mostly stopped”, but “Judgment mistakes still come back” (comment).
  • More rules past a point. One user built sixteen hooks and checks between two days of long work, and a reviewer scoring both days found behaviour “barely moved”; the user says to “treat this as a guide, not a measurement” (#106546). Anthropic’s advice runs the same way: a short file, and a hook only for rules with no exceptions.

Where Counterparts fits

Counterparts, the memory we make, is Claude’s memory of you and your work together. Claude writes down what it learned, in its own words, and each Claude Code session opens with a short “who I am, who you are, where we left off” that Claude wrote itself. What it knows about you reaches every project, so a correction about how you like to work doesn’t stay in one repository. When something changes, we keep the old version beside the new one, marked earlier, so the next session can see what changed.

It’s a memory note in the table’s terms: context, like CLAUDE.md, not enforcement. Keep rules the team shares in a committed CLAUDE.md and rules with no exceptions in hooks. Counterparts runs beside your CLAUDE.md and auto memory: it never writes to either, and never reads auto memory’s MEMORY.md.

In Claude Code (Node 22.15 or newer), install it from a terminal, then restart Claude Code:

npm install -g counterparts@latest
counterparts

On macOS or Linux you can install it as a plugin instead of the two lines above, not as well: /plugin marketplace add mlapeter/counterparts, then /plugin install counterparts@counterparts, then restart Claude Code. It’s free and open source, with no account or API key, and the memory stays on your computer. Counterparts for Claude Code has the details. For claude.ai, a hosted version is in beta with limited spots: Counterparts for claude.ai. There’s no Codex, Cursor or ChatGPT version, so there the rule files, hooks and checks above are the whole answer.

What we haven’t tested

This page is a research summary. Vendor docs were read November 21, 2026 (Claude Code 2.1.330). User reports are one person’s or one team’s setup. Reddit was read through the Arctic Shift archive, not opened live.

Questions people ask

Does Claude learn from my corrections?

Not in the sense of the model changing. Nothing you type changes the model you’re talking to. What carries over is text: a line you add to CLAUDE.md, or a note Claude Code’s auto memory writes (Anthropic files corrections under a feedback type). That text is loaded into later sessions as context, and Anthropic says it isn’t “enforced configuration”. When Anthropic says auto memory “lets Claude learn from your corrections”, it means Claude writes a note.

Why does Claude ignore a rule that’s in my CLAUDE.md?

Anthropic’s troubleshooting page says CLAUDE.md “is delivered as a user message after the system prompt” and that there’s “no guarantee of strict compliance, especially for vague or conflicting instructions.” Run /context all to check the file loaded, make the line concrete (“Run npm test before committing”), remove lines that contradict it, and keep the file under about 200 lines. If it still gets missed and it has no exceptions, move it into a hook.

I’ve corrected the same thing twice in one session and it’s still wrong. What now?

Start over with a better prompt. Anthropic’s best-practices page: “after two failed corrections run /clear and write a better prompt instead of a third,” because a third correction adds to a conversation that already holds two failed attempts for Claude to keep re-reading. Put the lesson in the new prompt, and in CLAUDE.md if it will come up again.

How do I stop Claude Code from saying tests pass when they don’t?

Ask for the command and its output with every “done”, and have it re-run the tests after any edit made since the last run. In one team’s 150 sessions (#104504 on GitHub), 32 of the 36 unbacked “tests pass” claims in the development set they labelled first came from a run made before a later edit, and 73% of test runs were piped through tail or head, which hides a failing exit code unless set -o pipefail is on. For a check Claude can’t skip, a Stop hook can run the tests and send Claude back to work when they fail.

Should I use a hook or a CLAUDE.md rule?

A hook for a rule with no exceptions, where a script can see the mistake in the command or file path (never edit migrations/, always use make test). CLAUDE.md for guidance Claude may need to weigh. Anthropic’s tip: “If you keep adding emphasis to a CLAUDE.md line and Claude still misses it, that’s a sign the line belongs in a hook.”

Does the same advice work for Codex and Cursor?

Mostly. Codex reads AGENTS.md files and has hooks with a blocking PreToolUse and a Stop event that can send it back to work; its local memories are off by default, and OpenAI calls them “a helpful recall layer”. Cursor has project rules in .cursor/rules/ (or AGENTS.md), user rules, team rules, and hooks that can deny a shell command or keep the agent going after it stops.

Does Counterparts stop Claude repeating mistakes?

Counterparts, the memory we make, is Claude’s memory of you and your work together, written by Claude in its own words, and it reaches every project, so a correction about how you like to work doesn’t stay in one repository. It’s context, like any memory note, so for a rule that must hold every time, use a hook or a test. We haven’t measured whether it cuts repeated mistakes.

Questions? Ask in r/AIMemorySystems.

References