Automating Codex Sessions

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:

Shell
codex "your prompt here"

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
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