agentmemory is a free, MIT-licensed MCP server that fixes this. It stores your project knowledge locally and auto-injects roughly 2,000 characters of context into the first turn of every new session — so Claude Code picks up exactly where you left off.
Step 1: Install agentmemory from the repo
Clone or install the package from github.com/rohitg00/agentmemory. Follow the repo's README for the exact install command for your environment. The server runs locally — no cloud account required.
Step 2: Register it as an MCP server in Claude Code
In your Claude Code MCP settings, add agentmemory as a local MCP server entry. Point it to the agentmemory binary or start script. Once registered, Claude Code will be able to call its memory tools on demand.
Step 3: Configure the SessionStart hook
agentmemory includes a SessionStart hook that fires automatically at the beginning of each session. When triggered, it queries your memory store and injects a summary — up to ~2K characters — into the first message context. No manual prompting needed.
Verify the hook is active by checking the repo's hook configuration docs and confirming it appears in your MCP server logs on first launch.
Step 4: Store your first memories
During a session, use agentmemory's write tools to save things worth remembering:
- Project conventions (naming patterns, folder structure rules)
- Bug history (what broke, what fixed it)
- File structure observations Claude made on its own
- Decisions you want future sessions to respect
You can trigger writes explicitly with a prompt like: "Save this convention to memory: all API routes live in /src/routes and follow REST naming." Or configure agentmemory to capture certain outputs automatically.
Step 5: Share memory across tools
agentmemory uses a single local memory store that any compatible agent can read. Claude Code, Cursor, Codex, Gemini CLI, OpenCode, and Hermes can all point to the same server. Conventions saved from a Cursor session are available the next time you open Claude Code.
Why this works
Large language models have no native persistence between API calls — each session is stateless by design. agentmemory solves this at the infrastructure layer by acting as an external knowledge base that the model can query, rather than relying on the model's context window to carry information forward. The SessionStart hook is the key mechanism: it transforms passive storage into active recall by front-loading relevant context before the user types a single word.
Pro tips
- Be specific when writing memories. "Use Tailwind utility classes, avoid custom CSS files" is more useful to Claude than "we prefer Tailwind."
- Review your memory store periodically. Stale or contradictory entries will confuse future sessions — treat it like a living document.
- Use bug history entries. Recording what caused a regression and how it was fixed gives Claude Code a head start on the next similar bug.
- Keep the injected context under 2K characters. agentmemory is already designed around this limit, but if you write many verbose entries, prune or summarize older ones to keep retrieval sharp.
Want a hand?
Book a 30-min call.
Walk through your stack with us. We'll find the bottleneck and map out the exact wiring you need — free.