Automating Codex Sessions

Welcome to the final lesson of the course! Thus far, we have focused on establishing Codex as a persistent agent. We created an AGENTS.md file to set rules, managed agent drift to maintain organization, and utilized slash commands to manage live sessions.

Throughout the previous lessons, we used Codex in Interactive Mode. This mode is activated when you type codex, which opens a full-screen chat window (TUI) for an extended conversation.

In this lesson, we’ll focus on session operations—how to start a session quickly with an initial instruction and, most importantly, how to resume work later without losing context.

Starting Codex with an Initial Prompt

When you already know the first thing you want, you can start Codex by passing the prompt directly:

This is useful when:

  • you want to “get to the point” without first opening a blank session
  • you’re repeating a common task and want it in your shell history
  • you want a consistent starting instruction (so the session begins with a clear goal)
  • you plan to follow up later using resume, and you want the session to have an obvious first message in the transcript

Starting with an initial prompt doesn’t just save time upfront—it makes the session easier to return to. Think of that first message as the session’s “label”: it captures the goal in one line, so the transcript is immediately recognizable in the resume list and instantly readable when you reopen it.

Resuming Your Work with resume

Codex keeps a local record of your sessions so you can return to them later. Resuming is the feature that turns Codex from a single chat into a multi-session workspace: you can pause work, switch tasks, and come back later without re-explaining what you were doing.

Note: Session retention can vary depending on your Codex version, configuration, and environment. Some setups may keep many sessions for a long time, while others may prune old sessions or cap the number of stored sessions. If you rely on a particular thread, treat the resume command/session ID as something worth saving in notes.

Why resume Matters

Use resume when you want to:

  • continue a partially completed task later
  • pick up a long-running investigation after stepping away
  • maintain separate threads for different topics (e.g., “auth refactor”, “deployment notes”, “test failures”)
  • avoid repeating repository context and prior decisions
Browse and Choose a Session

This opens a picker listing your recent sessions. Each entry typically includes a short summary so you can distinguish between them. When you select one, Codex reopens that session in the interactive UI.

Practical guidance:

  • If you’re working on multiple tasks, prefer the picker so you don’t accidentally resume the wrong thread.
  • If two sessions look similar, open one, skim the transcript, and back out—then resume the other. The transcript is your “bookmark.”
Resume the Most Recent Session

This skips the picker and immediately reopens the most recent session. Treat this as your “continue where I left off” shortcut.

This is especially useful for tight loops like:

  • ask Codex for a plan
  • exit to run tests or inspect files
  • resume and apply the next change
Resume a Specific Session by ID

When you exit a Codex session, Codex typically prints a helpful line showing exactly how to resume that specific session later—usually including a session ID. For example, you may see something like:

This is useful when:

  • you want to bookmark a specific thread (not just “the last one”)
  • you’re juggling multiple sessions and want a precise “return here” command
  • you want to copy/paste the exact resume command into notes or a TODO

Tip: If you know you’ll come back later, copy that printed resume command before closing your terminal—especially since session retention may vary by environment.

What Actually Gets Restored When You Resume

When a session is resumed, you return with continuity:

  • Transcript continuity: the full conversation is available, so you (and Codex) can reference earlier decisions, file paths, and TODOs.
  • Task continuity: you can continue the same objective without restating requirements or context.
  • Workflow continuity: you can request the “next step,” ask for a recap, or pivot slightly while keeping the original thread intact.

A good mental model is: a Codex session is a durable workspace. Resuming reopens that workspace.

How to Use Resume Effectively (Habits)
  • Exit freely: don’t keep a session open just because you might need it later—resume exists for that.
  • Keep threads separate: if you start discussing an unrelated task, consider exiting and starting a new session so resuming stays clean and predictable.
  • Ask for a checkpoint before exiting: request a short recap + next steps so resuming is instantly actionable.
  • Use --last by default, and use the picker when you’re context-switching across multiple efforts.
Summary and Course Completion
  • Start a session with an initial instruction: codex "your prompt here"
  • Resume a prior session from a list: codex resume
  • Resume the most recent session immediately: codex resume --last
  • Optionally resume a specific session using the ID Codex prints when you exit: codex resume <session-id>

While you should understand how to install and run these tools on your own machine, remember that within the CodeSignal IDE, everything is already configured for you. You’re now ready for the practice exercises, where you’ll apply these session operations.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal