
Codex CLI Chat History: Complete 2026 Guide to Finding Past Sessions
Codex CLI stores every session as JSONL under ~/.codex/sessions. Find any past session by date, search across months, and branch from earlier messages.
If you have ever typed codex into a fresh terminal and wondered where every past session went, this is the complete answer for 2026. Codex CLI keeps a durable record of every conversation on your own disk, split across two directories with different jobs. One holds the full transcript of every session with tool calls and diffs. The other holds only the prompts you typed, so the up-arrow key has something to walk through. Knowing which file does what cuts the time it takes to find an old session from ten minutes of digging to about four seconds.
This guide is the practical version, so no theory and no vendor marketing. It lists the exact paths on macOS, Linux, and Windows, shows the one-liner that finds a session by date, walks through how to branch from a previous message without corrupting the file, and covers the small set of commands that turn raw JSONL into something you can read without squinting. The companion post on where Codex CLI files live covers the raw location question in isolation and is a good second tab to keep open. If you work across more than one agent, our write-ups on reading Claude Code chat history and searching Codex CLI history extend the same patterns to adjacent tools.
What Codex CLI stores on disk
Every interactive Codex session writes a single JSONL file under ~/.codex/sessions/YYYY/MM/DD/ on macOS and Linux, and under %USERPROFILE%\.codex\sessions\ on Windows. The filename is rollout-<UTC-timestamp>-<session-id>.jsonl, so a session started on November 22nd 2026 at 20:48 UTC lands at ~/.codex/sessions/2026/11/22/rollout-2026-11-22T20-48-00-<id>.jsonl. Each line in that file is one event: a user message, an assistant reply, a tool call, a diff, or a system note. The ordering is preserved exactly, which is what makes resume and branch workflows possible later.
Prompt recall is a different file with a different job. It lives at ~/.codex/history/history.jsonl and contains only the text of the prompts you typed, one per line, with no assistant content. This is the file the up-arrow key reads inside interactive mode. If you want to grep for a phrase you remember typing, this is the fast path. If you want the assistant's reply, the tool call, or the resulting diff, you have to open the session file under sessions/ instead.
Finding a past session fast
The fastest way to locate a session is to sort by modification time and let the shell do the walking. ls -lt ~/.codex/sessions/**/*.jsonl | head -20 on macOS or Linux returns the twenty most recent sessions in order, with their full paths. On Windows, Get-ChildItem $env:USERPROFILE\.codex\sessions -Recurse -Filter *.jsonl | Sort-Object LastWriteTime -Descending | Select-Object -First 20 does the same job from PowerShell. For a known date, cd straight into ~/.codex/sessions/2026/11/22/ and list the files, since the directory tree is already date-partitioned for you.
Keep the four paths below somewhere you can find them, because every Codex CLI history question ends up at one of them. They cover the full session log, the prompt recall file, the configuration, and the debug log. The config path matters when persistence seems to be off and you need to confirm the CLI is writing where you think it is. The debug path is the first stop when sessions stop appearing on disk after an upgrade:
~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonlfor full per-session event logs with tool calls and diffs.~/.codex/history/history.jsonlfor up-arrow prompt recall across every session.~/.codex/config.tomlfor the active CLI configuration and persistence flags.~/.codex/log/for the CLI's own debug output, separate from your transcripts.
For content search across every session, rg -l 'my search phrase' ~/.codex/sessions returns every session file that contains the phrase, and rg -C 2 'my search phrase' ~/.codex/sessions shows the surrounding lines so you can confirm the match is the one you remembered. Both commands run in under a second on a year of sessions on a laptop SSD. Pipe the output into fzf for an interactive picker, and you have a complete local search UI in one shell line. The same approach works on the prompt recall file when you only remember what you typed, not what came back.
Reading a session without losing your mind
Opening a JSONL directly in Vim or VS Code looks like a kidnapper's ransom note. Each line is one event with escaped newlines, escaped quotes, and tool call arguments that stretch across several kilobytes. A naive jq -r '.content' strips the envelope but also flattens turn order and loses the shell command Codex ran between two user messages. You will spend more time scrolling than reading, and the markdown inside the content fields renders as literal \n## and triple-backtick strings.
The reliable move is to render each JSONL to real markdown once and then open the markdown in a reader built for long AI output. A short Python or Node script walks the file, emits an H2 per user turn, keeps the assistant reply as native markdown, and wraps tool calls in fenced code blocks with a bash or diff tag. Save one .md per session alongside the original JSONL so the folder sorts chronologically. Prism MD opens those files with proper type scale, syntax-highlighted code blocks, rendered KaTeX, and Mermaid diagrams where the assistant produced them, and the whole thing stays on your device so any API keys or secrets in the transcript never leave the machine.
Branching from a past message
Codex CLI does not ship a dedicated regenerate button for an earlier turn, but every event is already on disk, which means you can branch at the file level with no special tooling. Duplicate the JSONL you want to fork, truncate the copy at the user turn you want to edit, rewrite that one line with your corrected prompt, and start a new Codex session that loads the modified file. The CLI reads the ordered events as prior context and continues as if the discarded tail never existed. The original session stays untouched for reference, which means you can branch again later from the same point without redoing the surgery.
Two gotchas are worth internalizing before you touch the files. Never edit the JSONL for a session that a live Codex process still has open, because the CLI holds a write handle and will overwrite your changes on the next event. Always copy first, edit the copy, and start a new session against the copy. Keep every event's top-level schema intact: the parser rejects any line that is missing the fields the CLI wrote, so if you must transform content, do it inside the existing shape rather than rewriting the envelope. Treat the JSONL as a git-tracked artifact if you branch often, since a committed baseline makes forks and reverts trivial.
FAQ
What is the exact path to Codex CLI history?
~/.codex/history/history.jsonl on macOS and Linux, %USERPROFILE%\.codex\history\history.jsonl on Windows. That file is the prompt recall log. Full session transcripts live under ~/.codex/sessions/YYYY/MM/DD/ with one JSONL per session.
How do I find a Codex CLI session by date?
Open ~/.codex/sessions/YYYY/MM/DD/ for the date you remember, then pick the JSONL whose timestamp matches the hour. For unknown dates, ls -lt ~/.codex/sessions/**/*.jsonl | head sorts every session by recency across the full tree.
Can I branch a Codex conversation from an earlier message?
Yes. Copy the session JSONL, truncate the copy at the user turn you want to edit, rewrite that line with the corrected prompt, and start a new Codex session that loads the modified file. Never edit a JSONL that a live Codex process still has open.
Is it safe to delete old Codex session files?
Yes. Nothing in the CLI depends on them once a session has ended. Export the ones you want to keep as rendered markdown first, since the raw JSONL is hard to read in any tool that does not know the schema.
Open your Codex JSONL files as clean, searchable markdown.
Free to start — no credit card.
Related reading
Ready to read your own AI documents?
Open ChatGPT, Claude, Gemini, or any markdown file in the reader built for the way models write.
- ✓Renders code, math & Mermaid out of the box
- ✓Works offline once you've opened a doc
- ✓Free forever for personal reading


