You closed the terminal. The conversation where you and the agent worked out the migration plan is gone from the screen, and now you need it back.
It isn't gone. Claude Code writes every conversation to your disk as it happens:
-
Where it lives:
~/.claude/projects/<project>/<session-id>.jsonl, one folder per working directory. -
Reopen the last one here:
claude --continue. -
Pick an older one:
claude --resume, or/resumeinside a running session. PressCtrl+Ain the picker to see every project. -
Search what was said: the transcripts are JSONL, so
jqplusawkworks. There's a command below. -
The catch: Claude Code deletes transcripts older than 30 days by default. Raise
cleanupPeriodDaysin~/.claude/settings.jsonif you want to keep them longer.
Codex works the same way with different paths and commands. It has its own section below.
Where does Claude Code store conversation history?
Each conversation is a file at ~/.claude/projects/<project>/<session-id>.jsonl. The <project> folder name is your working directory with every non-alphanumeric character turned into -, so a session started in /Users/you/code/api lands in ~/.claude/projects/-Users-you-code-api/.
Each line in the file is one JSON object: a message you sent, a reply, a tool call, or some metadata. The format is internal to Claude Code and changes between releases, so treat it as something to read, not something to build on. For a readable copy of the current conversation, run /export.
There's one more file worth knowing about: ~/.claude/history.jsonl. It holds every prompt you've typed, with the project and time. It's what the up arrow and Ctrl+R read from, and the 30-day cleanup doesn't touch it.
How do I reopen a closed Claude Code conversation?
| Command | Use it when |
|---|---|
claude --continue |
You want the most recent conversation in this directory |
claude --resume |
You want to pick from a list |
claude --resume <name> |
You named the session with claude -n or /rename
|
claude --resume <session-id> |
You have the ID. Works from any directory as of v2.1.223 |
/resume |
You're already in a session and want to switch |
The picker shows sessions from the current directory first. Press Ctrl+A to widen it to every project on this machine, Space to preview a session before opening it, and start typing to filter the list. Ctrl+R renames the highlighted session, which makes it easier to find next time.
If you pick a session from another project, Claude Code copies a cd and resume command to your clipboard instead of opening it in the wrong directory.
After a restart, when several sessions in different folders need to come back at once, see How to pick up Claude Code and Codex sessions after a restart.
How do I search inside past Claude Code conversations?
The picker works when you remember roughly which session it was. When all you remember is something that was said, search the files. This prints the date, who said it, and the start of each matching message. It needs jq, which comes with macOS 15 and later. On older macOS, run brew install jq; on Debian or Ubuntu, sudo apt install jq.
q="migration"
for f in ~/.claude/projects/*/*.jsonl; do
jq -r '
select(.type == "user" or .type == "assistant")
| (.message.content
| if type == "string" then .
else map(select(.type == "text") | .text) | join(" ")
end) as $text
| "\(.timestamp[0:10]) \(.type): \t\($text | split("\n") | join(" "))"
' "$f" | q="$q" awk '
{ i = index($0, "\t") }
index(tolower(substr($0, i + 1)), tolower(ENVIRON["q"])) {
print substr($0, 1, i - 1) substr($0, i + 1)
}
' | cut -c1-160 | sed "s|^|$(basename "$f" .jsonl) |"
done
The first column is the session ID, so claude --resume <session-id> takes you straight back. jq turns each message into one line of plain text, and awk looks for your query in that text only, ignoring case. The date and role columns aren't searched, so q="user" finds messages that mention "user", not every message you sent. The awk on macOS also ignores case for accented letters. On Debian and Ubuntu, the default awk is mawk, which ignores case only for ASCII letters, so type accented words the way they were written. Searching the raw files directly returns whole lines full of tool output and metadata, and misses queries with quotes or backslashes because JSON escapes them.
If the transcript is already gone, you can still search your own prompts:
jq -r '.display' ~/.claude/history.jsonl | grep -Fi -- "migration"
Why did my Claude Code history disappear?
Claude Code deletes transcripts, and a few related files, once they're older than cleanupPeriodDays. The default is 30 days. The minimum is 1, and 0 is rejected as invalid.
To keep conversations longer, set it in ~/.claude/settings.json:
{
"cleanupPeriodDays": 365
}
It only protects conversations that haven't been deleted yet. Once a transcript is swept, Claude Code has no copy of it. A backup of your home folder, such as Time Machine, is the only way to get it back.
Two other things look like lost history but aren't. The picker only shows the current directory until you press Ctrl+A. And sessions started with claude -p or the Agent SDK are left out of the picker; you can still open one with claude --resume <session-id>.
Where is Codex CLI conversation history, and how do I search it?
Codex stores each session as ~/.codex/sessions/YYYY/MM/DD/rollout-<timestamp>-<id>.jsonl. Sessions you archive with codex archive move to ~/.codex/archived_sessions/, and codex unarchive brings them back. Your prompts are also in ~/.codex/history.jsonl. Codex doesn't delete old sessions on a schedule.
| Command | Use it when |
|---|---|
codex resume --last |
You want the most recent session in this directory |
codex resume --last --all |
You want the most recent session from any directory |
codex resume |
You want to pick from a list of sessions in this directory |
codex resume --all |
You want the list across every directory |
codex resume <id-or-name> |
You know which one |
codex fork |
You want a copy to try another approach |
This searches messages in both folders. Codex logs grow large, so it takes longer than the Claude Code search; on about 7 GB of sessions it runs in roughly a minute:
q="migration"
find ~/.codex/sessions ~/.codex/archived_sessions -name '*.jsonl' | while read -r f; do
jq -r '
select(.type == "response_item" and .payload.type == "message")
| select(.payload.role == "user" or .payload.role == "assistant")
| (.payload.content | map(.text // empty) | join(" ")) as $text
| "\(.timestamp[0:10]) \(.payload.role): \t\($text | split("\n") | join(" "))"
' "$f" | q="$q" awk '
{ i = index($0, "\t") }
index(tolower(substr($0, i + 1)), tolower(ENVIRON["q"])) {
print substr($0, 1, i - 1) substr($0, i + 1)
}
' | cut -c1-160 | sed "s|^|$(basename "$f" .jsonl) |"
done
Codex also saves context it adds for the agent as user messages, such as your AGENTS.md and environment details. A word that appears in your AGENTS.md can therefore match once in every session. Claude Code does the same with background task notifications. Skip those rows when you read the results.
Codex has an experimental option that compresses sessions older than a week into .jsonl.zst. It's off by default. If you turned it on, read those files with zstd -dc <file> before piping them to jq.
Can I search Claude Code and Codex history without leaving the terminal?
Yes, if the search lives where you already run the agents. The commands above work, and I used them for a while. What I kept wanting was to search while I was already in the terminal, and to jump from a result straight back into the session.
That's what transcript search in PonyMux does. Press ⌘K, type what you remember, and the Transcripts filter shows matching messages from Claude Code and Codex together, with your search terms highlighted. Pick a result and resume that exact session, not just the latest one in that directory.
Searching 'polish' — Terminal results and transcript matches appear together, with the matched conversation highlighted on the right.
It searches what's on your disk, so the same limits apply. A transcript that Claude Code's cleanup already deleted can't be found, and raising cleanupPeriodDays is still worth doing.
For scopes, ranking, and managing the index, see the Search docs.
Originally published on ponymux.com, where the demos are interactive.

Top comments (0)