Codex CLI Execution Modes
Introduction
Welcome to Mastering Advanced AI Tooling in Codex! This is the first lesson of the course. Throughout the course, we'll use Codex as a durable agent to help plan development work and automate workflows reliably.
In this lesson, we'll focus on the Codex CLI's execution modes—especially what changes when you run a prompt normally versus running it with exec, and why that difference matters for automation.
Understanding the Two CLI Modes
Before we dive into commands, let's establish a mental model.
Default mode: help and exploration
When you run a plain codex prompt, Codex can often behave like an agent: it may inspect your repository (for example, by listing directories, searching for filenames, or reading config files) to produce a better answer.
However, this mode does not provide a strict automation contract. You typically get:
- A helpful response (often based on a mix of model knowledge and observed repo context)
- No guarantee that any suggested results (like "tests pass") were actually executed
- No reliable task succeeded or failed signal for automation pipelines
Think of this as: "help me understand, plan, summarize, or suggest"—possibly with some repo exploration.
Exec mode: execution and verification
When you run codex exec, you're invoking Codex as an execution engine. It must perform real actions (running commands, editing files when requested), observe actual outputs, and finish with an exit code that represents the task outcome.
Think of this as: do it for real, and prove it with the environment.
Default Mode: Helpful Answers Without Automation Guarantees
Suppose we have failing tests in our JavaScript project, and we want Codex to analyze them and suggest a fix:
Note: --yolo stands for "You Only Look Once." It is a safety bypass flag that tells Codex to execute commands immediately without stopping to ask you for permission. This is useful for fast iteration during development or when running Codex in automated scripts.
What happens behind the scenes (in default mode) typically looks like this:
- Codex receives your prompt.
- It may explore the repository (search for tests, skim files, read configs) to improve its answer.
- It generates a response that appears in your terminal as text.
The output might look something like this:
Key point: even if Codex explored your repo to form this answer, default mode still does not guarantee that:
- tests were actually executed,
- the failure summary corresponds to a real test run,
- the suggested fix was validated.
You should treat default mode as high-quality assistance, not a CI-grade signal. It's excellent for learning, exploration, getting explanations, brainstorming approaches, or receiving code snippets that you will review and apply yourself.
