Aident AI

Claude Code Auto Memory Stale or Too Large? Audit It Safely
If Claude Code keeps repeating a correction, recalls an outdated project fact, or behaves differently after a long-running repository accumulates memories, audit auto memory before rewriting CLAUDE.md or deleting hidden files. Claude Code stores auto memory separately from your repository instructions, loads only the first 200 lines or 25KB of its MEMORY.md index at session start, and shares that auto-memory directory across worktrees in the same Git repository.
The safe fix is not a blind reset. First prove which memory surface loaded, make a recoverable copy, measure the index, trace each suspect claim to its source, and then either shorten the index or disable auto memory at the narrowest scope. Keep rules that must be reviewed by the team in version-controlled project instructions instead of relying on model-written notes.
Know which memory layer you are debugging
Claude Code currently has two different persistent context mechanisms:
Surface | Who writes it | Best use | Important limit |
|---|---|---|---|
| You or your team | Stable instructions, commands, architecture, and review policy | Context, not mechanical enforcement |
Auto memory | Claude | Machine-local learnings, preferences, and project observations | First 200 lines or 25KB of |
Auto memory is on by default. Its directory contains a short MEMORY.md index plus topic files. Anthropic documents that MEMORY.md is loaded automatically, while topic files are read on demand. The files stay until you or Claude edits or deletes them; the normal transcript-retention sweep does not remove them.
This distinction matters. A correct CLAUDE.md does not prove auto memory is current, and a stale auto-memory entry does not mean your tracked instructions failed to load. If your symptom appears only in a Git worktree, use the narrower Claude Code worktree memory guide first.
1. Record the symptom without teaching the answer
Start a fresh Claude Code session in the affected repository. Record:
the exact Claude Code version;
the repository root and current worktree path;
the smallest prompt that produces the stale or missing fact;
the answer Claude gives before you correct it;
whether the problem survives a fresh session.
Do not put the correct answer into the test prompt. Use a harmless project fact, never a secret or live credential. A good probe asks Claude to identify the source it used and allows it to answer that the fact is unavailable.
Expected result: you get a reproducible answer plus a claimed source, not a new memory write disguised as diagnosis.
2. Confirm what loaded with /context and /memory
Inside the fresh session, run:
Use /context to confirm which instruction files entered the session. Use /memory to verify whether auto memory is enabled and open the exact auto-memory folder for this repository. Do not infer the directory from an old path or another checkout.
Claude Code derives auto-memory identity from the Git repository, so all worktrees and subdirectories in the same repository normally share one auto-memory directory. Outside a Git repository, the project root is used instead. A stale note written from one worktree can therefore affect another even though their uncommitted files remain isolated.
Expected result: you can name the tracked instruction files, the auto-memory state, and the exact memory directory before changing anything.
3. Back up the exact memory directory
Close or pause sessions that might write to auto memory. In a separate shell, set explicit paths based on the directory that /memory showed:
If either test command fails, stop. Do not reuse an old backup directory or run a recursive delete to make the command pass. The copy should preserve the evidence you need to compare after the repair.
Never commit the backup automatically. Auto memory can contain local paths, private project facts, customer names, or copied tool output.
4. Measure the index before editing it
Inspect only the file counts and first loaded portion:
Anthropic documents two startup-load limits for MEMORY.md: 200 lines and 25KB. Content beyond the first reached limit is not loaded at session start. Claude Code may ask Claude to shorten an index near the threshold and returns an error after an oversized write, but the write itself can still succeed. That makes the next session the important verification boundary.
Classify the result before editing:
Observation | Likely problem | Next action |
|---|---|---|
| Later index entries may not load at startup | Shorten the index and move detail to topic files |
A suspect fact appears in the loaded portion | Stale or conflicting memory is actively available | Verify it against the repository, then correct or remove that entry |
The index points to a missing topic file | The memory map is internally inconsistent | Restore from backup or remove only the broken pointer after review |
| The tracked instruction layer did not load | Fix location or launch scope before touching auto memory |
The index is small and the fact is absent | The answer may come from conversation context or model knowledge | Reproduce in a fresh session and ask for the exact source |
Reports in the Claude Code issue tracker describe cascading bad answers from incomplete MEMORY.md summaries and silent loss of later index entries after the startup limit. Those reports establish real failure modes, but they do not prove every wrong answer is caused by auto memory.
5. Reconcile each suspect fact with a canonical source
For every stale entry, write down:
the exact memory line or topic file;
the version-controlled file, current documentation, or named owner that should decide the truth;
whether the fact is a stable instruction, a temporary task state, or a preference;
the minimal correction.
Move stable team rules into CLAUDE.md or a path-scoped rule and review them through Git. Use the CLAUDE.md audit guide to keep those instructions concise, current, and testable. Keep temporary task state in the issue or handoff that owns the work. Leave personal preferences in auto memory only when they are safe to persist locally.
Do not turn auto memory into a second architecture document. If a detail can be derived reliably from the repository, link the index to the canonical file instead of copying a paragraph that will drift.
6. Shorten the index without losing the evidence
Edit the copied backup first if you need to experiment. In the live directory, make one reviewed change at a time:
keep
MEMORY.mdas a concise index, ideally one line per topic;move supporting detail into clearly named topic files;
merge duplicate entries that point to the same source;
remove a stale statement only after verifying its replacement;
keep the most important current pointers inside the first 200 lines and 25KB.
Do not delete the entire memory directory just because one line is wrong. Do not replace it with an unreviewed third-party memory database during incident response. Both actions erase the comparison that tells you whether the repair worked.
After editing, rerun the line and byte counts. Then start a new Claude Code session, run /context and /memory, and repeat the original harmless probe.
Expected result: the answer cites the current canonical source or says the fact is unavailable; the removed stale statement does not reappear; and the index remains below both documented load limits.
7. Disable auto memory when isolation is safer
If you cannot yet trust the accumulated notes, temporarily disable auto memory rather than deleting them. Anthropic documents three controls:
use the toggle in
/memoryfor your user setting;set
autoMemoryEnabledtofalsein the project's settings for one project;launch with
CLAUDE_CODE_DISABLE_AUTO_MEMORY=1when you need an environment-level control.
For a project setting, merge the field into the appropriate existing settings file instead of overwriting the file:
For a one-launch comparison:
Repeat the same probe with no other changes. If the stale answer disappears, you have isolated the auto-memory layer, not necessarily found the bad line. If it remains, inspect conversation state, tracked instructions, and the repository itself.
Keep the backup until the repaired or disabled state has survived at least one fresh session. Restore settings deliberately after the test; do not leave a team unaware that a local context feature was disabled.
8. Use enforceable controls for rules that must never be skipped
Claude Code treats both CLAUDE.md and auto memory as context, not enforced configuration. A statement such as "never deploy from a worktree" can still be missed. For actions that must be blocked, Anthropic recommends a PreToolUse hook or another mechanical boundary.
Keep the layers separate:
Need | Correct home |
|---|---|
Team coding convention | Tracked |
Machine-local preference | Auto memory |
Current task state | Issue, plan, or handoff |
Prohibited command or protected path | Hook, permission, sandbox, or CI control |
Reusable cross-agent procedure | A reviewed Skill or runbook |
If a workflow should be reused across Claude Code, Codex, and other agents, package the procedure as a reviewed Skill rather than hoping each client's memory converges on the same steps. Aident Loadout can expose that Skill together with discoverable Actions, while Aident Vault keeps integration credentials out of memory files and prompts. This does not repair Claude auto memory; it gives portable procedures and external access their own explicit boundary.
What not to do
Avoid these tempting shortcuts:
deleting
~/.claudeor every project memory directory;copying one repository's memory into another;
committing auto-memory files without a privacy review;
treating a community issue as proof of your local root cause;
using a prompt instruction as the only protection for a destructive action;
expanding
MEMORY.mdwith more explanations when it is already near the load limit;testing several settings changes at once.
The diagnostic value comes from one controlled change, a preserved backup, and the same probe before and after.
Verification checklist
The repair is complete only when you can answer yes to all of these:
Did
/contextshow the expected tracked instruction files?Did
/memoryidentify the exact auto-memory state and directory?Is there a recoverable copy outside the live memory path?
Is
MEMORY.mdbelow 200 lines and 25KB?Does every retained high-impact entry point to a current canonical source?
Does a fresh session answer the original probe correctly or decline to guess?
Are mandatory restrictions enforced outside model-written memory?
Did you avoid exposing secrets, private paths, or customer data in a commit?
Sources and evidence
Anthropic: How Claude remembers your project, live-crawled and reviewed September 2, 2026.
Claude Code issue 23769: Auto-memory gets corrupted across sessions, reviewed September 2, 2026.
Claude Code issue 57574: MEMORY.md silently truncated near 25KB, reviewed September 2, 2026.
Claude Code issue 23750: Option to disable auto-memory, reviewed September 2, 2026.
Community workflow: replacing auto memory with a curated knowledge base, reviewed September 2, 2026.
Aident Loadout public CLI, connected Reddit search, Exa search, and live official-document retrieval evidence, September 2, 2026.
Follow the Aident setup guide to make one reusable agent procedure discoverable without storing provider credentials or volatile task state in Claude Code auto memory.
About the author
Aident AI
Related posts



The one tool
for every tool
your agent needs.
Give any AI agent real capabilities in seconds. Connect 27,000+ tools once, skip the setup headache, and let your agents execute.
