Why your coding agent forgets between sessions, and how to fix it
Last updated
A coding agent forgets because the model only knows what is in its context window, and every new session starts with an empty one. Nothing from yesterday's conversation comes back unless it was saved somewhere the agent reads or searches. The fix is to save what matters, such as decisions, preferences and how things work, in instruction files or a memory server, and have the agent read or search it at the start of each task.
What actually carries over
When a session ends, the conversation is gone from the model's point of view. What the next session sees is:
- Instruction files. Claude Code reads CLAUDE.md files at the start of each session, and Codex reads AGENTS.md files.
- The agent's own notes. Claude Code's auto memory saves notes in a folder on your computer and loads the start of its index file each session.
- The code itself. The agent can read the repository again, but it has to rediscover anything the code doesn't say: why a choice was made, what was tried and failed, who owns what.
- Tools. An MCP server the agent can call, such as a memory server, a ticket tracker or a docs search.
Everything else, including the hour you spent explaining a design, is lost unless it went into one of these.
Why it gets worse over time
Long sessions run into the same limit from the other side. When the context window fills, agents compact the conversation into a summary, and details drop out. Clearing the context between tasks keeps sessions fast and focused, but it also clears what the agent learned.
So the pattern most people see is: the agent is sharp at the start of a session, slows down and repeats itself as the session grows, and starts from zero in the next one.
Four ways to carry context across sessions
1. Keep a short instruction file
Put rules that rarely change into CLAUDE.md or AGENTS.md: build and test commands, style, where things live. Keep it short. Claude Code's documentation suggests under 200 lines per CLAUDE.md, because longer files use more context and are followed less closely.
2. Let the agent take notes
Claude Code's auto memory saves what you correct it on. It is a good default for one person on one computer. The notes stay on that machine and are not shared with other computers or agents.
3. Write a handoff before you stop
Ask the agent to write down where things stand before you end a session: what is done, what is next, what to watch for. Save it to a file or a memory, and tell the next session to read it first.
4. Connect a memory server
A memory server stores notes outside the session and outside one computer. The agent searches it for the task at hand instead of loading everything, and every agent you connect sees the same notes. Memlo is one; setup takes one command in Claude Code or Codex.
What to save
Save things that stay true and are expensive to rediscover:
- Decisions, with the reason. "Retries were cut from 5 to 3 because the provider rate-limits."
- Preferences. "This repo uses pnpm, not npm."
- How things work. "The billing service reads from the ledger-api."
- Mistakes not to repeat. "The staging database is shared; never run migrations from a laptop."
Don't save numbers that change every day, and never save passwords, API keys or tokens.
Frequently asked questions
Why does Claude Code forget everything when I start a new session?
Each session starts with a fresh context window. Claude Code reloads your CLAUDE.md files and the start of its auto memory, and nothing else from earlier sessions. Anything you want it to know next time has to be saved in one of those or in a tool it can search.
Is a bigger context window the fix?
It helps within one session, but it does not carry anything into the next session. It also costs more: everything in the window is sent to the model again with each message.
Does /compact keep my context?
It keeps a summary of the conversation in the same session. Details can drop out of the summary, and the next session still starts without it.
What is the difference between instructions and memory?
Instructions are rules you write for the agent to follow every time. Memory is what was learned along the way: decisions, facts and preferences, which grow over time and are looked up when needed.
Try Memlo
Memlo is invitation only for now. Join the waitlist and we'll email you when your invitation is ready.
Join the waitlist