Howto codex

Static reading edition · s10-01

Understand the interactive CLI and scripted runs

Working from the command line14 min estimatedApp-based lab / Optional CLI

Choose the terminal workflow that fits the task and confirm its environment before running work.

Understand the approach

The command-line interface lets Codex work from a terminal against local project files. Running codex opens an interactive terminal user interface, often shortened to TUI. You can give an initial request and continue with follow-ups, inspect commands and steer the task. The desktop app is still the default learning surface for this course; use the CLI when terminal navigation or repeatable execution makes the work easier.

A scripted run uses codex exec rather than Claude’s print-mode flags. It accepts a task and finishes without opening the interactive conversation UI. This is useful for a bounded summary or structured extraction. It is not automatically safe because it lacks a chat window: the working directory, authentication, permissions and available tools still determine what the agent can do. Begin with a read-only task that produces an inspectable result.

Install through an option documented on the official Codex CLI page if the CLI is absent, using your normal software-approval process. The current guide includes standalone installation for supported operating systems and package-manager alternatives. This course does not run installation for you. If the CLI is already available, check its version and help rather than installing another copy. Multiple installations can make documentation and observed behavior disagree.

Interactive work and scripted work have different interfaces

Use the interactive CLI for an ongoing conversation. Use codex exec for a bounded non-interactive task with an explicit output contract. Both require the correct project scope and result verification.

Use the interactive CLI for an ongoing conversation. Use codex exec for a bounded non-interactive task with an explicit output contract. Both require the correct project scope and result verification.

Open the full diagram

Compare one-shot execution with a continuing app chat

The dry-run planner prints run:false, the exact red project path and a fixed codex exec argument array. It launches no child. Inspect the directory and output artifacts before an optional authenticated task: events.jsonl, stderr.txt and final.json, accompanied by process.json.

The app chat can be steered with follow-ups. A one-shot process needs enough input and a verification contract up front. The optional runner captures process exit separately from event contents; the local exercise never claims that a Codex account or model ran.

A terminal is another project surface

Your shell’s current directory matters just as much as the folder selected in the app. Quote paths containing spaces and confirm whether commands run on the local computer, a remote host or a container. If a scripted run refuses a non-Git folder, use an appropriate disposable Git project rather than disabling repository checks casually. An environment mismatch should be diagnosed before model settings are changed.

About your environment

Checked 21 October 2026. Feature availability varies by client and host.

Try it step by step

  1. Open the fictional red project in the app and identify its actual source facts.
  2. Inspect the dry-run plan: directory, fixed argument array and new output artifacts; no Codex child starts.
  3. Compare app follow-up interaction with the one-shot prompt and process boundary.
  4. If independently choosing an existing authenticated CLI, inspect help first and record actual output; otherwise mark the client run unexecuted.

A useful starting example

Illustration · adapt before use.

Inspect a local invocation plan — no Codex child starts shell
node labs/cli-pipeline/capture-codex.cjs --project red
Read-only terminal orientation; run from an existing scratch project shell
codex --version
codex --help
codex --sandbox read-only "Read README.md and explain this scratch project without editing it."
codex exec --sandbox read-only "Read README.md and list missing setup information. Do not edit files."
From input to result

Understand the process loop before a live CLI run

Use the app to inspect and run the local synthetic producer; no Codex CLI account or installation is required.

Worked input shell
node labs/cli-pipeline/run-pipeline.cjs success
node labs/cli-pipeline/run-pipeline.cjs incomplete
Expected result · compare with your run
success → Outcome: completed, exit 0
incomplete → Outcome: incomplete, exit 4
Both runs are labelled synthetic and use no model service.

The offline lab makes process output and completion observable before an optional authenticated codex exec invocation.

Hands-on exercise

Your turn

Open the lab in the Codex app, inspect the red fixture README and ask a follow-up about its missing deployment URL. Generate the dry-run CLI plan and compare its one-shot prompt, resolved directory, arguments and output files with the ongoing app conversation. If you separately choose an existing authenticated CLI, execute the optional read-only capture and record its actual result; otherwise mark it unrun.

Try the exercise before opening its reference answer. Use a disposable practice folder.

Run the practice

Offline CLI event pipeline

Extract into a new practice folder and keep the included labs folder. Run these commands from that extraction root, or from the course folder, using an existing Node.js installation.

  1. Command 1 text
    node labs/cli-pipeline/capture-codex.cjs --project red

    Check: run:false; resolved red source path, fixed read-only arguments and output plan. No authenticated child starts.

  2. Command 2 text
    node labs/cli-pipeline/capture-codex.cjs --project blue

    Check: run:false; a distinct blue path, project name and documented check.

Commands are relative to the course folder. Open the lab in the Codex app first. Lesson-specific artifacts separate offline execution from optional authenticated CLI observations; a dry-run plan is not a live model result.

Check your result

  • The installed executable and version are identified, with no unnecessary global installation or settings change.
  • Both tasks inspect the same intended project and produce source-grounded answers.
  • You can explain why interactive codex and codex exec differ from each other and from desktop navigation.
Reference answer & rubric Try the exercise before opening

Start with the app and the local process contract, then compare interactive versus scripted Codex only when the client already exists.

  1. Open the lab in the Codex app and read the synthetic-fixture declaration.
  2. Run the two local cases and inspect both output and exit code.
  3. Explain how a one-shot process differs from an ongoing app chat.
  4. Compare the actual result with the lesson-specific answer key; record unrun client observations separately from executed local checks.
Think it through

Check your understanding

Which entry point is intended for a bounded non-interactive Codex task?

  1. codex exec
  2. claude -p
  3. /new typed directly into PowerShell
Reveal the answer and explanation

Answer 1: codex exec

codex exec is the documented scripted entry point; the other examples belong to another product or to the interactive composer.

Take this quiz in the interactive lesson to save your answer in the browser.

When it does not work

The lab cannot find node.

Likely cause: The current terminal does not expose an existing Node runtime.

What to try: Use the host’s configured runtime or inspect the source and mark execution unrun; do not install implicitly.

The synthetic result is described as a live model answer.

Likely cause: Fixture execution and service execution were conflated.

What to try: Retain the synthetic label and separate the unperformed Codex step.

Common mistakes

  • Using claude -p style flags in Codex without consulting the current command reference.
  • Assuming an unattended run has no permission or verification requirements.
Source mapping & differences · different

Codex uses interactive codex and non-interactive codex exec; Claude print-mode flags and native-install instructions are not copied across products.

Source topic: Overview ↗

Go to the source

Official documentation, checked 21 October 2026. Product names, controls and availability may vary with your version, platform or account.

Continue in the interactive lesson →

Completion and quiz progress are saved
only in the interactive course.