Skip to content

Session History and Memory

A fact can reach Codex because it was in an active conversation, because a saved thread was reopened, or because an enabled local memory contributed a summary. These paths have different inputs and different evidence. This chapter follows the public Codex CLI 0.172.0 source tree.

State Storage and lifetime How to observe it
Active context The runtime prepares a model request from a thread history snapshot. Normalization depends on the model’s supported input modalities. Compaction can replace the active history. Inspect the provider request’s ordered input. Request preparation · Context normalization
Saved thread history A persistent thread records rollout items that can be replayed after the session closes. Replay can use a compaction checkpoint and then apply later records. Reopen that thread and inspect the next request. Resume branch · Checkpoint selection
Local memory An optional background pipeline derives reusable artifacts from eligible prior chats. The selected memory version determines the store under CODEX_HOME. In a later thread, look for a developer fragment derived from the selected store’s memory_summary.md. Store paths · Memory contribution
  1. Resume the thread. The resumed-history branch takes the saved rollout items and calls the reconstruction path. Reconstruction restores conversation history and related state such as previous turn settings and the context window. Resume branch · Reconstruction fields
  2. Start the next turn. The runtime clones current history and normalizes the copy for the model. An unavailable attachment can become a text placeholder. Compare the outgoing request to see which information made it through. Snapshot · Prompt normalization
  3. Check the boundary. The upstream compaction/reopen fixture compares the normalized prefix in a post-compaction request with that in the first request after resuming. The previous chapter explains its exact comparison. Prefix assertion

When eligible root sessions start, the runtime can run the memory write pipeline in the background. It extracts per-thread summaries from selected rollouts, then consolidates the outputs. Startup and selection depend on factors such as feature configuration, storage availability, and rollout age and idle time. A completed chat alone does not demonstrate that a memory artifact was produced. Startup conditions and phase order · Rollout selection · Consolidation design

For the read path, the extension requires the memories feature and memories.use_memories. It reads the selected store’s memory_summary.md, trims and bounds the text, and renders developer instructions when there is content. The upstream v1 test seeds a temporary summary file and checks for a developer-policy fragment containing a known sentence. It tests the contribution step. Background generation and model recall are separate outcomes. Read gate · Summary lookup · V1 fixture

A version-selection test starts with a summary only in the v1 store. Asking for v2 yields no instructions. After the test adds a v2 summary, the v2 instructions contain new pipeline content and exclude legacy content. A v1 read still returns the legacy marker. This checks which file supplies the rendered instructions. The CLI probe below follows the v1 marker one step further, into an actual provider request. Version-specific directories · Store-selection fixture

  • To continue a specific saved conversation, use codex resume or App Server’s thread/resume. Inspect the reconstructed input when the exact context matters. CLI resume · App Server threads
  • To study reuse across fresh conversations, hold the new prompt fixed and compare memory use enabled and disabled against the same seeded summary. Check for the summary in request input before scoring whether the model used it. Local memory controls
  • For a project rule that should apply across work, keep it in versioned project instructions. Project Instructions

Evidence. The upstream unit test injects an enabled v1 extension config and checks the rendered fragment. A reproducible CLI 0.172.0 probe starts two fresh sessions with identical seeded v1 summaries and prompts. Both enable features.memories and disable memories.generate_memories. Changing only memories.use_memories makes the marker appear or disappear in the serialized developer input. To study recall, score a live model’s answer separately. Unit test setup · Run the CLI probe

Continue with Subagent Handoffs to see how a different thread can contribute a result during the parent’s follow-up turn.