Skip to main content

The question

In Context rot, the harness shrank the context by summarizing the test log and saving the full log to disk. That was the first half of context management: deciding what goes into the context. Now the second half: where does everything outside the context live, and how is the context rebuilt from it on every turn?

The answer

Split the agent’s state into separate stores, one for each kind of information. Before every call, a context builder in the harness picks what the next call needs from those stores and assembles a fresh context.
The seven-store split is this guide’s design. The last two columns show where Claude Code and Codex keep each kind of state, as real examples.

Why separate stores?

Not all state is alike. Two questions sort it:
  • How long does it need to live? For this call only, for this session, across future sessions, or permanently.
  • Who needs it? The model on every call, the model only sometimes, the harness only, or the user.
The test log is needed for one session and only sometimes by the model. A lesson like “this repo runs tests with npm run test:unit” is useful in every future session. The model choice is needed only by the harness. Each answer pair points to a different store.

The seven stores

Using the same session-expiry bug as before. The examples are illustrative. Claude Code keeps most stores under ~/.claude/ and Codex under ~/.codex/; the full paths are in Sources.

Where real agents keep it

The two products agree on most stores but make different choices on three:
  • Task state. Claude Code keeps the task list in its own store. Codex records its plan as part of the conversation, so the plan lives in the transcript alongside everything else.
  • File recovery. Claude Code snapshots files before editing them, so an edit can be undone without git. Codex can rewind a conversation, but its rewind does not restore files; undoing a code change relies on git.
  • Large tool output. Claude Code moves large outputs, like the 6,000-line log, into separate files next to the transcript. Codex writes tool output into the transcript itself.
None of these choices is wrong. Each one is a trade-off, which is why this guide treats the split as a design decision.

How the context is rebuilt

Before call 51, the context builder takes a small piece from some stores and leaves the rest on disk. Each box below is labelled with the store it came from:
Working context for call 51
System promptHarness
Tool definitionsHarness
Memory: run tests with npm run test:unit.Memory
User: Fix the session-expiry bug. Don’t change the isExpired signature.History
Tasks: ✓ reproduce the bug · ✓ fix the comparison · ☐ run session testsTask state
Summary: 1 test fails: sessions expire 1 ms late at the boundary.History
Current diff: session.ts, > changed to >=Code
Stays outside the context
Full 6,000-line test logHistory
Older messages and tool resultsHistory
Explorer subagent’s full search trailSubagent history
session.ts as it was before the editFile recovery
Model choice and allowed commandsConfiguration
The rest of the repositoryCode
The working context holds only what this call needs: the goal and constraint, the task list, one line about the failing test, and the current diff. The full log, the old file version, and the subagent’s search trail stay on disk. If the agent needs one of them, it reads it back with a tool, the same way it reads code.
Design decision: Store state by lifetime and purpose, and rebuild a small working context from those stores before every call.

Sources

All paths are as of October 2026 and can change between versions.

Claude Code

From the .claude directory reference:
  • Conversation history: ~/.claude/projects/<project>/<session>.jsonl. Large tool outputs are moved to <session>/tool-results/.
  • Subagent history: ~/.claude/projects/<project>/<session>/subagents/
  • Task state: ~/.claude/tasks/
  • Persistent memory: ~/.claude/projects/<project>/memory/
  • File recovery: ~/.claude/file-history/<session>/
  • Configuration: settings.json, described in Settings

Codex

From OpenAI’s docs, the openai/codex source at commit c7234c1, and a local Codex install:
  • Conversation history: ~/.codex/sessions/YYYY/MM/DD/rollout-<timestamp>-<id>.jsonl, with tool output stored inside the transcript (recorder.rs, local install)
  • Subagent history: each spawned agent’s transcript is stored in sessions/ with its parent thread’s ID (local install)
  • Task state: recorded in the conversation by the update_plan tool (plan.rs)
  • Persistent memory: ~/.codex/memories/, off by default (Memories)
  • File recovery: rewinding a thread writes a new transcript file and does not restore files (revert_thread.rs)
  • Configuration: ~/.codex/config.toml (Config basics)

Continue the walkthrough

Why not one blob

Continue to topic 5 of 14: why each store uses its own format.