The problem: stateless agents
When you run a Claude Code session or any AI agent, it has no built-in memory of previous interactions. Each new session is a blank slate. If your agent learned something useful last week—a workaround, a discovered API pattern, a user preference—that knowledge is lost.
For single-shot tasks this doesn't matter. But for ongoing automation, code review loops, or multi-stage projects, the agent repeats the same mistakes, rediscovers the same solutions, and wastes context tokens rehashing past events.
Claude-Mem fixes this by capturing session activity, compressing it with AI, and making it available as context for future runs. Your agent builds up a persistent knowledge base without you manually maintaining a changelog.
How Claude-Mem works
Claude-Mem is a Claude Code plugin built on lifecycle hooks. Per its README:
- Capture: hooks on SessionStart, UserPromptSubmit, PostToolUse, Stop and SessionEnd record tool-use observations during each session.
- Compress: a model turns those observations into semantic summaries.
- Store: a local worker service (managed by Bun) keeps sessions, observations and summaries in SQLite with full-text search, plus a Chroma vector database for hybrid semantic + keyword search.
- Retrieve: relevant context is injected into new sessions, and Claude can query past work through Claude-Mem's MCP search tools. A local web viewer shows your memory.
Besides Claude Code, the installer supports other agents and tools; check the README for the current list.
Fitting it into a Claude Code workflow
Claude Code runs discrete, often iterative tasks: debugging, generating features, refactoring. Without memory, you repeat context: "I tried approach X last session and hit problem Y." Claude-Mem eliminates that friction.
A typical workflow:
- You start a Claude Code session to work on a feature.
- Claude-Mem captures the agent's reasoning, code decisions, test results, and errors.
- Next session, Claude-Mem injects a summary: "Previously discovered that auth library version 2.x breaks with async patterns; use 1.9.x instead."
- Claude Code uses this to avoid the same pitfall.
This is especially valuable for long-running automation tasks where the agent needs to adapt based on past attempts. It also reduces context bloat—instead of pasting full logs, you get a compressed memory.
Real limitations
- Hosted by default: the installer asks you to sign in, and the default memory is the hosted CMEM Pro service. If your code or prompts must stay on your machine, opt out: pass an explicit
--providerflag or setCLAUDE_MEM_ONLINE_OPTIN=false, as the README describes. - Compression costs tokens: summarising observations calls a model, which adds cost and some latency.
- Summaries lose detail: for exact past outputs (an exact error message, a full diff) keep using git history and logs.
- Hooks run on every session: review what a plugin's hooks do before installing, and expect memory to grow over time.
- Stale memories: a lesson from last month can be wrong after a refactor; prune memory that no longer applies.
Getting started
npx claude-mem installOr from inside Claude Code:
/plugin marketplace add thedotmack/claude-mem
/plugin install claude-memDon't use npm install -g claude-mem for this: the README notes it installs only the SDK/library and does not register the hooks or start the worker. Restart Claude Code after installing; the next sessions start building memory automatically. Claude-Mem is Apache-2.0 licensed.