Skip to content
ottto Docs
Concepts

Seven layers of agent memory

Live context, repository instructions, local memory, runtime state, compaction summaries, prompt caches and retrieval all get called memory. How they differ in lifetime, scope, cost and who can review them.

“Memory” in an AI coding agent means at least seven different things. They differ in how long they last, who can see them, what they cost and who can review them. Before you ask whether an agent remembers something, ask which layer holds it, when it enters a request and where it is saved.

A note on your laptop is not a checked-in instruction. A prompt cache is not a knowledge store. A compaction summary is not the original conversation.

Layer What it is How long it lasts Who sees it Watch out for
1. Live context Everything sent to the model on this request: instructions, messages, tool results, files read. One request or session This conversation Retained history is sent again on later requests, so input grows.
2. Repository instructions AGENTS.md, CLAUDE.md, skills, runbooks and docs in the repository. Versioned with the code Everyone who opens the repository Long or stale instructions are paid for on every session.
3. Local agent memory Notes the agent saves on one computer and reuses across chats, such as Claude Code auto memory or Codex Memories. Across chats One computer and login Useful lessons stay on one machine and drift from the repository.
4. Runtime state Open terminals, browser tabs, task queues and checkpoints kept by the app or a tool. While the process runs That app or sandbox It enters the model only when shown to it, and it is gone when the process ends.
5. Compaction summary A shorter summary that replaces older conversation history. Until the session ends or compacts again That conversation It drops detail and changes the cached prompt.
6. Prompt cache The provider reuses an input prefix it has seen recently, at a lower rate. Minutes to an hour Requests with the same prefix Cached tokens still fill the context window. It stores nothing for later.
7. External retrieval Databases, search indexes, issue trackers and document stores the agent can query. As long as the store keeps it Whoever has access Being connected is not the same as being read on this request.

Exact lifetime, scope and loading rules depend on the app, its settings, the model and the version. Check the vendor’s own docs before relying on one.

Most agents build each request from the context they kept plus the new material. As a session grows, later requests send the same instructions, earlier messages and tool results again.

A useful way to think about it: context kept × requests that carry it × the input rate. This is a mental model, not a billing formula. Your real cost is the sum of each request’s token types at their prices.

  • Startup sets a floor. The first request already carries system, tool, repository and memory context.
  • Long sessions compound. Something added early rides along on every later request.
  • Caching changes the rate, not the size. A cache hit costs less and can be faster, but the tokens still count against the context window. Providers report cached tokens differently.
  • Compaction resets the curve. It shrinks the history by carrying a summary forward. Compare before and after a compaction separately.

The prompt caching and compaction guide covers cache lifetimes, idle costs and when compacting pays.

Ottto shows measured, estimated and missing data separately, and keeps each number to the app, machine, repository, session, model and time it comes from. In the Ottto web app under Optimize:

  • Session start shows what loads at the start of a session, and flags a MEMORY.md near or past its load limit.
  • Context growth shows when sessions compacted and what compacting earlier would have cost.
  • Prompt caching shows when the cache was rebuilt and what cache reuse saved.

Ottto does not:

  • Show your prompts, responses, transcripts or code in these views.
  • Delete memory, clear sessions, compact for you or change your settings.
  • Turn missing data into zero usage, zero cost or confirmed savings.
  • Claude Code keeps auto memory per repository folder on each computer. Worktrees of one checkout share it. At the start of a session it loads the first 200 lines of MEMORY.md, up to about 25,000 characters; other topic files load when needed. See How Claude remembers your project.
  • Codex Memories are off by default. When on, each Codex home folder keeps its own store. See Codex Memories.
  • Retrieval systems may keep data for a long time and share it widely, but only what a query returns enters the request.

One app’s rules never tell you how another app behaves.

Keep each comparison narrow enough to act on. Mixing tools, repositories, models or kinds of work blurs real differences.

  1. Fix the scope. Pick one app, machine, repository, model, kind of work and time range. Note any missing data first.
  2. Separate start from growth. Compare the first request with later requests and the peak. A large first request is a lead, not proof of one cause.
  3. Check what entered and what stayed. Something added once can stay in context for many requests.
  4. Mark compactions. Compare the parts of a session before and after each compaction. A drop after compaction is a new baseline.
  5. Check the cache numbers. Know how the provider reports cache reads and writes, and which prices apply. Missing write data means the net saving is unknown, not zero.
  6. Change one thing, then measure again. Move shared lessons into the repository, make one change, and compare the same scope and work afterwards.