[BUG] Memory rules written to persistent files are not enforced after context compaction

Resolved 💬 3 comments Opened Mar 10, 2026 by YooClid Closed Mar 13, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Reproduction Steps
During a conversation, Claude makes a mistake (e.g., reading a stale cache file instead of calling a live API)
User corrects Claude; Claude writes a rule to memory/critical_rules.md: "Never read crypto_positions.json — always use live API"
Context compaction occurs (or new session starts)
Claude immediately reads crypto_positions.json again, presenting 3-day-old data as live data
User catches the error again — same mistake, same file, rule already documented
Impact
Financial risk: In a trading system, stale data led to incorrect position analysis (showed BTC at 1.79M KRW when actual was 148K KRW — 12x overestimate)
Trust erosion: User has to manually catch and correct every repeated mistake
Memory is write-only: Rules are saved but not reliably applied to behavior
Expected Behavior
Rules in persistent memory files should be actively checked before taking relevant actions
At minimum, critical_rules.md (or equivalent) should function as pre-action constraints, not just passive reference
Environment
Claude Code CLI (VS Code extension)
Model: claude-opus-4-6

What Should Happen?

Rules in persistent memory files (e.g., memory/critical_rules.md) should be actively enforced after context compaction or new session starts. At minimum, critical_rules.md should function as pre-action constraints, not just passive reference that gets ignored.

Error Messages/Logs

Steps to Reproduce

  1. In a Claude Code session, make a mistake that the user corrects (e.g., reading stale data from a local file instead of calling a live API)
  2. Write a rule to the persistent memory file memory/critical_rules.md: "Never read crypto_positions.json — always use live API"
  3. Continue the conversation until context compaction occurs (or start a new session)
  4. Ask Claude to check crypto positions again
  5. Claude reads the same forbidden file (crypto_positions.json) and presents 3-day-old data as live data — despite the rule being loaded into context via MEMORY.md

Claude Model

None

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.1.71

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

VS Code integrated terminal

Additional Information

_No response_

View original on GitHub ↗

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