noninteractive.md +22 −2
1# Non-interactive mode1# Non-interactive mode
2 2
3Use `codex exec` to run Codex in scripts and CI
4
5Non-interactive mode lets you run Codex from scripts (for example, continuous integration (CI) jobs) without opening the interactive TUI.3Non-interactive mode lets you run Codex from scripts (for example, continuous integration (CI) jobs) without opening the interactive TUI.
6You invoke it with `codex exec`.4You invoke it with `codex exec`.
7 5
113 111
114`codex exec` reuses saved CLI authentication by default. In CI, it's common to provide credentials explicitly:112`codex exec` reuses saved CLI authentication by default. In CI, it's common to provide credentials explicitly:
115 113
114### Use API key auth (recommended)
115
116- Set `CODEX_API_KEY` as a secret environment variable for the job.116- Set `CODEX_API_KEY` as a secret environment variable for the job.
117- Keep prompts and tool output in mind: they can include sensitive code or data.117- Keep prompts and tool output in mind: they can include sensitive code or data.
118 118
124 124
125`CODEX_API_KEY` is only supported in `codex exec`.125`CODEX_API_KEY` is only supported in `codex exec`.
126 126
127Use ChatGPT-managed auth in CI/CD (advanced)
128
129Read this if you need to run CI/CD jobs with a Codex user account instead of an
130API key, such as enterprise teams using ChatGPT-managed Codex access on trusted
131runners or users who need ChatGPT/Codex rate limits instead of API key usage.
132
133API keys are the right default for automation because they are simpler to
134provision and rotate. Use this path only if you specifically need to run as
135your Codex account.
136
137Treat `~/.codex/auth.json` like a password: it contains access tokens. Don't
138commit it, paste it into tickets, or share it in chat.
139
140Do not use this workflow for public or open-source repositories. If `codex login`
141is not an option on the runner, seed `auth.json` through secure storage, run
142Codex on the runner so Codex refreshes it in place, and persist the updated file
143between runs.
144
145See [Maintain Codex account auth in CI/CD (advanced)](https://developers.openai.com/codex/auth/ci-cd-auth).
146
127## Resume a non-interactive session147## Resume a non-interactive session
128 148
129If you need to continue a previous run (for example, a two-stage pipeline), use the `resume` subcommand:149If you need to continue a previous run (for example, a two-stage pipeline), use the `resume` subcommand: