Short-term memory is the context window
Everything an agent reasons over in a session sits in its context window: your prompt, the files it read, the commands it ran and their output. The window is large but finite, and agents compact or drop older turns as it fills. When you close the session, all of it is gone.
Engineers notice this most on long tasks. An agent figures out on turn 12 that a test is flaky because of a shared fixture, then on turn 80, after a compaction, rediscovers it from scratch. Next morning's session never knew.
Long-term memory sits outside the model
| Short-term (context window) | Long-term (memory store) | |
|---|---|---|
| Lifetime | One session | Months, across sessions |
| Scope | One agent, one task | One person, or a whole organization |
| Size limit | The model's context length | Bounded by storage, not by the model |
| What gets in | Whatever the agent reads this session | What was recorded or written earlier |
| Cost | Tokens on every turn | A lookup, plus tokens for what is recalled |
The built-in long-term layers are deliberately small because they load whole. Claude Code's auto memory loads the first 200 lines or 25 KB of its index per session, and Codex reads AGENTS.md files up to 32 KiB by default. Both live on one machine or in one repo.
Moving knowledge from one to the other
The interesting part is the hand-off. If writing to long-term memory waits for the model to decide something matters, most of the session is lost. If reading waits for the model to think of searching, memory stays unused.
- At the end of each turn, Glen's Stop hook records what happened. In Claude Code that includes tool calls, tool results and thinking blocks; in Codex, the prompt and final reply.
- Before the next prompt reaches the model, the UserPromptSubmit hook sends the prompt with repo and branch, and Glen injects the memories that match.
- When the agent needs more, it can run
glen searchfor a written answer with a citation behind each claim, orglen code-searchto follow git blame back to the conversation that wrote a line.
Why long-term memory has to be selective
Long-term memory competes with the task for room in the short-term window. Recall that pastes in everything crowds out the code the agent should be reading. Glen recalls by relevance to the prompt, so a month of a team's sessions costs the agent only the few memories that bear on the change at hand. For more on budgeting the window itself, see context window memory.
Does the extra recall pay for itself? In Glen's own replay of 100 merged PRs, agents with memory used 29% fewer tokens and finished 21% faster at equal or better quality. That replay used per-prompt injection, so agents that only search on demand may see different numbers. The full method is published.
Frequently asked questions
What is short-term memory in AI?
The context window: everything the model can see during the current session. It is cleared when the session ends and trimmed as it fills.
Is the context window the same as memory?
It is working memory for one session. Anything you want an agent to know next week has to be stored outside the model and loaded back into the window later.
Does a bigger context window remove the need for long-term memory?
No. A bigger window holds more of today's session, but it still empties when the session ends, and it never contains a teammate's sessions.