AI coding agents

Your AI coding agent keeps making the same mistake. Here is why, and how to stop it

On Tuesday you spent an hour on a failing build. The cause was a cache key, you found it, the agent fixed it. On Thursday a new session hits the same error, and the agent starts from the beginning: clear the cache, reinstall, retry. The two things you already ruled out come first.

You are not the only one. "I have to remind it every time I start a new session," someone wrote in the Cursor forum. Issue #14227 in the Claude Code tracker puts it shorter: "It's a goldfish."

The short answer

Every session starts with an empty context. What carries over is what the tool loads at the start: your instruction files and, in some tools, a few notes the tool wrote itself. Those notes are built for rules and preferences. A bug fix, the cause behind it and the approaches that failed are usually not among them. So the agent meets the bug as if for the first time.

The fix: write the lesson where the agent will find it again, and bring it back when the same problem shows up. Five ways to do that are below, from a test to a hook.

Three reasons it happens

  1. Each session starts empty. The Claude Code docs say it plainly: "Each Claude Code session begins with a fresh context window." Cursor's docs: "Large language models don't retain memory between completions." Compaction in a long session has the same effect: details become a summary. What survives /compact.
  2. Built-in memory is not made for fixes. Claude Code's auto memory "skips anything it can derive from the codebase, such as architecture, file paths, or debugging fixes." Copilot is told not to store "short-lived or task-specific instructions". The fix is in the code, true. The reason for it, and the dead ends, are not.
  3. Instruction files have a size limit in practice. Claude Code advises under 200 lines per CLAUDE.md: "Longer files consume more context and reduce adherence." Cursor advises rules under 500 lines. A team that writes down every fix passes that in a few months, and the agent follows all of it a little less. What to move out of a long CLAUDE.md.

What each tool remembers by itself

ToolWhat carries overWhere it appliesKeeps a bug fix?
Claude CodeCLAUDE.md, written by you. Auto memory, notes Claude writes itself; the first 200 lines or 25 KB of its index load at start.Auto memory is machine-local: one repository, one machine. CLAUDE.md goes wherever you commit it.Not by itself. Auto memory skips “debugging fixes” on purpose, because they can be derived from the code.
CursorRules (.mdc files in .cursor/rules) and AGENTS.md, written by you. The old Memories docs page now redirects to Rules.Project, user or team rules, as you set them up.Only if you write it down as a rule.
GitHub CopilotCopilot Memory: repository facts and your preferences, chosen and written by Copilot.A repository fact works only in that repository. Facts expire after 90 days without reinforcement (the default).Copilot decides. It is told not to store short-lived or task-specific instructions.

From the docs of each tool, as of 6 November 2026: Claude Code memory, Cursor rules, Copilot Memory.

Five ways to make a fix stick

  1. Write a test that fails when the bug comes back. It is the one way that does not depend on the agent remembering anything. A red test shows up in every session, in every tool, for every person on the team.
  2. Add one line to your instruction file, with the symptom. CLAUDE.md, AGENTS.md or a Cursor rule. The Claude Code docs name this exact moment: add to CLAUDE.md when "Claude makes the same mistake a second time". Write the symptom first, so the line matches what the agent sees: Build fails with "cache miss" → the cache key includes the lockfile hash; do not clear the cache.
  3. Block the wrong command with a hook. If the mistake is a command, a rule in a file is a wish. A PreToolUse hook runs before every tool call and can refuse it. The docs: "To block an action regardless of what Claude decides, use a PreToolUse hook."
    .claude/settings.json
    {
      "hooks": {
        "PreToolUse": [
          {
            "matcher": "Bash",
            "hooks": [
              { "type": "command", "command": "node .claude/hooks/no-npm.mjs" }
            ]
          }
        ]
      }
    }
    .claude/hooks/no-npm.mjs
    // Exit code 2 blocks the call. Claude reads the message on stderr.
    let raw = "";
    for await (const chunk of process.stdin) raw += chunk;
    const command = JSON.parse(raw).tool_input?.command ?? "";
    
    if (/\bnpm (install|i)\b/.test(command)) {
      console.error(
        "This repo uses pnpm. npm install rewrites the lockfile and breaks CI.",
      );
      process.exit(2);
    }
    More events and what each can block: Claude Code hooks.
  4. Write the dead ends down, too. "Tried a clean install, did not help, the cache key was the cause." Without that line, the next session tries the clean install again. What a useful note contains: Lessons learned for coding agents.
  5. Bring the matching note back for each prompt. Keep the notes in a file outside CLAUDE.md, and let a UserPromptSubmit hook look up the ones that fit the prompt you just typed. The agent gets three relevant lines instead of three hundred.

Rules versus experience

Ways 1 to 3 work well for rules: a convention, a forbidden command, a bug that must never return. Experience is different. It is the many small things a team learns every week: why the deploy fails on a full disk, which flag breaks the build, the migration that must run first.

Experience grows faster than any instruction file should. It also lives in several tools at once: one person uses Claude Code, another Cursor, the review runs in Copilot. Each tool keeps its own notes, on its own machine or in its own repository. A fix found in one tool does not reach the others.

With cachly

cachly does ways 4 and 5 for you:

  • In Claude Code, when a turn ends with a fix, cachly's Stop hook records it as a lesson: the symptom, the cause, what failed, the command that worked. In Cursor, Copilot and other editors, the agent saves lessons through cachly's MCP tool.
  • Before each prompt, a hook adds up to three matching lessons. When the cache error shows up on Thursday, Tuesday's fix is already in the context.
  • Lessons live in your instance, not on one machine. A fix saved in Claude Code shows up in Cursor and Copilot, and for your whole team.
Claude Code
/plugin marketplace add cachly-dev/cachly-mcp
/plugin install cachly-brain@cachly

Then turn on auto-update once: /plugin → Marketplaces → cachly → Enable auto-update. Claude Code leaves it off for marketplaces outside Anthropic's own, and the hooks update only with the plugin.

Lessons are stored on servers in the EU. What leaves your machine, and where it goes.

Sources

More: Auf Deutsch lesen: KI wiederholt denselben Fehler · Lost context after /compact · Cursor Memories removed · AI memory in three layers · All docs