Agent writes lessons to persistent memory but consistently fails to apply them in execution

Resolved 💬 3 comments Opened Mar 19, 2026 by dmax1 Closed Mar 23, 2026

Description

Claude Code's persistent auto memory system (~/.claude/projects/.../memory/MEMORY.md) allows the agent to record lessons learned across sessions. However, there is a fundamental disconnect: the agent records rules to memory but does not change its execution behavior based on those rules.

Reproduction

Over the course of ~30 sessions (2026-02-05 to 2026-03-19) working on a multi-service ecosystem with a team of agents, the following pattern repeatedly occurred:

  1. Agent makes a mistake (e.g., sends implementation instructions without verifying against project contracts/specifications)
  2. User corrects the agent
  3. Agent acknowledges the mistake and writes a lesson to MEMORY.md
  4. In a subsequent turn or session, agent makes the exact same mistake
  5. User corrects again
  6. Agent writes another variation of the same lesson to memory
  7. Cycle repeats

Concrete Example

The rule: "Verify implementation details against contracts (the project's source of truth) before dispatching work to teammate agents."

How many times it was written to memory (6 separate entries, same file):

Line 64: "Never present teammate claims as fact — VERIFY by reading code"
Line 71: "Always verify contracts first on discrepancies"  
Line 109: "Read architecture BEFORE dispatching"
Line 110: "Verify implementation against contracts BEFORE dispatching"
Line 112: "Include architecture context in every task message"
Line 117: "Never label without evidence, verify against contracts"

What happened despite all 6 entries existing in memory:
The agent sent a teammate to implement a credit pre-check feature using SSE event type insufficient_credits and error code B203. Neither exists in the project contracts. The contracts explicitly state B203 is for "Subscription required" (not credits) and that B203 should NOT be returned for the endpoint in question. The agent did not check the contracts before dispatching — the user had to catch the error.

This is not a one-time occurrence. The same class of mistake (acting without verifying against contracts/specifications) has been corrected by the user at least 8 times across sessions, each time resulting in a new memory entry, with no observable improvement in behavior.

Expected Behavior

When the agent loads MEMORY.md at the start of a session (which it does — the file is loaded into the system prompt), rules recorded in memory should materially influence the agent's execution flow. If a rule says "verify X before doing Y," the agent should actually verify X before doing Y.

Actual Behavior

The agent:

  1. Loads MEMORY.md into context (confirmed — it's in the system prompt)
  2. Has access to 6 variations of the same rule
  3. Ignores all of them during execution
  4. Only acknowledges them when the user points out the failure
  5. Then writes yet another entry to memory

The act of writing to memory appears to serve as a substitute for actually changing behavior, rather than as a mechanism that drives behavioral change.

Impact

  • User must manually catch errors that the agent's own memory system was designed to prevent
  • Trust erodes as the same mistakes repeat despite apparent "learning"
  • Memory file grows with redundant entries that have no practical effect
  • In a team coordination scenario (team lead + multiple agent teammates), uncaught errors propagate to teammates who implement incorrect specifications

Environment

  • Claude Code CLI
  • Model: claude-opus-4-6
  • Persistent auto memory enabled (~/.claude/projects/.../memory/MEMORY.md)
  • Multi-session usage over 6+ weeks
  • Team/swarm mode with multiple agent teammates

Possible Root Causes

  1. Memory is loaded but not weighted for execution — the rules exist in the system prompt but compete with the immediate task context and don't create actionable checkpoints in the agent's reasoning
  2. No execution hooks — memory entries are passive text, not procedural triggers. Writing "verify contracts before dispatching" doesn't create an actual verification step in the agent's workflow
  3. Recording substitutes for learning — the agent may treat the act of writing the lesson as completing the corrective action, without internalizing the behavioral change
  4. Context compression loses emphasis — in long sessions, memory rules may lose salience after context compression even though the file remains in the system prompt

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗