Why AI forgets
A model has no memory between messages. Every request you send is processed on its own, from nothing. When a chat appears to remember what you said ten minutes ago, what is actually happening is that the entire conversation so far is being resent with your new message, every single time.
That resent bundle has a size limit, called the context window, measured in tokens — chunks of text roughly three quarters of a word each. When the conversation grows past that limit, something has to go. Older messages get dropped or summarised away, and the model genuinely no longer knows what was in them.
This is why an assistant that was perfect for an hour suddenly starts contradicting decisions you made at the start. It is not degrading. The instruction simply is not in front of it any more.
You are not talking to something with a memory. You are assembling a document and sending the whole thing, every turn. Once you see it that way, every technique in this phase becomes obvious: they are all about what goes in the document.
There is a second, subtler failure. Even when everything fits, instructions buried in the middle of a very long context get less reliable attention than material at the start or the end. A rule you stated in paragraph forty of a huge system prompt is technically present and practically invisible.
The memory bank pattern
The fix is to stop keeping project knowledge in the conversation and start keeping it in files. A memory bank is a small set of Markdown files in your repository that the assistant reads at the start of a session and updates at the end of one.
The conversation becomes disposable. The files are what persists. Close the chat, open a new one tomorrow, tell it to read the memory bank, and it is oriented in seconds instead of you re-explaining the project for the fifth time.
Where the files live depends on your tool — .cursor/memory/,
memory-bank/, or just the repository root. What matters far more than the
location is that the assistant is instructed to read them. A memory bank nobody
reads is just documentation.
That instruction goes in whatever file your tool loads automatically at the start of
every session: .cursorrules, CLAUDE.md, AGENTS.md,
or the equivalent. Something as short as this is enough:
At the start of every task, read the files in memory-bank/.
They are your only record of previous sessions.
After any significant change, update activeContext.md
and progress.md to match the new state.
What goes in each file
The point of splitting memory across several files is that they change at very different rates. Mixing a stable project description with a volatile task list means rewriting both every time either one moves — and, as the next section shows, it also wrecks your caching.
Files that rarely change
- projectbrief.md — what this project is, who it is for, what counts as done. Written once, edited rarely.
- productContext.md — why it exists, the problem it solves, the decisions behind the shape of it.
Files that change occasionally
- systemPatterns.md — the architecture, the conventions, the patterns to follow and the ones to avoid. This is the file that stops an assistant reinventing your structure every session.
- techContext.md — stack, versions, environment, boundaries. Cheap to write and it prevents a whole category of wrong-version answers.
Files that change constantly
- activeContext.md — what is being worked on right now, what just got finished, what is blocked.
- progress.md — what works, what is left, known issues.
These filenames are a widely copied convention, not a standard. Some tools expect entirely different names. Pick one scheme, use it consistently in a project, and do not waste an afternoon looking for the official version — there isn't one.
Context compression
Memory files solve knowledge across sessions. Compression solves length within one. As a long working session accumulates file contents, command output, and reasoning, the window fills whether or not any of it still matters.
There are three common strategies, and they are not equally good.
- Truncation — drop the oldest messages. Costs nothing, and destroys exactly the wrong things: the constraints you set at the very beginning are always the first to go.
- Rolling summarisation — replace old messages with a prose summary. Much better, but lossy in a compounding way. Each pass smooths the detail a little more, and exact code, precise wording, and the reasons behind decisions evaporate first.
- Structured handoff — summarise into a fixed schema instead of free prose: files changed, decisions made, constraints still active, what is next. Because the shape is fixed, the important categories cannot be smoothed away.
The third is what you want, and the good news is that you do not need a library to do it. You need a prompt.
The summarize & save routine
This is the single highest-value habit in this phase. When a session gets long — or before you close your laptop — ask for a structured handoff and save it to a file. Then start a fresh conversation from that file instead of dragging the old one along.
Write a handoff to SUMMARY.md with these sections only:
## Goal
## Decisions made (and why)
## Files changed
## Constraints still active
## Next step
Be specific. Include exact file paths and function names.
Do not include conversational filler or restate the code.
Two details make the difference between this working and not. Fixed sections, so nothing important can be quietly dropped in favour of a nice narrative. And "and why" on the decisions, because a decision without its reason will be politely reversed by the next session that finds it inconvenient.
Starting the next session is then one line: read SUMMARY.md and continue from
the next step. You have replaced forty thousand tokens of history with about six hundred,
and kept the parts that were load-bearing.
Why the order of your files matters
One last thing, because it costs nothing and saves a great deal. Providers can cache the beginning of your request — the exact sequence of tokens at the front — so that resending it is much cheaper and much faster than the first time.
The catch is that it has to match exactly, from the very first character. Change one word near the start and everything after it has to be recomputed and recharged.
So order your payload from most stable to most volatile: system instructions first, then tool definitions, then the memory files that rarely change, then the volatile ones, and finally the current conversation and the user's actual question.
Injecting anything dynamic — a timestamp, the current file, today's task — into the front of a long stable prompt. It invalidates the whole cache behind it and you pay full price on every turn without ever seeing why.
Phase 3 goes into what that is actually worth, and how the two major providers differ.