Expand description
Read-side access to the CLI’s on-disk session logs.
Read-only. Mutation goes through the CLI, via
ArchiveCommand and
DeleteCommand.
§On-disk layout
$CODEX_HOME/sessions/<YYYY>/<MM>/<DD>/rollout-<ISO8601>-<uuid>.jsonlThe date partitioning is why SessionQuery::after and
SessionQuery::before are cheap: they filter directories, without opening
a file.
§Two envelope generations
A real machine holds sessions written by many CLI versions, and the line format changed. Both were found on one machine while writing this, 205 files spanning both:
Modern, from around 0.47 onward. Every line is an envelope:
{"timestamp":"...","type":"session_meta","payload":{"id":"...","cwd":"..."}}
{"timestamp":"...","type":"response_item","payload":{"type":"message","role":"user"}}Legacy, older files. No envelope at all: the first line is the metadata, and later lines are bare records.
{"id":"...","timestamp":"...","git":{},"instructions":null}
{"id":"...","type":"message","role":"user","content":[]}A parser written against only the modern shape returns nothing at all for
the older half of a real history, silently. SessionEntry::entry_type is
None for a legacy line, and its payload is the whole line.
Field-level drift is handled the same way: every metadata field is
optional, because older files carry no cli_version, no cwd, and a
different instructions key. SessionMeta::raw keeps whatever this
crate does not name.
§Coverage of current history modes
CLI 0.163.0 writes materialized, persistent legacy and paginated threads
under the layout above. Both use the modern envelope; the current
history_mode: "legacy" setting is distinct from the older bare-line format.
SessionMeta::raw preserves history_mode. Paginated item_completed
payloads are retained as written, including their nested item.
This is a file reader, not the provider’s logical thread-history view.
Discovery does not include archived sessions, ephemeral or unmaterialized
threads, or a server’s other storage roots. It does not query the state
database. Entries are not normalized into turns, replayed, or deduplicated.
Envelope fields other than timestamp, type, and payload (including
paginated ordinal) are not exposed. Invalid JSON lines are skipped.
For the provider’s view, enable app-server and use
AppServerHandle::request with thread/read, thread/turns/list, or
thread/items/list. In an isolated 0.163.0 capture, thread/read and
cursor-paginated thread/turns/list worked for both materialized modes.
thread/items/list worked for paginated history and rejected legacy history.
Continue each method’s opaque nextCursor until absent; do not derive a
cursor from rollout ordinals or treat one page as complete history.
Availability depends on CLI version, mode, and materialization. These probes
used failed offline turns and do not qualify every item kind or history
recovery scenario. Versioned fixture provenance ships in tests/history/.
§Example
use codex_wrapper::history::{self, SessionQuery};
for session in history::list(&SessionQuery::new().after(2026, 8, 1))? {
let log = history::read(&session.path)?;
println!("{} in {:?}", session.id, log.meta.and_then(|m| m.cwd));
}Structs§
- GitMeta
- Git metadata recorded with a session.
- Session
Entry - One line of a session log.
- Session
File - A rollout file on disk, identified without opening it.
- Session
Log - A parsed session log.
- Session
Meta - The session’s opening metadata.
- Session
Query - Which sessions to list.