Persistent Memory for Agents: claude-mem, planning-with-files and MCP Memory Servers
Persistent agent memory comes in two kinds: an on-disk task plan that survives /clear and compaction (planning-with-files), and a recall store for past decisions (claude-mem, the Memory MCP server, basic-memory). If you are a developer running a task across several sessions, start with the plan on disk and add a recall store only when you need answers across weeks.
It is day two of a feature. Yesterday’s session hit 80% context, you ran /clear, and this morning the agent spends twenty minutes re-reading the repository, proposes the retry design you rejected on day one, and has no idea which tests already pass. This page is for developers who run agent tasks longer than one context window, and for tech leads deciding which memory tools are allowed near company code.
What persistent memory gives you on a multi-day task
Section titled “What persistent memory gives you on a multi-day task”- A decision table for the five places agent memory can live, with what each costs and where your data goes
- planning-with-files installed in Claude Code, Codex or Cursor, and a check that its hooks actually fire
- A worked example: resume a half-finished task after
/clearwithout re-explaining it - A multi-day feature workflow built on
task_plan.md,findings.mdandprogress.md, with a verification gate per phase - Safe installs for claude-mem, the Memory reference server and basic-memory, and the traps in each
Which memory tool fits which job?
Section titled “Which memory tool fits which job?”Start with what your agent already has. CLAUDE.md, .claude/rules/ and auto memory in Claude Code, and AGENTS.md in Codex, carry durable project knowledge through reviewed commits; the Claude Code memory system and long-term context retention patterns cover them. Codex also has a memories feature, stable but off by default (checked with codex features list on 0.157.1). The tools on this page solve two different problems those files do not.
| Tool | What it keeps | Where it lives | Always-on cost | Leaves your machine? | Best for |
|---|---|---|---|---|---|
| planning-with-files | The live plan for one task: phases, findings, progress | Three Markdown files in the project | ~1,124 tokens (plugin 3.20.8) | No; the skill has no upload path | Tasks that span sessions or days |
| claude-mem | Compressed observations of every session, searchable | SQLite (~/.claude-mem/claude-mem.db) plus Chroma | ~2,000 tokens (13.25.3) plus injected context | Depends on --provider; the default offers a hosted observer | Recall across many tasks and weeks |
| Memory reference server | A knowledge graph of entities, relations, observations | One JSONL file (MEMORY_FILE_PATH) | MCP tool schemas only | No | Small, explicit facts a chat client should keep |
| basic-memory | Markdown notes linked into a graph | ~/basic-memory by default | MCP tool schemas only | No, unless you route a project to its cloud | Human-readable notes shared with Obsidian |
CLAUDE.md, AGENTS.md, auto memory | Conventions and decisions for the repo or for you | The repo, or ~/.claude/projects/ | The file size | No | Anything the whole team should know |
Token costs are what claude plugin details reported on Claude Code 2.1.283 on 2026-09-26, from the research for this page. The claude-mem figure was measured on 13.25.3; 13.28.0 is current, so rerun claude plugin details claude-mem@thedotmack after installing. Hooks cost no context unless they inject text, and claude-mem’s SessionStart hook does.
Popularity, as of 2026-09-26 (GitHub stars read through the GitHub API that day): thedotmack/claude-mem 94.7k, OthmanAdi/planning-with-files 27.1k, basicmachines-co/basic-memory 4.0k. The Memory server lives in modelcontextprotocol/servers (90.6k stars for the whole repository, not for Memory alone). Stars measure attention on a repository, not fitness for your codebase.
Install planning-with-files in your agent
Section titled “Install planning-with-files in your agent”The hooks are what make planning-with-files work: they re-inject the plan on every prompt and after /clear. Every route below keeps the hooks; the one-line skills install does not, so it comes last.
If plugins and marketplaces are new to you, read how plugins work in the three agents first. Run inside a Claude Code session:
/plugin marketplace add OthmanAdi/planning-with-files/plugin install planning-with-files@planning-with-filesThen, in a terminal, check what it loads into every session:
claude plugin details planning-with-files@planning-with-filesOn 3.20.8 that reported 14 skills, 6 hooks and about 1,124 always-on tokens; the README listed v3.21.0 on 2026-09-26, so rerun the command after every update. Back in the session, run /planning-with-files:plan-doctor: it prints one PASS, WARN or FAIL line each for plan resolution, injection, attestation, install surfaces and hook latency.
The vendor’s Codex guide installs a repository skill plus standalone hooks. Run in the project root:
git clone https://github.com/OthmanAdi/planning-with-files.git /tmp/planning-with-filesmkdir -p .agents/skills .codexcp -r /tmp/planning-with-files/.agents/skills/planning-with-files .agents/skills/cp /tmp/planning-with-files/.codex/hooks.json .codex/hooks.jsoncp -r /tmp/planning-with-files/.codex/hooks .codex/hooksrm -rf /tmp/planning-with-filesHooks are stable and on by default in codex-cli 0.157.1, but Codex only runs a new hook after you trust it: open the TUI, run /hooks, and review each entry. If .codex/hooks.json already exists, merge the entries instead of overwriting the file. The repository also ships a Codex plugin package; do not enable it together with the standalone hooks, because Codex runs every matching hook from every source.
The vendor’s Cursor guide copies a .cursor directory with the skill, hooks.json and hook scripts:
git clone https://github.com/OthmanAdi/planning-with-files.git /tmp/planning-with-filesmkdir -p .cursorcp -r /tmp/planning-with-files/.cursor/skills /tmp/planning-with-files/.cursor/hooks .cursor/cp /tmp/planning-with-files/.cursor/hooks.json .cursor/hooks.jsonrm -rf /tmp/planning-with-filesMerge hooks.json by hand if the project already has one. On Cursor the plan is injected when a conversation starts (sessionStart), not on every prompt, so start a new chat after /clear-style resets. The vendor guide says Cursor Cloud Agents do not run sessionStart, so a cloud run gets no plan context from the hook. These details come from the project’s docs/cursor.md; cursor.com was unreachable from our environment on 2026-09-26.
For any other agent, the Agent Skills route installs the skill in one line:
npx skills add OthmanAdi/planning-with-files --skill planning-with-files -gThe README describes this route as the pattern “without lifecycle hooks”: no slash commands, no per-turn plan injection and no SessionStart recovery. Use it when your agent has no plugin route, and expect to ask for the plan explicitly after a reset.
Resume a task after /clear with planning-with-files
Section titled “Resume a task after /clear with planning-with-files”This example uses Claude Code. The Codex and Cursor routes above install no slash commands, so there you start the plan by asking for it (the first prompt below already does), skip the /planning-with-files:* commands, and reset with /new in Codex or a new chat in Cursor.
-
Start the plan. Run
/planning-with-files:plan, then paste the task prompt below. The agent writestask_plan.md,findings.mdandprogress.mdin the project root. Type the namespaced command: in Claude Code, a bare/planis the built-in plan mode. -
Work through the first phases. As it goes, the agent appends research to
findings.md, logs commands and test results inprogress.md, and ticks items intask_plan.md. Check/planning-with-files:statusfor the current phase and totals. -
Checkpoint before the reset. When context runs high, paste the checkpoint prompt further down so the three files hold everything the next session needs.
-
Run
/clear. The conversation is gone; the files are not. -
Paste the resume prompt. The
UserPromptSubmithook injects the plan head before the model sees your message. -
Check what you see. The agent’s first reply names the current phase and the next step exactly as
task_plan.mdstates them, and it runs the last recorded test command before editing code. If it starts re-exploring the repository instead, run/planning-with-files:plan-doctor.
Run a multi-day feature on plan, findings and progress files
Section titled “Run a multi-day feature on plan, findings and progress files”The example above covers one reset. A feature that spans a week needs the files to carry the whole loop, from plan to merge, and to carry proof, not only intent.
-
Plan (day 1). Agree the approach in plan mode, then have the agent write it into
task_plan.mdas phases, each with a runnable exit check. For larger features, write the spec first; see spec-driven development. Lock the approved plan with/planning-with-files:plan-attest: hooks then stop injecting the plan, and print[PLAN TAMPERED], iftask_plan.mdno longer matches the attested SHA-256, which catches silent rewrites. -
Build (days 1–4). One phase at a time. The agent logs every decision in
findings.mdwith its reason (“rejected exponential backoff in memory: lost on restart”), so a later session cannot re-propose it. -
Verify at every phase boundary. A phase moves to
completeonly after its exit check passes and the output is pasted intoprogress.md. For unattended stretches, gated mode (run/planning-with-files:pwfand ask for gated mode in the task text, or initialise with the skill’sinit-session.sh --gated) holds the agent’s stop while a phase is stillin_progress, with a block cap (PWF_GATE_CAP, default 20 consecutive blocks) so an unfinished plan cannot trap the session. -
Checkpoint at the end of each day. Paste the checkpoint prompt below, then close the session. Tomorrow starts with the resume prompt.
-
Review. Give the reviewer, human or agent, the diff plus
task_plan.mdandprogress.md. The question is no longer “is every line right?” but “does every phase have passing evidence, and does the diff stay inside the plan?” -
Ship and promote. The plan files are working memory: the README says they are gitignored by default and the next task overwrites the root plan. Before you merge, move durable knowledge out of them: architecture decisions into an ADR, conventions into
CLAUDE.mdorAGENTS.md. Then delete the files.
Two or more tasks in one repository need their own plans. init-session.sh "<name>" creates .planning/YYYY-MM-DD-<slug>/ with the same three files, and PLAN_ID pins a terminal to one of them. On the Codex and standalone hook routes, several named plans and no PLAN_ID means the hooks refuse to inject context rather than guess. On Cursor, the bash hooks read only the root task_plan.md, so use one root plan per worktree there. Separate git worktrees, one per task, are the simpler alternative; see running agents in parallel.
Add cross-session recall with claude-mem
Section titled “Add cross-session recall with claude-mem”claude-mem records what happens in every session through hooks, compresses it with a model, and lets a later session search it through the mem-search skill and an MCP server with search, timeline and get_observations tools. It answers questions that no task plan holds, across weeks and tasks.
The default installer finishes setup and then asks you to sign in to the hosted “claude-mem observer” (a 30-day free trial, per the README; afterwards it falls back to your Anthropic plan unless you subscribe). For company code, choose the provider yourself. Run in a terminal:
npx claude-mem install --provider claude # compress with your own Anthropic plan; no sign-innpx claude-mem telemetry disable # anonymous telemetry is on by defaultnpx claude-mem doctor # checks Bun, uv and the worker--provider accepts claude, gemini, openrouter or host (npx claude-mem --help, 13.28.0, the npm latest on 2026-09-26). The same help lists --ide codex-cli and --ide cursor for Codex and Cursor; we did not run those routes. The installer’s --disable-auto-memory flag turns off Claude Code’s own auto memory; decide deliberately whether you want both stores writing notes. Wrap anything that must never be stored in <private> tags.
Use an MCP memory server: the reference Memory server or basic-memory
Section titled “Use an MCP memory server: the reference Memory server or basic-memory”An MCP memory server exposes memory as tools the agent calls on purpose, and the setup is the same idea in all three tools. The reference Memory server keeps a knowledge graph in one JSONL file; set MEMORY_FILE_PATH, or the file lands inside the npx package cache. basic-memory writes plain Markdown notes to ~/basic-memory, readable in any editor or Obsidian; it is AGPL-3.0, and its cloud sync is optional.
claude mcp add memory -e MEMORY_FILE_PATH=$HOME/.agent-memory/memory.jsonl -- npx -y @modelcontextprotocol/server-memoryclaude mcp add basic-memory -- uvx --prerelease=allow basic-memory mcpcodex mcp add memory --env MEMORY_FILE_PATH=$HOME/.agent-memory/memory.jsonl -- npx -y @modelcontextprotocol/server-memorycodex mcp add basic-memory -- uvx --prerelease=allow basic-memory mcpAdd to .cursor/mcp.json (project) or ~/.cursor/mcp.json (global), with your own absolute path:
{ "mcpServers": { "memory": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-memory"], "env": { "MEMORY_FILE_PATH": "/Users/me/.agent-memory/memory.jsonl" } }, "basic-memory": { "command": "uvx", "args": ["--prerelease=allow", "basic-memory", "mcp"] } }}Versions on 2026-09-26: npm @modelcontextprotocol/server-memory 2026.8.31, PyPI basic-memory 0.23.2. For a coding team, a fact the whole team needs belongs in CLAUDE.md or AGENTS.md, where it changes through review; the reference MCP servers page explains when the Memory server is worth running at all.
How do you prove agent memory is helping?
Section titled “How do you prove agent memory is helping?”Memory is context, not evidence. Every recalled fact can be stale, so put a cheap check at each point where memory re-enters the work:
- The resume test. After
/clear, the first reply must repeat the current phase and Next Step fromtask_plan.mdand rerun the last exit check. A reply that does not is a failed install, not a bad prompt. - Evidence per phase. A phase is complete only when
progress.mdholds the passing output of its exit check. The reviewer, or a review agent, checks the diff against the plan and that evidence instead of reading every line. - Citations for recall. A claude-mem answer carries observation IDs and dates, and a basic-memory answer carries note paths; the prompt then checks the claim against code and
git log. - Context cost. Run
/contextin Claude Code before and after installing a memory tool. If a recall store injects more than it saves, remove it. - Who signs off. The developer owns the plan and its exit checks. The tech lead decides which stores may hold company code, especially any tool whose provider sends session content to a third party.
What breaks with persistent agent memory?
Section titled “What breaks with persistent agent memory?”- The agent ignores the plan after
/clear. The hooks are not firing: the skills-only route, an untrusted Codex hook, or a Cursor Cloud Agent. In Claude Code, run/planning-with-files:plan-doctorand fix the failing line; in Codex, open/hooksand trust each planning-with-files hook; in Cursor, start a new chat sosessionStartfires. Then paste the resume prompt again. On a Cursor Cloud Agent, no hook fires: start the run with “Read task_plan.md, findings.md and progress.md first” as the opening instruction. - The wrong plan is injected. Two named plans exist and the pointer moved. Run the plugin’s
set-active-plan.sh --list, then start the session withPLAN_IDset to the right one. - The agent re-proposes a rejected design. The rejection lived only in the conversation. Add it to
findings.mdwith the reason, and make the end-of-day checkpoint a habit. - Recall contradicts the code. claude-mem or the Memory graph holds a decision that a later commit reversed. Trust the code and
git log, delete or correct the stale observation, and keep “check against the code” in every recall prompt. - Sessions got expensive. Two memory tools plus auto memory inject overlapping context. Keep one recall store, measure with
/context, and uninstall the rest (npx claude-mem uninstallfor claude-mem). - Company code reached a hosted service. Someone accepted the claude-mem sign-in. Rerun the installer with an explicit
--provider, and have the tech lead add the approved install command to the team’s setup notes.