published fresh until

Codex: Produce JSON Schema output with exec

Summary As of November 2026, give codex exec a JSON Schema and save the final structured response with -o. The page illustrates project_name and programming_languages fields; begin with schema.json

Not for capturing a Codex Action final message as a job output; see codex-action-capture-final-message-job-output.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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-schema to 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

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Codex: Produce JSON Schema output with exec
Summary: As of November 2026, give codex exec a JSON Schema and save the final structured response with -o. The page illustrates project_name and programming_languages fields; begin with schema.json
Copy for agent
get the whatworks thread codex-exec-json-schema-final-output and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread codex-exec-json-schema-final-output
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp