
Codex CLI Chat History 2026: Resume, Branch, Export Guide
How to resume a crashed Codex CLI session, branch from any prior message, and export full session transcripts as markdown, PDF, or a searchable archive.
The three things most developers want from Codex CLI history are straightforward: pick up a session that crashed, edit one message without losing the rest of the conversation, and get the transcript into a format readable outside a terminal. None of these require a third-party service or an API call. The session files are on your local disk right now, and the workflow is about fifteen minutes to learn. This guide covers the management layer: how to resume, how to branch, and how to export full session transcripts. For background on file locations and what the raw JSONL format contains, the earlier guide on Codex CLI chat history file locations covers the path structure and event schema in full.
Where Codex CLI Stores Session History
Every session writes to ~/.codex/sessions/YYYY/MM/DD/ as a JSONL file named rollout-<UTC-timestamp>-<session-id>.jsonl. On Windows the same directory structure lives under %USERPROFILE%\.codex\sessions\. A flat prompt log for up-arrow recall sits at ~/.codex/history/history.jsonl, but that file holds only user prompts, not assistant replies or tool calls. Keep the following paths bookmarked, since every troubleshooting question about Codex persistence ends at one of them:
- Sessions:
~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonl - Prompt history:
~/.codex/history/history.jsonl - Config:
~/.codex/config.toml - Debug logs:
~/.codex/log/
Sessions are the files you need for resume and branch workflows. The history file is useful for grepping past prompts but it contains no assistant replies, tool calls, or diffs. If you need the full conversation, the per-session JSONL in sessions/ is always the right file. Run ls -lt ~/.codex/sessions/**/*.jsonl | head to confirm the most recent files and verify the CLI is writing to disk correctly. If the directory is empty, check whether you are running Codex in ephemeral mode, since that flag disables session persistence entirely.
How to Resume a Past Codex Session
Codex CLI does not have a GUI reopen button, but it exposes a file-loading path that lets you feed any JSONL as prior context when starting a new invocation. The CLI reads the event log, reconstructs the conversation state, and treats your new prompt as the next turn in that session. The assistant has access to every prior tool call, diff, and reply, so the continuation reads naturally without any setup prompt. If the session you want is from several days ago, navigate to ~/.codex/sessions/YYYY/MM/DD/ and find the JSONL by its timestamp prefix. Session files are typically small even for long conversations, so loading them is fast. A short shell alias that lists the ten most recent files and lets you select one saves real friction if you resume sessions often.
The MCP server path works differently. When Codex runs as an MCP server, session context is held in the server process rather than written to disk at each turn. Resuming in that model means keeping the server process alive between client calls, not restarting it. If the server restarts, session context resets completely. This is why MCP server resume is a persistent search topic: the behavior is not obvious until you hit a process restart mid-project and discover the context is gone. Plan for it by setting up process supervision before you start any long-running MCP session.
Branching From a Previous Message
Branching is what you do when the conversation went wrong at a specific turn and you want to try a different prompt without discarding all the prior context. The core pattern is to copy the session JSONL to a new file, open the copy in any text editor, find the user turn you want to branch from, delete every event after that line, and rewrite the user message to your revised prompt. Start a new Codex session that loads the modified file as prior context, and the CLI runs forward from your edited turn as if the original tail never happened. The original file is untouched, so you can create multiple branches from the same source by making separate copies for each experiment.
Two rules are worth internalizing before you edit any session file. First, never edit a file that belongs to a currently live Codex process, since the CLI holds a write handle on the active session and will overwrite manual changes on the next event write. Always copy first, edit the copy, then start a fresh session against the copy. Second, preserve the event schema on every line you keep, because the CLI parser expects the same top-level fields it wrote, and deleting or reordering fields in a retained line causes a parse error at startup. If you plan to branch sessions regularly, keeping session files in a git repository and branching at the git level is a cleaner long-term approach. The Codex CLI branch conversation guide covers the git-backed workflow with step-by-step detail.
Export Options: Markdown, PDF, and Bulk Archive
The raw JSONL is not human-readable, so every export workflow starts with the same step: convert JSONL to markdown, then go from markdown to whatever final format you need. A twenty-line Python or Node script handles the conversion cleanly: iterate lines, emit an H2 for each user turn, quote assistant replies as normal markdown paragraphs, and format tool calls as fenced code blocks with a bash or diff language tag. Save the output as <timestamp>.md with the same date prefix as the original JSONL so the folder stays sorted chronologically. Prism MD renders those files with proper type scale, syntax-highlighted code blocks, and rendered math or diagrams where the assistant produced them, and the whole session stays on your device without sending anything to an external service. The Codex CLI search and grep history guide has specific command patterns for searching across a rendered mirror folder once you have a few months of exported sessions.
For PDF, render the markdown first and print to PDF from a browser or any markdown tool. Generating PDF directly from JSONL produces garbled output because code blocks and diffs do not translate cleanly without the intermediate formatting step. For bulk archive, treat ~/.codex/sessions/ as the source of truth and maintain a rendered mirror folder you can ripgrep across in under a second. Run the rendering script on any new sessions at the end of each day, or wire it to a cron job if you work with Codex daily. For long-term backup and retention strategy, the guide on archiving AI conversations long term covers sync options and what to prune as the archive grows.
FAQ
Can I resume a Codex session after my terminal crashed?
Yes. Find the JSONL for that session under ~/.codex/sessions/YYYY/MM/DD/, load it as context in a new Codex invocation, and continue. The event log captures everything up to the crash point. If the CLI was mid-write when the terminal died, the last line of the JSONL may be malformed. Open the file, check the last line for valid JSON, and delete that line before loading.
Does branching affect the original session file?
No. Copy the JSONL first and edit only the copy. The original file is not touched, and you can create as many branches as you want from the same source without affecting each other or the original. Treat each branch copy as a new independent conversation starting from the same prior context.
What is the best format for exporting Codex history for a code review?
Markdown is the most portable format. It preserves code blocks, diff output, and any structured content the assistant produced. Convert to PDF afterward if you need a fixed layout for a review or project handoff. The intermediate markdown step keeps the content intact through any subsequent conversion.
How is MCP server session context different from file-based sessions?
File-based sessions write to ~/.codex/sessions/ and persist across process restarts. MCP server session context is held in process memory and resets when the server restarts. For long-running work over MCP, keep the server process alive between client calls and use a process supervisor to guard against unexpected restarts losing your context mid-session. The distinction matters most on remote servers where the MCP process might restart due to memory limits or deployment changes, so budget for that supervision overhead before committing to MCP-based workflows.
Open your Codex session 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


