<!-- generated by build_articles.py — edit content/answers/claude-code-memory.md instead -->
---
title: "Claude Code memory 2026: CLAUDE.md vs MCP memory server"
canonical: "https://xerj.org/answers/claude-code-memory"
updated: "2026-11-14"
source: "content/answers/claude-code-memory.md"
---

# Claude Code memory: CLAUDE.md, auto memory, or an MCP memory server?

**Short answer** (updated 2026-11-14): How does Claude Code memory work? Claude Code loads CLAUDE.md files you write and an auto memory index Claude writes at the start of every session. For more history than fits in context, or memory shared across agents, add an MCP memory server such as XERJ that the agent searches on demand.

**Key number:** Claude Code loads the first 200 lines or 25KB of MEMORY.md at the start of each session; topic files are read on demand. (as of 2026-10-30; source: [code.claude.com/docs/en/memory](https://code.claude.com/docs/en/memory))

**TL;DR** CLAUDE.md suits short rules for every session. An MCP memory server suits facts the agent looks up later. Claude Code memory has two built-in sources. CLAUDE.md files hold rules you write, and auto memory holds notes Claude writes. Both load at the start of each session. When you need search over more than fits in context, add an MCP memory server that the agent calls only when it needs a fact.

## Agent prompt

```text
Act as a coding agent. Read https://xerj.org/llms.txt, install XERJ, start a local node, run claude mcp add --scope user xerj -- xerj mcp, store one fact about this repo with xerj_memory_store, start a new session, recall it with xerj_memory_recall, and report the result.
```

*Figure: The two built-in systems load on their own. A memory server adds search over more than fits in context, and only costs tokens when the agent asks. Based on the Claude Code memory docs, checked 2026-10-30.*

## What loads at session start

Claude Code does not start from a blank page. Before you type anything, it already has a stack of files in context. That stack can include a managed policy, your user CLAUDE.md, the project CLAUDE.md (or AGENTS.md if that file is missing), optional local notes and path-scoped rules, and then the auto memory index.

That stack is useful because the same rules show up in every session. It is also the limit. The docs say to keep each CLAUDE.md under 200 lines, and they say Claude reads only the first 200 lines or 25KB of MEMORY.md at start. Topic files are pulled later, when they look relevant. Anything bigger than those windows is either trimmed or left out of the default load.

Step through the order below. Each step is one source the official memory docs describe, plus an optional memory server at the end.

*Figure: Steps 1 to 6 come from the Claude Code memory docs (code.claude.com/docs/en/memory), checked 2026-10-30. Step 7 is optional and only happens if you add an MCP memory server.*

## The built-ins compared with a memory server

Who writes the notes, when they load, and who can share them are the differences that matter in practice.

| | CLAUDE.md | Auto memory | MCP memory server |
| --- | --- | --- | --- |
| Who writes it | You | Claude | The agent, through a tool |
| When it loads | Every session, in full | MEMORY.md at start; topics on demand | Only when called |
| Size guide | Under 200 lines per file | First 200 lines or 25KB of MEMORY.md | Limited by disk, not context |
| Shared | Through git, for project files | One machine, all worktrees of a repo | Any agent that can reach the server |
| Best for | Rules for every task | Lessons Claude picks up | Facts you look up later |

Use the picker to match those rows to the week you are actually having. If your notes are short and only Claude Code needs them, stay with the built-ins. If the notes are long, shared, or must be searched later, add a server.

*Figure: Runs in your browser and sends nothing. Each answer adds a point to the setup it matches. This is a rule of thumb from the Claude Code memory docs (checked 2026-10-30) and from how an MCP memory server is called, not a benchmark.*

## When the built-ins are enough

For one person, one repo and one agent, start with CLAUDE.md and auto memory. Put build commands and code style in the project file so the team shares them in git. Put personal habits, such as "explain shell commands before running them," in your user file. Let auto memory collect corrections like "always use pnpm, not npm".

Check what auto memory saved with `/memory` now and then. The index lives at `~/.claude/projects/<project>/memory/` and is shared across worktrees of the same repo. If a lesson is really a rule that should load every time, move it into CLAUDE.md yourself. That keeps the start-of-session context small and stable.

## When to add a memory server

Add one when notes are too long to load every time. Add one when you want to search past sessions, or when other agents should share the same facts. A memory server stores those facts outside the context window. The agent calls it with a query and gets the top matches. You pay tokens only for what it actually reads back.

That is the idea behind an [MCP memory server](/answers/what-is-an-mcp-memory-server): tools to save and recall, over the same protocol the client already uses. If you also want to look through old Claude Code JSONL on disk, that is a file-search job, covered in [search Claude Code past sessions](/answers/search-claude-code-past-sessions). For how memory compares across open-source tools on the same questions, see the [AI agent memory benchmark](/compare/ai-agent-memory-benchmark) and the [mcp-memory-service comparison](/compare/xerj-vs-mcp-memory-service).

## A recorded recall example with XERJ

We stored three memories in a local XERJ node and queried them with default settings, which use BM25 full-text search.

| Query | Result |
| --- | --- |
| pnpm | "User prefers pnpm over npm", score 1.0526 |
| what port does the API use | "The API runs on port 9200", score 2.9425 |
| which package manager | No match |
| deploy day | No match |

Keyword recall finds exact words fast and shows why it matched. It misses a question that uses other words. For those, ask for semantic or hybrid recall, or store the words you expect to search for. These four queries were recorded on 2026-10-30 on a local node, namespace demo, default mode.

## How to try it with XERJ

Use the Copy the prompt button and paste it into Claude Code. It installs XERJ, adds it as an MCP server for all your projects and checks recall in a new session. By hand:

```bash
curl -fsSL https://xerj.org/get | sh
claude mcp add --scope user xerj -- xerj mcp
```

The same node can also index your repo for [code search](/answers/code-search-mcp-for-claude-code) and your [past Claude Code sessions](/answers/search-claude-code-past-sessions). To compare XERJ with claude-mem and MemPalace, see [this comparison](/compare/xerj-vs-claude-mem-and-mempalace). For the broader idea of memory the agent manages itself, see [what agentic memory is](/answers/what-is-agentic-memory).

## Sources checked

- Claude Code memory docs, [code.claude.com/docs/en/memory](https://code.claude.com/docs/en/memory), checked 2026-10-30: file locations, load order, the 200 line and 25KB limits, /memory and the disable setting.
- XERJ recall results: local node, namespace demo, default mode, recorded 2026-10-30.

## Read next

[the AI agent memory benchmark](/compare/ai-agent-memory-benchmark), [XERJ vs Memvid](/compare/xerj-vs-memvid), [agentic memory](/science/agentic-memory), [context engineering](/science/context-engineering) and [best MCP memory servers for Claude Code](/compare/best-mcp-memory-servers-claude-code-2026).

More comparisons: [OpenViking alternatives 2026](/compare/openviking-alternatives-2026).

More comparisons: [best memory for AI coding agents 2026](/compare/best-memory-for-ai-coding-agents-2026).

## FAQ

### Where does Claude Code store auto memory?

In ~/.claude/projects/<project>/memory/ on your machine. A MEMORY.md file is the index and topic files hold the details. All worktrees of the same repo share it.

### How long should CLAUDE.md be?

The docs suggest under 200 lines per file. Longer files use more context and Claude may follow them less closely.

### How do I turn auto memory off?

Use the /memory command to toggle it, or set CLAUDE_CODE_DISABLE_AUTO_MEMORY=1.

### Does Claude Code read AGENTS.md?

Yes, when a directory has no CLAUDE.md, recent versions read AGENTS.md instead.

### When do I need a memory server?

When notes outgrow what should load every session, when you want search over old sessions, or when several agents should share one memory.

### Does XERJ replace CLAUDE.md?

No. Keep rules that apply every time in CLAUDE.md. Use XERJ for facts the agent looks up only when needed.

## Related

- [How do people store user preferences so an agent can recall them next week?](/answers/coding-agent-memory-across-sessions)
- [What is an MCP memory server?](/answers/what-is-an-mcp-memory-server)
- [Claude Code search conversation history](/answers/search-claude-code-past-sessions)
- [MemPalace vs claude-mem (and XERJ): which memory should Claude Code use?](/compare/xerj-vs-claude-mem-and-mempalace)
- [I need my agent to find a passage and cite the file, not dump the whole tree. How?](/answers/code-search-mcp-for-claude-code)
- [AI agent memory benchmark 2026: real tests on 7 open-source projects](/compare/ai-agent-memory-benchmark)
- [XERJ vs mcp-memory-service: two MCP memory servers, tested](/compare/xerj-vs-mcp-memory-service)
- [How to use agentic memory in XERJ](/answers/what-is-agentic-memory)
- [What's a simple way to give an agent long-term memory on my laptop without Qdrant?](/answers/agent-memory-without-postgres-qdrant) (same intent: agent memory)
- [Best MCP memory servers for Claude Code in 2026: 8 compared, with install lines](/compare/best-mcp-memory-servers-claude-code-2026) (same intent: agent memory)
- [Best memory for AI coding agents in 2026: ai-memory, claude-mem and Beacon compared](/compare/best-memory-for-ai-coding-agents-2026) (same intent: agent memory)
