Shell scripts often need a model's answer without an interactive session. Codex exec accepts a task prompt and returns the final response on standard output, while progress goes to standard error.
A prompt supplies instructions; repository files and piped text supply material to inspect. Keeping those roles separate lets an automation reuse one task with changing input.
The CLI needs a working model provider, and OpenAI-hosted models require authentication. An existing trusted Git repository is enough for a request that needs no file changes.
Prompt text and any repository content Codex reads can reach the selected model provider. Credentials and private project data should stay out of requests unless that provider is approved to receive them.
Steps to run Codex exec with a prompt:
- Pass a quoted task to Codex exec from your repository.
$ codex exec 'Suggest a short commit title for a typo fix. Reply with only the title.' ##### snipped ##### "fix typo in README"
The shell passes the quoted text as one prompt argument. Codex returns to the shell when the run finishes. The default sandbox is read-only, and this request needs no file edits.
Related: How to set the working directory for CodexOptional stdin input can carry the entire task instead. The - argument explicitly reads the prompt from stdin.
$ printf '%s\n' 'Suggest a short commit title for a typo fix. Reply with only the title.' | codex exec -
With a quoted prompt argument in place of -, piped text is additional context for that task, rather than the task itself.
- Confirm that the final answer suggests a commit title for a typo fix.
The answer should be a short title describing the typo correction. Its wording depends on the model. An authentication error, connection error, or missing final answer means the request has not completed successfully. Progress messages appear on standard error; the final answer appears on standard output.
Related: How to save the last Codex response to a file
Related: How to enable JSON output in Codex