DEV Community

John Rood
John Rood

Posted on

Your AI agent forgets everything between sessions. Here is why, and the memory layer I built to fix it

Yesterday my coding agent and I spent forty minutes deciding that the billing service would use idempotency keys stored in Postgres, not Redis, and why. This morning I opened a new session and asked it to implement the retry path. It proposed Redis. Then it asked me what the service was called.

If you use Claude Code, Codex, Cursor, or a chat assistant for real work, you have lived some version of this. The agent re-asks a question you answered three times this week. It rewrites a helper that already exists two directories over. It forgets the convention you corrected it on yesterday and you correct it again, a little more tersely each time. It is not dumb. It has no memory. Those are different problems, and only one of them is fixable by you.

I run a small fleet of agents every day and I got tired of being their memory. This post is what I learned about why they forget, what actually fixes it, and the numbers from the system I built and now depend on.

The context window is not memory

The first thing to unlearn is that a bigger context window solves this. It does not. A context window is working memory for one session. It starts empty every time, it fills up, and when it fills up something has to go.

Three mechanisms are doing the damage.

Sessions are isolated by design. Every new session starts from the system prompt plus whatever you type. Nothing from yesterday is in there unless something put it there. The model cannot reach back into a prior conversation. There is no prior conversation, from its point of view.

The vendor holds whatever memory exists. ChatGPT has a memory feature. Claude has project knowledge. Some coding agents keep a per-project notes file. Each of these lives inside one product, in one format, controlled by one company. Switch tools and it stays behind. Get rate limited or change plans and it is not yours to take. You cannot query it, export it cleanly, or point a second tool at it.

Compaction destroys detail. Long sessions get summarized so they fit. That summary is lossy in the worst way: it keeps the shape of a decision and drops the reasons. "Chose Postgres for idempotency keys" survives. "Because the Redis cluster is shared with the rate limiter and a flush there would replay charges" does not. Two weeks later the agent sees the decision without the constraint and cheerfully proposes the thing the constraint was protecting against.

So you end up with a coworker who is brilliant for ninety minutes and then gets replaced by a clone with amnesia.

The fix is a layer you own

Once I framed it that way the architecture was obvious. Memory has to sit outside any one model or product, and it has to be mine.

The shape that works:

  1. A store you control. Memories live in a vault keyed to you, not to a vendor account. Every tool you use points at the same vault.
  2. Recall before the prompt. Before the model sees your message, something searches the vault for what is relevant and injects it. The agent does not have to remember to look things up. It just knows.
  3. Capture after the turn. When a turn completes, the useful parts get written back. Decisions, corrections, constraints, preferences.
  4. Tiered storage. Raw turns are noisy. Over time they get consolidated into reflections, and reflections into higher level ones, so a search returns the distilled version and can still drill down to the raw source when detail matters.

That is MemoryRouter. I built it for my own agents first, and it has been in daily use across everything I run. What follows are measurements from that use, not a benchmark I staged.

What it looks like in production

For a typical vault, which in practice means under 15,000 vectors, recall lands in the 300 to 500 ms range. That is the number that matters for most people reading this, because it is what you will see: the agent pauses for well under a second before it answers, and then it answers like it was in the room yesterday.

My own vault is the heavy end. It is the one all my agents write to, and it has been accumulating for months.

  • 66,486 vectors in the main vault, more than four times a typical size
  • 6,758 memory injections logged
  • 43.6 memories per injection on average, about 9,264 tokens of recalled context per prompt
  • Prepare latency at that size: p50 2,369 ms, p90 4,285 ms
  • Of that, embedding the query averages 248 ms and the tiered search across 4 shards averages 551 ms. The rest is the remainder of the prepare step.

Two things I want to be plain about. First, those latency figures are for an oversized vault and they still come in around two seconds at the median. That is the scaling story, not the typical one. Second, the 9,264 tokens per injection is a lot of context. It is the right tradeoff for me because the alternative is re-explaining the same architecture to a fresh agent every morning, but it is a real cost and you should size your recall to your work.

What the numbers do not show is the part that changed how I work. Sessions stopped being resets. I start a new Claude Code session, ask it to continue the billing work, and it knows about the Postgres decision and the reason behind it, because the reason is in the vault, not in a compacted summary that dropped it.

Wiring it in

Two of the paths I use every day, plus the generic one. Every snippet below is taken from the current docs and I run these commands myself.

Claude Code. One command installs lifecycle hooks that recall before each prompt and capture at the end of each turn.

npx -y memoryrouter-claude init
Enter fullscreen mode Exit fullscreen mode

Check that it took:

npx -y memoryrouter-claude doctor
Enter fullscreen mode Exit fullscreen mode

If you also want explicit memory tools inside Claude Code (search, store, status), add the MCP server and sign in:

npx -y memoryrouter-claude mcp install --local
claude mcp login memoryrouter
Enter fullscreen mode Exit fullscreen mode

Full reference: https://docs.memoryrouter.ai/claude-code

Codex. Same idea, user scope so every trusted project gets it.

npx -y memoryrouter-codex init --scope user
npx -y memoryrouter-codex doctor --scope user
Enter fullscreen mode Exit fullscreen mode

Full reference: https://docs.memoryrouter.ai/codex

OpenClaw. It ships as a plugin, and you can upload prior workspace and session history so the agent is not starting from zero.

openclaw plugins install npm:mr-memory
openclaw mr upload
openclaw mr status
Enter fullscreen mode Exit fullscreen mode

Full reference: https://docs.memoryrouter.ai/openclaw

Any MCP client. Claude desktop and web, Cowork, ChatGPT in Developer mode, and anything else that speaks remote Streamable HTTP with OAuth: add this as a remote server, complete the browser authorization, and pick your vault.

https://mcp.memoryrouter.ai/mcp
Enter fullscreen mode Exit fullscreen mode

The tools it exposes include search_memories, store_memory, date_search_memories, and memory_status. Ask the client to run memory_status in a new chat and you will see the connection is live. Protocol details, scopes, and the full tool list: https://docs.memoryrouter.ai/mcp

A note on stdio-only clients: this is an HTTPS endpoint, not an executable. Adding the URL as a local command will not work. You need a client with remote MCP support or a bridge.

Moving your ChatGPT history with you

This is the part that made a few friends switch. Most people have months or years of context sitting in ChatGPT: their role, their projects, the way they like things explained, the decisions they made in long threads. When they try Claude or a coding agent, all of that is gone and the new tool feels stupid by comparison.

There are two ways to bring it over. The fast way is a single prompt you paste into ChatGPT. It hands back everything it knows about you, you approve what moves line by line, and it saves into your vault. About two minutes. The thorough way is to request your official ChatGPT data export, then run it through the advanced import, which pulls the detail out of the actual conversations rather than ChatGPT's summary of you.

Either way, once it is in the vault, Claude, Cursor, Codex, and everything else pointed at that vault knows the history immediately. You did the explaining once, years ago, to a different product. You should not have to do it again.

Walkthrough: https://memoryrouter.ai/chatgpt-to-claude-memory

What is still rough

I would rather you hear this from me.

Dedupe is not automatic. If you tell three different agents the same fact on the same day, you get three memories. Consolidation into reflections tidies this up over time, and search handles near duplicates fine, but the raw tier will carry redundancy until then. It is fixable, and it is on the list.

Team access control is early. Per-user vaults, key scoping, and organization features exist, but if you want fine grained roles across a large team, what is there today is closer to a foundation than a finished permissions system. Shared team memory is on the Enterprise plan for that reason.

Query sensitivity needs tuning. Recall is a search, and searches have a threshold. Set it loose and the agent gets 9,000 tokens of tangentially related context. Set it tight and it misses the one constraint that mattered. The defaults are reasonable for coding work, but you will want to adjust them to your own vault after a week or two.

None of these change the core proposition. They are the things I would want to know before I pointed my agents at it.

Try it

MemoryRouter is 14 days free, then $20 a month. There is no markup on inference, because your model calls do not have to go through us at all. Bring your own provider keys and the memory layer stays exactly that, a layer.

Start here: https://app.memoryrouter.ai/signup?utm_source=devto&utm_medium=article&utm_campaign=agent-memory-layer

Install it on one project, work for a week, then open a fresh session and ask the agent what you decided last Tuesday. That is the whole test.

Top comments (0)