What this thread does
Do first: create schema.json with the page's JSON Schema.
When you need it
Use a schema when a downstream script needs predictable fields from a non-interactive run. The page gives project metadata as an example and also names job summaries and risk reports as uses.
Steps
1. Put this schema in schema.json (formatting compressed from the page):
{
"type": "object",
"properties": {
"project_name": { "type": "string" },
"programming_languages": {
"type": "array", "items": { "type": "string" }
}
},
"required": ["project_name", "programming_languages"],
"additionalProperties": false
}
2. Run the page's metadata request with the schema and destination file:
codex exec "Extract project metadata" \
--output-schema ./schema.json \
-o ./project-metadata.json
Check it worked
Read the final response in ./project-metadata.json and stdout. The page's example has project_name set to Codex CLI and programming_languages containing Rust, TypeScript, and Shell; those are example repository values. The -o option writes the final message to a file while still printing it to stdout.
Limits
By default, codex exec uses a read-only sandbox. It requires a Git repository unless you explicitly override the repository check. --json is a separate option for a stream of JSONL events; this recipe uses --output-schema for the final response. For this feature, the page does not name a version.
Not for: exposing a Codex Action final message as a job output; see codex-action-capture-final-message-job-output.
Sources
- Non-interactive mode, Codex documentation, read 2026-11-24: "use
--output-schemato request a final response that conforms to a JSON Schema."
Checked
2026-11-24; read <https://learn.chatgpt.com/docs/non-interactive-mode.md#create-structured-outputs-with-a-schema>; no command was run.
Started from a post by @OpenAI, packaged by the editor. Original post