Skip to content
Membase
How to Add Persistent Memory to Claude Code

How to Add Persistent Memory to Claude Code

Give Claude Code Long-Term Memory in 2 Minutes

Research
MembaseMembase Team
View the original post on Medium

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: 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 topic files for each project. It needs Claude Code v2.1.59 or later and is on by default.

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:

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

In this guide: Does Claude Code have memory? · CLAUDE.md · Auto memory · The /memory command · Why Claude Code forgets · What forgetting looks like · Your options · Add persistent memory with Membase · 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:

ScopeLocationUse it for
Managed policySet by your organizationCompany-wide rules
User~/.claude/CLAUDE.mdYour personal preferences in every project
Project./CLAUDE.md or ./.claude/CLAUDE.mdTeam conventions, committed to the repo
Local./CLAUDE.local.mdPersonal 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.

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: fixes that worked, preferences it learned from your corrections, decisions you made together.

How it works:

  • Each git repository gets a memory folder at ~/.claude/projects/<project>/memory/. It's shared across worktrees of the same repo, and it stays on that machine.
  • MEMORY.md is the index. 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.
  • Other files in the folder (for example debugging.md) are topic files, read only when needed.
  • Turn it off in /memory, with "autoMemoryEnabled": false in your settings, or with the environment variable CLAUDE_CODE_DISABLE_AUTO_MEMORY=1.

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/<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-<ULID> and old numbers never change. The code still says max + 1.

WhenWhereWhat Claude Code suggests
TuesdaySame laptopINV-<ULID>, if auto memory saved it
WednesdayYour other laptopmax + 1: auto memory didn't come with you
ThursdayYour teammate's Claude Codemax + 1: the decision lives on your machine
FridayCursormax + 1: Cursor never saw the conversation
Months laterSame laptopmax + 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

OptionSetupWorks across machinesShared with teammatesShared with other AI toolsCost
CLAUDE.md, updated by handNoneIf committed to gitIf committed to gitNoFree
Auto memoryOn by defaultNoNoNoFree
Local memory pluginOne installNoNoSomeUsually free
Hosted memory plugin or MCP serverOne installYesDepends on the toolYesVaries
MembaseOne commandYesYes, with a key scoped to the same MemoryYes: Codex, Gemini CLI, Cursor, ChatGPT, ClaudeFree in beta

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).

Set it up in 2 minutes:

  1. Sign up at app.membase.com, open Connect > Developer keys and create a key. Create a Memory named after your repo.

  2. Add Membase to Claude Code:

    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. 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:

LayerKeep here
CLAUDE.mdRules that should always apply: commands, coding style, architecture
Auto memoryWhat Claude learns on this machine in this repo
MembaseDecisions 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).

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

Membase is in beta and free during the beta.

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 needs Claude Code v2.1.59 or later.
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 local plugin are enough. For several machines, teammates or tools, use a hosted memory layer. See Best MCP Memory Servers in 2026.
Back to all posts