Where Codex stores sessions
Published · Updated · Checked against Codex CLI 0.166.0
A Codex session is one JSONL "rollout" file at ~/.codex/sessions/YYYY/MM/DD/rollout-<timestamp>-<session-id>.jsonl. Set CODEX_HOME and the base moves from ~/.codex to that directory. Next to the files sit an index, session_index.jsonl, and SQLite state databases that codex resume depends on.
The layout below is what Codex CLI 0.166.0 writes on macOS. The official pages do not state the sessions path at all; the Codex issues cited below and the files on disk are the evidence. The docs now live at learn.chatgpt.com/docs, with developers.openai.com/codex redirecting there.
The layout
ls ~/.codex
ls ~/.codex/sessions/2026/11/03
Path under ~/.codex/ | What it is |
|---|---|
sessions/YYYY/MM/DD/rollout-<ts>-<id>.jsonl | One file per session (a "rollout") |
session_index.jsonl | One line per session: id, thread_name, updated_at (keys on one install) |
state_5.sqlite | Thread metadata. It has a threads table, among others |
thread_history_1.sqlite, logs_2.sqlite | More state and logs |
history.jsonl | Prompt history, controlled by history.persistence |
config.toml | Your settings |
The path $CODEX_HOME/sessions/YYYY/MM/DD/rollout-*.jsonl is stated in openai/codex#2288, where the reporter's example sets CODEX_HOME. The ~/.codex/sessions form, with rollout-*.jsonl under YYYY/MM/DD, appears in #24948 and #34061.
The SQLite files and session_index.jsonl are named in #17540 and #34061. Their numeric suffixes are schema versions and can change between releases.
The config reference documents three settings that matter here. history.persistence takes save-all or none ("whether Codex saves session transcripts to history.jsonl"), history.max_bytes caps the history file by dropping the oldest entries, and sqlite_home sets the directory for the SQLite state DB. It treats $CODEX_HOME as the base for other paths, such as the log directory, without defining it; the ~/.codex default was confirmed locally.
Archiving is in the CLI docs. /archive removes a session from active lists but keeps the transcript, codex unarchive <SESSION> restores it, and /delete removes it permanently. They do not say where archived files go, and no archived sessions were available to check.
Windows is unsettled. Third-party blogs disagree: one says %APPDATA%\codex\, another CODEX_HOME and then the user profile's .codex. The official docs do not settle it, so check %USERPROFILE%\.codex first and then search for rollout-*.jsonl.
The line format
No OpenAI documentation treats the rollout format as a stable interface. What follows is a snapshot from 0.166.0, so check your own files before scripting against it.
Each line is a JSON object with timestamp, type and payload, and often an ordinal. The first line has type session_meta, and on 0.166.0 its payload carries id, cwd, cli_version, model_provider, git, history_mode, parent_thread_id and base_instructions, among others. Count the line types:
f=$(ls -t ~/.codex/sessions/*/*/*/rollout-*.jsonl | head -1)
jq -r '.type' "$f" | sort | uniq -c | sort -rn
Observed types are response_item, event_msg, token_usage_record, turn_context, world_state, session_meta and inter_agent_communication_metadata. The two big ones break down like this:
type | payload.type values observed on 0.166.0 |
|---|---|
response_item | message (roles user, assistant, developer), reasoning, function_call and function_call_output, custom_tool_call and custom_tool_call_output, agent_message |
event_msg | item_completed, token_count, task_started, task_complete |
A function_call payload has name, arguments (a JSON string) and call_id; the matching function_call_output has the same call_id and an output.
These files are verbose by design. Per #24948, a maintainer said they are "designed to record the full session details". Reporters there and in #34061 say each compaction writes a full replacement_history snapshot, inline base64 images are copied into each one, and subagent files inherit the parent's history. Those are user analyses that maintainers did not confirm. On one machine ~/.codex/sessions is 21 GB across about 1,000 files.
Reading it with jq
The session's working directory and ID:
head -1 "$f" | jq '{id: .payload.id, cwd: .payload.cwd, cli: .payload.cli_version}'
User and assistant messages:
jq -r 'select(.type=="response_item" and .payload.type=="message"
and (.payload.role=="user" or .payload.role=="assistant"))
| "\(.payload.role): \(.payload.content[0].text)"' "$f"
Every tool the session called, by name:
jq -r 'select(.type=="response_item" and .payload.type=="function_call") | .payload.name' "$f" \
| sort | uniq -c | sort -rn
Which session mentions a word, newest first:
grep -rl "migration" ~/.codex/sessions --include='rollout-*.jsonl' | sort -r | head
To map a name to an ID, ~/.codex/session_index.jsonl has thread_name:
jq -r '[.id, .thread_name] | @tsv' ~/.codex/session_index.jsonl | tail
Leave moving and deleting to Codex
codex resume reads the SQLite state as well as the files. Commenters in #34061 say that deleting rollouts without pruning the matching rows in state_5.sqlite and thread_history_1.sqlite leaves dead codex resume entries. Use codex delete <session ID> (CLI 0.141.0 and later, per a maintainer in #24948) and codex archive instead. Missing sessions are covered in Codex older sessions missing from resume, and size in Codex sessions disk usage. Claude Code uses a different layout; see where Claude Code stores sessions.
Sealkeep and Codex
Sealkeep reads Codex's session files, seals each one with encryption on your machine, uploads it to storage you choose and verifies the copy. Searching inside the sealed copies is sealkeep search <query> --content; sealkeep recover <id> <dest> writes the original bytes back out, or back into place with --native. If you opt into disk reclaim, Codex keeps a tiny resume pointer under the same session ID.
It does not change Codex's layout, edit or compact rollout files, or manage the SQLite state. The reclaim step is a Sealkeep Cloud feature for now. On your own bucket nothing local is removed.
FAQ
Are Codex sessions encrypted?
Nothing in the official pages says so. The rollout files are plain JSONL that jq reads directly.
Can I turn session saving off?
The config reference lists history.persistence = "none" for history.jsonl. It does not say this also stops the rollout files, and this is untested.
Does Codex delete old sessions on its own?
The config reference shows no session retention setting. The closest is memories.max_rollout_age_days, which limits thread age for memory generation only.