On this page#
- Claude Code memory is persistent context, not model memory
- Why memory exists
- How Claude Code memory actually works
- When you need memory and when you do not
- The part vendors leave out
- FAQ
Claude Code memory is persistent context, not model memory#
Claude Code memory is a set of durable instructions and notes that Claude Code loads into its working context across sessions. It does not retrain the model or give it perfect recall. It makes repository conventions, commands, constraints, and selected discoveries available without requiring an engineer to repeat them in every prompt.
That distinction matters. “Memory” sounds like the agent remembers everything it has seen, but it does not. A fresh session still has a finite context window and cannot reconstruct an old conversation unless the relevant information was saved somewhere it can load.
In practice, the term covers two related mechanisms described in the Claude Code documentation:
- Instructions maintained by people, usually for stable project knowledge.
- Notes maintained by Claude Code, where that capability is enabled, for useful information discovered during work.
Both are context inputs. Neither is a database of complete project history, a substitute for source control, or a guarantee that every instruction will be followed.
If you remember one sentence, use this one: Claude Code memory is a persistence layer for selected context, not a persistent brain.
Photo by Snapwire on Pexels.
Why memory exists#
Memory exists because real repositories contain important rules that are not reliably inferable from source code alone. Without a durable context layer, engineers must repeat those rules in prompts, keep a separate setup document open, or accept that each new session will rediscover the same commands, conventions, and failure modes.
Before repository-level agent instructions, teams mostly relied on:
- README files written for humans.
- Onboarding documents that agents might never read.
- Copy-pasted “starter prompts.”
- Shell history and personal notes.
- Corrections repeated after the agent made a predictable mistake.
Those approaches scatter operational knowledge. A README may explain the product but omit the required verification command. A starter prompt becomes stale. A correction given in one chat disappears with that chat.
Claude Code’s value proposition is broader than memory: it is an agentic coding tool that can inspect a codebase, edit files, and use development tools, as the official Claude Code overview explains. Memory narrows the gap between that general capability and the rules of one specific repository.
The strongest memory entries are invariants: facts that should remain true across tasks and sessions. Examples include:
- “Generated files must not be edited directly.”
- “Run the focused test before the full suite.”
- “Database migrations must be backward-compatible.”
- “This package cannot import from the application layer.”
- “Use the repository wrapper instead of invoking the tool directly.”
This is also why memory should not become an encyclopedia. Architecture explanations belong in maintained documentation. Task state belongs in an issue or plan. Code behavior belongs in tests and types. Memory should point the agent toward those systems and state the rules it must not miss.
How Claude Code memory actually works#
Claude Code memory works by loading stored text into the agent’s context, alongside your prompt and the code or tool output needed for the current task. The model then reasons over that material. The text can influence decisions, but it does not become a hard policy engine and cannot override what the repository actually does.
The human-controlled form is commonly associated with CLAUDE.md: a Markdown file containing instructions Claude Code should consider while working. The official Claude Code documentation is the authority for supported locations, scope, imports, and related configuration.
The practical model is hierarchical:
- Broad instructions apply across work.
- Repository instructions describe shared project rules.
- More local instructions can describe a narrower directory or component.
- The active task adds temporary context through the current conversation.
That hierarchy is useful because a monorepo rarely has one universal workflow. A frontend package and a migration package may use different commands and have different safety constraints. Putting every rule into one global file creates noise and contradictions.
Automatic memory, where available, serves a different purpose. It lets Claude Code retain selected discoveries across sessions instead of requiring every useful fact to be manually promoted into project instructions. That can reduce repeated investigation, but it also introduces a governance problem: generated notes are not automatically correct just because the agent wrote them.
Treat the two forms differently:
| Memory type | Best for | Owner | Trust level | |---|---|---|---| | Repository instructions | Stable commands, invariants, boundaries | Team | Reviewed guidance | | Personal instructions | Individual preferences and workflow | Engineer | Local preference | | Automatic notes | Reusable discoveries and reminders | Agent, supervised by engineer | Provisional context | | Current conversation | Task-specific decisions | Active participants | Temporary context |
Memory competes for attention with your prompt, code, diagnostics, and tool results. More text is not automatically better. A short instruction with a command and a reason is more useful than several paragraphs of background.
For a broader mental model of agent foundations—context, tools, constraints, and verification—see PairFoundry Foundations.
Photo by Lukas Blazek on Pexels.
When you need memory and when you do not#
You need Claude Code memory when the same repository-specific correction would otherwise be repeated across sessions or engineers. You do not need it for facts already enforced by code, facts that change with the current task, or generic advice the agent can derive without help.
Use memory when at least one of these conditions is true:
- The repository has non-obvious commands or wrappers.
- A plausible edit can violate an architectural boundary.
- Generated and hand-written files are easy to confuse.
- Verification requires a specific sequence.
- Multiple engineers want the agent to follow the same conventions.
- The agent repeatedly chooses a reasonable but wrong path.
A useful test is simple: if a competent engineer could inspect the repository and still make the mistake, the constraint is a good candidate for memory.
Do not add memory merely because information is important. Add it when the information must be present during agent decision-making and no stronger mechanism already enforces it.
Prefer stronger controls where possible:
- Use tests for behavior.
- Use types and schemas for structural guarantees.
- Use linters for mechanical conventions.
- Use permissions for prohibited operations.
- Use source control for history and rollback.
- Use issues or plans for task progress.
- Use maintained documentation for explanations.
Memory is justified when it connects those controls to the agent: which command runs the test, where the schema lives, or why a tempting shortcut is invalid.
Do not use it for transient statements such as “the build is currently failing” or “finish endpoint B next.” Those facts expire quickly and can mislead a later session. Keep task state in the task.
Teams adopting a wider agent workflow may also want the PairFoundry packs overview, while related term-level explanations live in Plain Definitions.
The part vendors leave out#
Memory creates a new source of repository behavior, and that source can be stale, contradictory, or wrong. Official documentation explains how memory is supplied, but teams still have to decide who owns it, how it is reviewed, and what happens when stored instructions disagree with executable reality.
The common mistake is treating memory as a dumping ground. That produces three costs.
First, long files consume context and dilute important constraints. If twenty minor preferences surround one migration safety rule, the agent may not give the safety rule the attention it deserves.
Second, memory can preserve obsolete knowledge. A renamed command in code is visible immediately; an old command in an instruction file continues sounding authoritative until someone removes it.
Third, instructions are not enforcement. An agent can misunderstand them, miss a conflict, or follow them while still producing a defective change. The Claude Code overview describes an agent capable of acting through development tools; that capability makes verification more important, not less.
Use these operating rules:
- Keep entries short, specific, and testable.
- Explain unusual constraints with one sentence of rationale.
- Link to canonical repository documentation instead of duplicating it.
- Review shared memory like code.
- Remove entries when automation makes them redundant.
- Treat agent-written memory as untrusted until inspected.
- Resolve conflicts in favor of current code, explicit task requirements, and executable checks.
The right memory file is intentionally incomplete. Its job is to prevent high-cost misunderstandings, not to narrate the entire repository.
Photo by Digital Buggu on Pexels.
Related reading#
- Copilot API — a plain explanation for people with a real repo
- Claude Code system prompt: the definition, and the part vendors leave out
FAQ#
Should a team commit CLAUDE.md to the repository?#
Commit it when the instructions describe shared repository behavior that every contributor’s agent should follow. Keep personal preferences out of the shared file. A committed memory file should have clear ownership, ordinary code review, and changes tied to actual workflow or architectural changes.
Shared instructions might cover required commands, generated files, and module boundaries. Editor preferences or an individual’s preferred response style belong in personal configuration. The official locations and scoping rules should come from the Claude Code documentation, not assumptions copied from another repository.
What should we do when memory gives Claude Code the wrong instruction?#
Stop relying on the instruction, inspect its scope, and correct or remove the stored text before continuing. Then verify the repository’s current behavior through code, configuration, and executable checks. Do not “fix” working code merely to make it agree with stale memory.
If the bad instruction caused edits, use source control to review and revert those edits selectively. Memory is guidance; Git remains the rollback system. Add an automated check if the mistake represents a durable invariant that tooling can enforce.
How is Claude Code memory different from normal project documentation?#
Project documentation explains the system to readers; memory supplies selected constraints directly to the agent while it works. The two should reinforce each other, but memory should be shorter and more operational. Duplicating entire design documents into memory creates drift and wastes context.
A good entry points to the canonical document and states the decision-relevant rule. For example: identify the approved migration process, link to its documentation, and name the required verification command.
Can automatic memory be trusted in a team workflow?#
No. Treat automatically written memory as a provisional note, not reviewed project truth. It can capture a useful discovery, but it can also preserve a misunderstanding or a condition that was only true during one task. Shared rules require human review and deliberate promotion.
The safe path is to inspect important notes, confirm them against the repository, and move stable facts into team-owned instructions or stronger automated controls.
When should we avoid Claude Code memory entirely?#
Avoid adding memory when the repository is small, conventions are obvious, and existing automation already prevents the mistakes you care about. Also avoid it for secrets, rapidly changing task state, speculative conclusions, and instructions that attempt to replace tests or permissions.
An empty memory file is better than a misleading one. Add persistence only after you can name the repeated decision it improves.