Generate images from Claude with the Codex CLI
-
What you'll see
An AI agent such as Claude (Claude Code) is building or updating a Docly site and needs a photo or an illustration — a hero image, a background, a picture for an article — but answers that it cannot generate images, or falls back to a placeholder.
-
What's actually happening
Claude cannot create images. It can write SVG and CSS, but not a photo or a painted illustration. The Codex CLI from OpenAI can: it has a built-in image generation tool, and
codex execruns Codex without its interactive screen. Claude Code, or any agent with a terminal, calls it like any other command and gets a PNG file back.What happens in a call. Codex generates the image and saves it under
~/.codex/generated_images/, in a folder per session. Then it does what the prompt asks for — here, copying the file into the folder the agent works in. If the prompt does not ask for the copy, the file stays under~/.codex.Measured 2026-11-12 with codex-cli 0.156.1 on Windows: one square illustration, 1254×1254 pixels, a 1.4 MB PNG, in 2 minutes 7 seconds.
-
What to do
1. Install the Codex CLI (once per machine)
The Codex CLI needs Node.js. Install it with npm and check the version:
npm install -g @openai/codex codex --versionUpdate it later with
codex update.2. Sign in (once, by a person)
codex loginThis opens the browser to sign in with a ChatGPT account. The built-in image tool runs on that account; no OpenAI API key is needed. Signing in is the person's job: the agent asks for it and waits.
Check that image generation is on: in the output of
codex features list, the lineimage_generationmust end intrue.3. Let the agent call Codex
codex exec --skip-git-repo-check -s workspace-write -C "<scratch folder>" "Generate one image with your built-in image generation tool: <what the image shows, style, format>. Copy the generated file into this folder as images/hero.png. Reply with the saved path only."-Csets the folder Codex works in, and-s workspace-writelets it write only there. Use a scratch folder outside the docly working copy, so drafts are never pushed.--skip-git-repo-checklets Codex run in a folder that is not a git repository.- Say what the image shows, the style and the format (square, wide 16:9), and give the file name. One call per image.
- Give the call time. One image took just over two minutes in the measurement above, which is longer than the two-minute default of Claude Code's shell tool. Set the timeout to five minutes or more, or run the call in the background.
4. Look at the image before using it
Claude can open the PNG and see it. Check it against what was asked for. If something is off, ask for a new image with one specific change rather than a new prompt from scratch.
5. Put it on the site
Copy the chosen file into the working copy and push it, like any other image. Keep the full-size original and let Docly scale and convert it to WebP or AVIF when it is served — see Scale and convert images in Docly. Images for social sharing must stay JPEG or PNG.
Icons, diagrams and simple shapes are still better as SVG or CSS: they scale cleanly and can be edited.
Last reviewed 12 Nov 2026