The memory we recommend for your agents is Glen, shared memory for coding agents.Go to tryglen.com →
Short vs long term3 min read

Glen, shared memory for coding agents

Short-term and long-term memory in AI agents

Short-term memory in an AI agent is its context window: the prompt, files and tool output it can see right now, gone when the session ends. Long-term memory is stored outside the model and survives across sessions, machines and people. A useful setup moves knowledge between them on its own: written down as each turn finishes, and read back when a later prompt needs it.

Get Glen for your agents
On this page
  1. Short-term memory is the context window
  2. Long-term memory sits outside the model
  3. Moving knowledge from one to the other
  4. Why long-term memory has to be selective
  5. Frequently asked questions

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 and long-term memory in an AI coding agent
Short-term (context window)Long-term (memory store)
LifetimeOne sessionMonths, across sessions
ScopeOne agent, one taskOne person, or a whole organization
Size limitThe model's context lengthBounded by storage, not by the model
What gets inWhatever the agent reads this sessionWhat was recorded or written earlier
CostTokens on every turnA 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.

  1. 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.
  2. Before the next prompt reaches the model, the UserPromptSubmit hook sends the prompt with repo and branch, and Glen injects the memories that match.
  3. When the agent needs more, it can run glen search for a written answer with a citation behind each claim, or glen code-search to 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.

More in this guide

Related guides on agent memory

Fix your agents’ amnesia.

Glen gives your agents the memory of every session your team has run. Start on your own or with up to two teammates. Your first 15,000 memories are free, no credit card.

Start free at tryglen.com