This page documents the codex exec resume and codex review commands, which provide headless (non-interactive) session management capabilities. These commands enable automation workflows by allowing scripts and CI/CD pipelines to continue existing conversations or request code reviews without launching the interactive TUI.
For information about the broader exec mode event processing pipeline, see 4.2.1. For interactive session resumption via the TUI, see 4.4.
The resume subcommand allows codex exec to continue a previously saved session by loading its rollout file and optionally adding new input. This enables workflows where a conversation can be paused and continued across multiple invocations.
The ResumeCommand struct defines three main usage patterns:
| Pattern | Example | Description |
|---|---|---|
| By ID/Name | codex exec resume abc123 | Resume specific session by UUID or thread name |
| Last Session | codex exec resume --last | Resume the most recently updated session |
| Interactive Picker | codex exec resume | Fall back to starting fresh (no picker in exec mode) |
Flags:
--last: Resume the most recent session without requiring an ID--all: When used with picker (TUI only), shows sessions from all directoriesSources: codex-rs/cli/src/main.rs186-202 codex-rs/exec/src/lib.rs383-400
Session Resolution Logic
The resolve_resume_path function implements the following resolution strategy:
session_id parses as a UUID, search by thread ID--last flag is set, query RolloutRecorder for the most recent threadSources: codex-rs/exec/src/lib.rs562-589
When a resume path is resolved, the ThreadManager orchestrates loading the session state from its rollout file.
Key Components:
ThreadManager::resume_thread_from_rollout: Loads rollout file and reconstructs session stateRolloutRecorder: Manages JSONL rollout files that persist conversation historyfind_thread_path_by_id_str / find_thread_path_by_name_str: Locate rollout file by identifierNewThread: Return struct containing thread_id, thread handle, and session_configured eventSources: codex-rs/exec/src/lib.rs383-400 codex-rs/core/src/lib.rs87-92
After resuming a thread, exec mode can submit new input to continue the conversation:
Input resolution order:
--prompt argument provided to resume command--last is used, the session_id argument (if present) becomes the promptprompt argument from main exec command--images and root --images flagsSources: codex-rs/exec/src/lib.rs401-438
The codex review command provides non-interactive code review functionality, submitting a review request as the initial operation instead of a user turn.
ReviewArgs structure:
target: Optional custom diff target (e.g., commit range)last_diff: Boolean flag to review the last committed difffiles: List of specific files to reviewstyle: Review style preference (passed to model)Sources: codex-rs/exec/src/cli.rs (referenced), codex-rs/cli/src/main.rs86-88
Review Target Types:
| Target | Description | Usage |
|---|---|---|
Diff | Current working tree changes | Default when no flags provided |
LastDiff | Last committed diff (HEAD) | --last-diff flag |
Files(Vec<PathBuf>) | Specific files to review | List files as arguments |
| Custom | Parsed target string | --target "HEAD~1..HEAD" |
Review flow:
build_review_request constructs ReviewRequest from CLI argsparse_review_target interprets target string into structured targetuser_facing_hint generates human-readable summary for outputInitialOperation::ReviewSources: codex-rs/exec/src/lib.rs401-620
| Aspect | Resume Command | Review Command |
|---|---|---|
| Thread Creation | resume_thread_from_rollout | start_thread (new) |
| Initial Operation | InitialOperation::UserTurn | InitialOperation::Review |
| Input Source | Prompt text + images | Review target (diff/files) |
| Session State | Restored from rollout | Fresh session |
| Use Case | Continue existing work | One-shot code review |
Both commands ultimately feed into the same event processing loop, but differ in how they initialize the thread and what operation they submit as the first action.
Sources: codex-rs/exec/src/lib.rs383-529
Key Functions:
find_thread_path_by_id_str(&codex_home, id_str): Searches session directory for thread with matching UUIDfind_thread_path_by_name_str(&codex_home, name): Searches for thread with matching name metadataRolloutRecorder::find_latest_thread_path(...): Queries for most recently updated thread, optionally filtered by CWD and providerresume_thread_from_rollout(config, path, auth): Loads rollout JSONL, reconstructs conversation history, returns NewThread with restored statestart_thread(config): Creates fresh session for new conversations (review command or fallback)Sources: codex-rs/core/src/lib.rs119-134 codex-rs/exec/src/lib.rs562-589
Both resume and review commands handle missing or invalid sessions gracefully:
Common error cases:
RolloutRecorder::loadThe exec mode prints errors to stderr and exits with non-zero status code, making it suitable for scripting and CI/CD integration.
Sources: codex-rs/exec/src/lib.rs562-589
Refresh this wiki