Codex CLI reference and argument patterns
Overview
This page is a background reference for Codex CLI usage in terminal-based coding workflows. It focuses on argument patterns that are useful in non-interactive runs and automation scripts.
Codex evolves over time, so treat codex --help and codex exec --help as the authoritative source for the exact flags and defaults available in your installed version.
Install and authenticate
Install Codex CLI using the official install path and sign in before running repository tasks. The official documentation and repository are listed in Sources at the end of this page.
Non-interactive run pattern
A common automation shape is:
codex exec --skip-git-repo-check --sandbox workspace-write --cd <workdir> --add-dir <workdir> -
In this pattern, - is used as stdin input so prompt content can be piped safely without shell-escaping long multi-line text.
Common arguments
The following flags are commonly used in script-driven Codex runs:
| Argument | Purpose |
|---|---|
exec |
Run Codex in command mode for a single task. |
--cd <dir> |
Set working directory for the run. |
--sandbox workspace-write |
Run with writable workspace sandbox policy. |
--add-dir <dir> |
Allow additional directories when project context spans multiple paths. |
--model <model> |
Pin a specific model instead of runtime default selection. |
--oss |
Enable OSS/local mode where applicable. |
-c <key=value> |
Pass low-level runtime config overrides. |
- |
Read prompt from stdin. |
Model and reasoning tuning
When your version supports it, model-level tuning can be provided through -c overrides. Common examples include reasoning effort, reasoning summary behavior, and verbosity.
codex exec \
--sandbox workspace-write \
--cd /path/to/repo \
--model gpt-5-codex \
-c 'model_reasoning_effort="high"' \
-c 'model_verbosity="low"' \
-
Use the exact value set accepted by your installed Codex version (codex exec --help).
Prompt input patterns
For one-line tasks, inline prompt text is usually enough. For multi-line prompts, stdin is generally safer and easier to review in shell history.
printf '%s\n' "Review this repository and propose the next three tasks." | \
codex exec --sandbox workspace-write --cd /path/to/repo -
For longer prompts:
cat prompt.txt | codex exec --sandbox workspace-write --cd /path/to/repo -
Repository and multi-directory access
When a task needs files outside the primary working directory, pass explicit --add-dir flags. This is common with monorepos, nested repositories, and setups that rely on external build or dependency directories.
codex exec \
--sandbox workspace-write \
--cd /path/to/repo \
--add-dir /path/to/repo \
--add-dir /path/to/shared \
-