Feature: Resume CLI session after premature exit (Ctrl-C) and restore transcript context
What feature would you like to see?
Currently, when using the Codex CLI, exiting the session by pressing Ctrl-C too many times can result in the session closing and the user losing access to the ongoing chat transcript and context. While the transcript is saved as JSONL files, restoring a previous conversation requires manual file access and editing, which is not user-friendly.
I would like to propose a feature that allows users to easily resume or restore a previous CLI session, loading the last transcript and its context if the CLI is exited unexpectedly (e.g., via Ctrl-C or terminal close). This would work similarly to competing CLI tools, which offer a 'save chat <tag>' or 'continue chat <tag>' command. This feature would greatly improve usability, especially for users who accidentally exit and want to continue their work seamlessly.
Proposed solution:
- Provide a command-line flag or option to resume the last chat session OR a way to save the current chat.
- On startup, if a recent transcript is detected, prompt the user to restore the session?
- Automate recovery of context so that users do not need to manually locate and load JSONL transcript files.
This would help avoid loss of context and improve productivity when using Codex CLI.
Are you interested in implementing this feature?
Not at this time (sorry)...
Additional information
Other CLI competitors offer this type of chat saving. This would improve Codex CLI's usability for anyone who relies on continuous context within the same conversation, especially during long troubleshooting.
Work around:
Assuming bash (WSL windows), Codex actually helped me make this "get last chat" bash script:
#!/usr/bin/env bash
set -euo pipefail
SESS_ROOT="${HOME}/.codex/sessions"
# Check if clip.exe is available in PATH (copies to windows clipboard from WSL)
if ! command -v clip.exe >/dev/null 2>&1; then
echo "Error: clip.exe not found in PATH" >&2
exit 1
fi
# Need jq
command -v jq >/dev/null 2>&1 || { echo "jq is required"; exit 1; }
# Find newest JSONL. Prefer GNU find; fall back to ls -t.
latest="$(
find "$SESS_ROOT" -type f -name '*.jsonl' -printf '%T@ %p\n' 2>/dev/null \
| sort -nr | head -1 | cut -d' ' -f2-
)"
if [[ -z "${latest:-}" ]]; then
latest="$(ls -t "$SESS_ROOT"/*/*/*/*.jsonl 2>/dev/null | head -1 || true)"
fi
[[ -n "${latest:-}" ]] || { echo "No .jsonl files found under ${SESS_ROOT}"; exit 1; }
# Stream just prompts and responses to clipboard.
# - joins multi-part content arrays
# - accepts either .text or .content fields
# - normalises CR/LF
jq -r '
select(.type=="message" and (.role=="user" or .role=="assistant"))
| .role as $r
| (
if (.content | type == "array")
then
[ .content[]
| if has("text") and (.text != null) then .text
elif has("content") and (.content!= null) then .content
else ""
end
]
else
[ .content ]
end
| map(tostring)
| map(gsub("\r\n"; "\n") | gsub("\r"; "\n"))
| join("\n")
) as $body
| (if $r=="user" then "Prompt:" else "Response:" end)
+ "\n" + $body + "\n"
+ "\n"
' "$latest" | clip.exe
echo "Copied prompts and responses from: $latest"This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗