Context

codex exec can generate PNGs on a ChatGPT login, with no API key, when the image_generation feature is on. It calls a built-in image tool and saves the files under ~/.codex/generated_images/<thread>/.

Insight

  • -m doesn’t pick the image model. It only changes the agent model that drives the tool. The PNG’s embedded C2PA metadata names ChatGPT/gpt-image as the generator whatever -m is set to.
  • Overwrite trap: Codex’s bundled imagegen instructions refuse to overwrite an existing file and save a sibling such as hero-v2.png instead. So “the requested path exists” is a false pass when a run fails or writes elsewhere.
    • Use a fresh output path, or say “overwrite” explicitly in the prompt.
    • Verify against the path in the final message written by -o, not against the path you asked for.
  • Non-TTY runs wait on stdin: pass < /dev/null.
  • --ignore-user-config avoids errors from broken plugin hooks. It only cuts input tokens from about 130k to 110k, so don’t use it to save cost.

Snippet

Terminal window
codex exec --ignore-user-config -o last.txt \
"Generate a 1536x1024 hero image ... save it to ./out/hero-$(date +%s).png" < /dev/null
cat last.txt # check the path actually written