# Claude Code Memory: How It Works and How to Add Persistent Memory

*CLAUDE.md, Auto Memory, Memory Plugins, and Long-Term Memory in 2 Minutes*

Published: 2026-11-03 · Updated: 2026-11-17 · Author: Membase Team  
Source: https://membase.com/blog/claude-code-memory

> *Disclosure: Membase is our product. Claude Code's built-in memory is good, and for many solo projects it is all you need. We say where. Claude Code features were checked against Anthropic's Claude Code documentation in November 2026.*

## Quick answer

Claude Code has two kinds of built-in memory:

- **CLAUDE.md (or AGENTS.md):** instructions you write. Claude Code loads them at the start of every session.
- **Auto memory:** notes Claude writes for itself as it works, in a MEMORY.md index plus one file per memory for each project. It’s on by default in local sessions.

Use the /memory command to see, open and toggle these files.

Claude Code still forgets in four places: on your other machines, for your teammates, in your other AI tools, and once its memory index grows past what loads at startup. To fix that, add a memory layer that lives outside one machine. With Membase it takes one command:

```bash
npx add-mcp 'https://api.app.membase.com/mcp-http'
```

**In this guide:** [Does Claude Code have memory?](https://membase.com/blog/claude-code-memory#does-claude-code-have-memory) · [CLAUDE.md](https://membase.com/blog/claude-code-memory#claudemd-memory-you-write) · [Auto memory](https://membase.com/blog/claude-code-memory#auto-memory-memory-claude-writes) · [The /memory command](https://membase.com/blog/claude-code-memory#the-memory-command) · [Why Claude Code forgets](https://membase.com/blog/claude-code-memory#why-claude-code-forgets) · [What forgetting looks like](https://membase.com/blog/claude-code-memory#what-forgetting-looks-like) · [Your options](https://membase.com/blog/claude-code-memory#your-options-for-longer-lasting-claude-code-memory) · [Memory plugins](https://membase.com/blog/claude-code-memory#claude-code-memory-plugins) · [Add persistent memory with Membase](https://membase.com/blog/claude-code-memory#add-persistent-memory-with-membase) · [FAQ](https://membase.com/blog/claude-code-memory#faq)

## Does Claude Code have memory?

Yes, with limits.

Inside one session, Claude Code remembers everything in its context window. When the session ends, that conversation is gone. A new session starts from the files on disk and whatever memory files load at startup.

So "memory" in Claude Code means files: the ones you write (CLAUDE.md) and the ones Claude writes (auto memory).

## CLAUDE.md: memory you write

CLAUDE.md is a Markdown file of instructions. Claude Code reads it in full at the start of every session.

It can live in several places, from broadest to most specific:

| Scope | Location | Use it for |
| --- | --- | --- |
| Managed policy | Set by your organization | Company-wide rules |
| User | ~/.claude/CLAUDE.md | Your personal preferences in every project |
| Project | ./CLAUDE.md or ./.claude/CLAUDE.md | Team conventions, committed to the repo |
| Local | ./CLAUDE.local.md | Personal notes for one project; add it to .gitignore |

Tips:

- Run /init in a project to generate a starter CLAUDE.md.
- Import other files instead of copying them, for example @README.md or @AGENTS.md.
- Keep each CLAUDE.md under 200 lines. Longer files use more context, and Claude follows them less consistently.
- Already have an AGENTS.md? Claude Code reads it when there’s no CLAUDE.md. See [AGENTS.md vs CLAUDE.md vs SKILL.md](https://membase.com/blog/agents-md-vs-claude-md).

**Good for:** stable rules. Build and test commands, coding style, architecture notes.

**Not good for:** decisions you make while chatting. Claude Code won't add them to CLAUDE.md unless you ask.

## Auto memory: memory Claude writes

Auto memory is Claude taking its own notes. It saves four kinds:

| Type | What it holds |
| --- | --- |
| user | Your role, expertise and working preferences |
| feedback | Corrections you give Claude and approaches you confirm |
| project | Ongoing work, deadlines and decisions Claude can't work out from the code or git history |
| reference | Where to find information outside the project, such as an issue tracker or dashboard |

Claude skips anything it can work out from the codebase, such as architecture, file paths or debugging fixes, and anything your CLAUDE.md already says. It doesn’t save something every session; it saves what would help in a future conversation.

How it works:

- Each git repository gets a memory folder at ~/.claude/projects/&lt;project>/memory/. It’s shared across worktrees and subfolders of the same repo, and it stays on that machine.
- MEMORY.md is the index, one line per memory. Claude Code loads its first 200 lines, or first 25 KB, whichever comes first, at the start of each session. Anything past that isn’t loaded.
- Each memory is its own file in the folder (for example feedback_testing.md), read only when needed.
- To store memory somewhere else, set autoMemoryDirectory in your settings.json to an absolute path or a path starting with ~/.

**Turn it on or off** in /memory, with the auto memory toggle. To turn it off for one project, add this to that project’s settings:

```json
{
  "autoMemoryEnabled": false
}
```

Or set the environment variable CLAUDE_CODE_DISABLE_AUTO_MEMORY=1.

Auto memory is on by default in local sessions. In a self-hosted environment it starts off.

The files are plain Markdown. Open and edit them yourself to correct what Claude wrote.

## The /memory command

Type /memory in Claude Code to:

- See your memory files
- Open CLAUDE.md or auto memory files to edit them
- Turn auto memory on or off

**How to clear Claude Code memory:** open the file from /memory and delete the lines you no longer want, or delete the project's folder under ~/.claude/projects/&lt;project>/memory/ to start auto memory fresh.

## Why Claude Code forgets

The built-ins are designed for one developer, on one machine, in one tool. Outside that, they forget:

1. **On your other machines.** Auto memory lives in your home directory. A second laptop, a server or a cloud sandbox starts with nothing but what is committed in CLAUDE.md.
2. **For your teammates.** Each developer's auto memory stays on their machine. A new teammate's Claude Code doesn't know what yours learned last month.
3. **In your other AI tools.** Cursor, Codex and ChatGPT keep their own memory. A decision made in Claude Code doesn't reach them.
4. **As the index grows.** Only the first 200 lines of MEMORY.md load at startup. As it grows, older notes can fall outside what Claude sees.

And one more: if neither you nor Claude writes a decision down, no file has it, so the next session can't know it.

## What forgetting looks like

On Monday, you and Claude Code agree that new invoice numbers use INV-&lt;ULID> and old numbers never change. The code still says max + 1.

| When | Where | What Claude Code suggests |
| --- | --- | --- |
| Tuesday | Same laptop | INV-&lt;ULID>, if auto memory saved it |
| Wednesday | Your other laptop | max + 1: auto memory didn't come with you |
| Thursday | Your teammate's Claude Code | max + 1: the decision lives on your machine |
| Friday | Cursor | max + 1: Cursor never saw the conversation |
| Months later | Same laptop | max + 1: the note fell outside the first 200 lines of MEMORY.md |

Nothing is broken. The memory just isn't where the work is.

## Your options for longer-lasting Claude Code memory

| Option | Setup | Works across machines | Shared with teammates | Shared with other AI tools | Cost |
| --- | --- | --- | --- | --- | --- |
| CLAUDE.md, updated by hand | None | If committed to git | If committed to git | No | Free |
| Auto memory | On by default | No | No | No | Free |
| Local memory plugin | One install | No | No | Some | Usually free |
| Hosted memory plugin or MCP server | One install | Yes | Depends on the tool | Yes | Varies |
| Membase | One command | Yes | Yes, with a key scoped to the same Memory | Yes: Codex, Gemini CLI, Cursor, ChatGPT, Claude | Free, then $19/mo |

## Claude Code memory plugins

If the built-ins aren’t enough, the main choices are:

- **[claude-mem](https://github.com/thedotmack/claude-mem):** an open-source plugin (Apache 2.0) that captures what your agent does during sessions, compresses it with AI and adds relevant context to future sessions. It also works with Codex, OpenClaw, Gemini, Hermes, Copilot and OpenCode.
- **MCP memory servers:** Mem0, Supermemory, Basic Memory, the official Knowledge Graph server and others, connected with claude mcp add. We compare nine in [Best MCP Memory Servers in 2026](https://membase.com/blog/best-mcp-memory-servers).
- **Membase:** one hosted memory that Claude Code shares with your other machines, your teammates and your other AI tools, with automatic recall through hooks. Setup is below.

## Add persistent memory with Membase

Membase is a memory layer for AI agents. It keeps one memory outside any single machine or tool, so Claude Code can save what matters and bring it back in the next session, wherever you work.

What it does differently:

- **Recalls on every prompt, automatically.** With the Claude Code hooks, relevant memory is added at session start and to every message you send. Claude doesn't have to decide to look.
- **Never blocks you.** Recall waits up to 10 seconds; if Membase is slow, the hook moves on and the results arrive with your next prompt.
- **Saves once, in the background.** Each session is saved when it ends, without slowing Claude Code down.
- **One memory, everywhere.** The same Memory works on every machine. Give each teammate's agent its own key scoped to that Memory, and revoke it any time.
- **Every answer has a source.** Each search result points back to the session or document it came from.
- **Hosted or local.** Use the hosted service, or keep memory on your own machine with local mode.
- **Fewer tokens.** Membase's engine scores 93.1% on LoCoMo while using up to 11x fewer tokens than the full history (our own numbers; [see the method](https://membase.com/research)).

**Set it up in 2 minutes:**

1. Sign up at [app.membase.com](https://app.membase.com), open Connect > Developer keys and create a key. Create a Memory named after your repo.
2. Add Membase to Claude Code:

   ```bash
   claude mcp add --transport http membase https://api.app.membase.com/mcp-http \
     --header "Authorization: Bearer $MEMBASE_API_KEY"
   ```

3. For automatic recall on every prompt, install the Claude Code hooks: follow [Membase Use Case 01: Claude Code Persistent Memory](https://membase.com/blog/membase-use-case-01-coding-agents). The same installer works for Codex CLI and Gemini CLI.
4. Test it: decide something specific, quit, open a new session and ask about it without mentioning it.

## Use it alongside CLAUDE.md and auto memory

You don't have to choose. Each layer has its job:

| Layer | Keep here |
| --- | --- |
| CLAUDE.md | Rules that should always apply: commands, coding style, architecture |
| Auto memory | What Claude learns on this machine in this repo |
| Membase | Decisions and context that must follow you across machines, teammates and tools |

The same Memory also works in Cursor (add the MCP server to .cursor/mcp.json) and in ChatGPT and Claude (connect Membase as a custom connector). Guides for other tools: [Codex](https://membase.com/blog/codex-memory) · [OpenClaw](https://membase.com/blog/openclaw-memory).

## Common mistakes

- **Putting everything in CLAUDE.md.** Long files are followed less consistently. Keep rules there and let memory hold the rest.
- **Running /clear or /compact before saving decisions.** Ask Claude to note important decisions first.
- **Letting MEMORY.md grow unchecked.** Review it now and then so important notes stay in the first 200 lines.
- **One memory for every repo.** Create one Memory per repository so projects don't mix.

## Start building with Membase

- Get an API key: [app.membase.com](https://app.membase.com) > Connect > Developer keys
- Tutorial: [Membase Use Case 01](https://membase.com/blog/membase-use-case-01-coding-agents)
- MCP server: [https://api.app.membase.com/mcp-http](https://api.app.membase.com/mcp-http)
- Docs: [docs.membase.com](https://docs.membase.com)
- Official docs: [How Claude remembers your project](https://code.claude.com/docs/en/memory)

Membase has a free plan, then $19 or $69 a month.

See also: [Cross AI Memory: How to Use One Memory Across ChatGPT, Claude, Cursor and More](https://membase.com/blog/cross-ai-memory)

## Frequently Asked Questions

### Does Claude Code have memory?

Yes. CLAUDE.md files you write, and auto memory notes Claude writes itself. Both load at the start of a session.

### How do I use the /memory command in Claude Code?

Type /memory to see and open your memory files and to turn auto memory on or off.

### What is Claude Code auto memory?

Notes Claude writes for itself in ~/.claude/projects/<project>/memory/, with MEMORY.md as the index loaded at startup. It saves four kinds of notes: user, feedback, project and reference.

### Is Claude Code auto memory on by default?

Yes, in local sessions. Turn it off in /memory, with “autoMemoryEnabled”: false in a project’s settings, or with CLAUDE_CODE_DISABLE_AUTO_MEMORY=1.

### How do I clear Claude Code memory?

Edit or delete lines in the files from /memory, or delete the project's auto memory folder.

### Does Claude Code load all of MEMORY.md?

No. It loads the first 200 lines or 25 KB, whichever comes first. Keep important notes near the top.

### Does Claude Code memory sync across machines?

No. Auto memory stays on the machine that wrote it. Only what you commit in CLAUDE.md travels with the repo. Use a hosted memory layer to sync.

### Can Claude Code and Cursor share memory?

Not with the built-ins. Connect both to the same memory layer, such as Membase.

### Can I use Membase with CLAUDE.md and auto memory?

Yes. Keep rules in CLAUDE.md, let auto memory handle local learnings, and use Membase for what must follow you across machines, teammates and tools.

### What is the best memory plugin for Claude Code?

It depends on what you need. For one machine, the built-ins or a plugin such as claude-mem are enough. For several machines, teammates or tools, use a hosted memory layer. [See Best MCP Memory Servers in 2026.](https://membase.com/blog/best-mcp-memory-servers)
