Why Your AI Agent Keeps Forgetting (And Why Bigger Context Windows Won't Fix It)
Your coding agent works brilliantly for twenty minutes, then forgets the architecture you explained. That's not a bug you can prompt your way out of — and million-token windows won't save you. What actually helps.
You explain the architecture. The agent gets it. You work together for half an hour, making real progress. Then it suggests a change that contradicts something you established twenty minutes ago, and you realise you're about to explain the whole thing again.
Everyone who uses coding agents seriously has hit this. It's the single most common complaint about them, and the usual advice — write better prompts, wait for bigger context windows — mostly misses why it happens.
Two different kinds of forgetting
They get conflated constantly, and the fixes are completely different.
Session forgetting is the conversation disappearing. You close the terminal, come back tomorrow, and the agent has no idea what you discussed. This is a property of how LLMs work: the model is stateless, each call processes a fresh context window, and everything not in that window doesn't exist.
Environment forgetting is the work disappearing. The dependency the agent installed is gone. The branch it created isn't there. The database rows it inserted to test a migration have vanished. The scratch script that reproduced the bug — gone.
Most discussion focuses on the first. In day-to-day agent work, the second is often more damaging and much more fixable.
Why bigger context windows don't solve it
The intuitive fix is more room. If the agent forgets because things fall out of the window, make the window bigger. A million tokens, ten million — surely that's enough for any codebase.
It isn't, for three reasons.
Windows are finite and work isn't
Any fixed budget gets exhausted by a sufficiently long task. A refactor across a large codebase, a debugging session with hundreds of tool calls, a migration verified in stages — these grow without bound. Doubling the window buys you one more doubling of task length, which is not a strategy.
Attention degrades before the window fills
This is the part people miss. Models don't use a large context uniformly well. Recall reliability drops for material buried in the middle of a long context — the "lost in the middle" effect — and it shows up well before you hit the limit.
A 500k-token context isn't 500k tokens of reliable memory. It's a lot of tokens with a reliability gradient across them. Filling it with your entire codebase gives you a worse signal-to-noise ratio, not better recall.
Compaction is lossy, and lossy at the worst moment
When context runs out, something has to go. Agents summarise, drop old turns, or compact — and this is exactly the moment users report the agent "suddenly losing critical information."
The summary keeps what looked important to a heuristic. The specific constraint you mentioned once — don't use that library, it breaks our build — is exactly the kind of detail that gets compressed away, because it was one sentence forty turns ago.
Bigger windows delay compaction. They don't make it lossless.
The fix isn't a bigger head. It's a desk.
Here's the thing about human engineers: our working memory is far worse than any model's context window. We hold maybe a handful of things at once, and we forget what we did last Tuesday.
We compensate by putting almost nothing in our heads. Code lives in files. Decisions live in commit messages and ADRs. State of play lives in a branch and a TODO. Reproduction steps live in a test. When we need something we don't re-derive it — we look it up, in seconds, from durable external storage.
That's the model. Not a bigger head, a desk you can leave things on.
An agent with a persistent filesystem can do the same thing:
- Write notes to a file instead of holding them in context
- Leave a failing test as an executable description of the bug
- Keep the branch, the stash, the half-finished migration
- Grep the code rather than remember the code
- Read its own commit messages to reconstruct what it was doing
Context becomes a cache, not the system of record. Cheap to lose, because the durable copy is on disk.
What this actually fixes — and what it doesn't
Being precise here matters, because "persistent workspaces fix AI memory" is an overclaim and you should distrust anyone who makes it.
A persistent workspace fixes environment forgetting. Files, git state, installed dependencies, environment variables, database contents, build caches, and anything the agent chose to write down. That's real and it's most of the practical pain.
It does not fix session forgetting on its own. Conversation history is a separate concern, handled by memory systems, session summaries, or the agent's own notes-to-file discipline.
But there's a compounding effect worth naming: when the environment persists, the agent's notes persist, and notes-to-file is the most reliable conversation-memory mechanism available. A NOTES.md the agent maintains and re-reads is more durable than any context window, because it's explicit, greppable, editable by you, and survives every compaction.
The environment doesn't replace memory. It's the substrate that makes durable memory possible.
Practical things that help today
Independent of platform:
- Make the agent write things down. Ask for a running log of decisions and constraints in a file. Persistent for free, and you can correct it.
- Encode constraints as tests, not sentences. "Don't break the auth flow" gets forgotten. A failing test does not.
- Use the repo as memory. Clear commit messages, a
CONTRIBUTING.mdexplaining conventions, anARCHITECTURE.md. The agent can re-read these; it cannot re-read your chat. - Prefer many small verified steps to one large speculative one. Each verified step is durable progress; a large one is a bet.
- Re-anchor after compaction. When you notice a summarisation event, restate the two or three constraints that matter. Cheaper than debugging a wrong assumption.
- Keep the environment warm. If your setup rebuilds from scratch each session, you're paying the orientation cost every time, in tokens as well as minutes.
The short version
Your agent forgets because the model is stateless and the window is finite — and no window size fixes that, because attention degrades and compaction is lossy.
The durable fix is the same one humans use: stop keeping things in your head. Put them somewhere that survives. That requires an environment that persists between sessions, which is a property of your infrastructure, not your prompt.
EasySpawn gives every project a persistent cloud workspace — files, git history, dependencies, and data survive across sessions and container restarts. Join the waitlist.
Related: The Sandbox Is the Wrong Abstraction · Why AI Coding Agents Need Persistent Workspaces
Keep reading
The Sandbox Is the Wrong Abstraction for AI Coding Agents
The industry settled on ephemeral sandboxes for AI agents — isolated, disposable, destroyed after each task. That's exactly right for running untrusted code and exactly wrong for building software. Here's the distinction that matters.
Leaving Gitpod: Where Cloud Dev Environments Went in 2026
Gitpod Classic shut down in October 2025 and the product became Ona, an AI-agent platform on a new runtime. If that broke your workflow, here's an honest map of the alternatives and what to check before you migrate.