TL;DR — Use Codex CLI to connect OpenAI Image-2 into Claude Code. No OpenAI API key required. Say “generate an image” and the file lands in
./images/. There’s a Skill for both the Claude Code terminal and the Claude App / Cowork — both downloadable and ready to use.
I spend most of my day in Claude Code.
Writing articles, breaking down tasks, organizing materials, editing code, generating prompts — most of my work happens in a single Claude window.
But one thing breaks the flow every time: image generation.
I also have a ChatGPT / OpenAI account, and OpenAI’s image generation is genuinely good. The problem is, every time I need an image, I have to switch to the ChatGPT web UI, paste a prompt, wait for the image, download it, and move the file back into my project folder.
None of those steps are hard. They’re just annoying.
So I wanted to do something lazy:
Could I just say “generate me an image” inside Claude Code, have it call Codex CLI, use my ChatGPT account to run OpenAI Image-2, and drop the file directly into ./images/?
The answer is: yes.
This post is the complete walkthrough.
If you’re just getting into Claude Code, here’s the thing this post is really about: the best AI tools aren’t the ones with the most capabilities — they’re the ones you can chain together so your workflow never has to stop.
This post is especially for you if:
- You’re getting into Claude Code and excited about it
- You also have a ChatGPT or OpenAI account
- You regularly need image assets in articles, presentations, product mockups, or project folders
- You’re tired of switching to ChatGPT’s web UI every time you need a picture
- You want to start connecting AI tools into a real workflow, not just using them one at a time
If you only generate an image occasionally, just use the ChatGPT web UI — that’s totally fine. The value here is turning image generation into something repeatable, batchable, and triggerable from a single phrase.
A quick translation for the jargon
| Term | What it means in plain English |
|---|---|
| Claude Code | Claude’s developer environment — it can read files, write files, and run commands inside your project folder |
| Codex CLI | OpenAI’s local command-line tool — log in with your ChatGPT account to bring OpenAI’s capabilities into your terminal |
| Image-2 | OpenAI’s image generation model used in this tutorial; in API docs it’s called gpt-image-2 |
| Skill | A set of instructions you give Claude so it knows what to do when you ask for something specific |
| MCP | A bridge that lets the Claude desktop App call capabilities on your local machine |
| Cowork | A mode inside the Claude desktop App designed for collaborative work — it can create files and outputs |
What you’ll end up with
Inside Claude Code, you can say:
Generate a shiba inu wearing sunglasses and save it as
./images/shiba.png
Claude assembles the prompt, calls the local Codex CLI. Codex CLI uses your ChatGPT account to call OpenAI Image-2, and the image lands in your project folder.
No ChatGPT web UI. No manual download. No API key.
How the workflow runs
The main path is straightforward:
You describe what you want in Claude
→ Claude assembles the prompt
→ Codex CLI runs
→ ChatGPT account authenticates
→ Image-2 generates the image
→ PNG saved to ./images/
No matter which Claude interface you use, everything converges on the same OpenAI chain:

The only difference between the two paths is how Claude calls your local codex.
Claude Code can run Bash natively, so it calls codex directly. Claude App / Cowork can’t run terminal commands directly, so it needs the “Control your Mac” MCP as a bridge. Everything after that is identical — Codex authenticates via your ChatGPT account, calls Image-2, and the image lands where you told it to.
flowchart LR
U([User]) -->|"generate a shiba inu"| D{Which interface?}
D -->|Claude Code terminal| S1[gen-image-cli<br/>Skill]
D -->|Claude App / Cowork| S2[gen-image-app<br/>Skill]
S1 -->|Bash direct call| CX[Codex CLI 0.125+<br/>local]
S2 -->|Control your Mac MCP<br/>osascript| CX
CX -->|ChatGPT account auth| TOOL[image_gen.imagegen]
TOOL --> GPT[(OpenAI Image-2<br/>gpt-image-2)]
GPT -->|PNG bytes| F[./images/foo.png]
F -->|"CLI: project folder<br/>App: Cowork outputs"| U
What you need to set up
1. Install Codex CLI
Pick one:
# npm version (cross-platform)
npm i -g @openai/codex
# or Homebrew (macOS)
brew install --cask codex
2. Log in with your ChatGPT account
codex login # opens a browser to authorize via your ChatGPT account
codex login status # should show "Logged in using ChatGPT"
3. Confirm your account can use image generation
This approach uses ChatGPT account authorization — not an OpenAI API key.
Per OpenAI’s announcement, all ChatGPT and Codex users can access image generation:
| Plan | Can use it? | Notes |
|---|---|---|
| Free ChatGPT | ✅ Yes | Basic image generation |
| ChatGPT Plus / Pro / Business | ✅ Yes | Better quality, more control, complex scenes |
| OpenAI API | ✅ Yes | Different path — uses API key and token billing |
Key point: you don’t need Plus to run this setup. Free accounts work too — the difference is just output quality.
4. For Claude App / Cowork users: install the Control your Mac MCP
Pure Claude Code terminal users can skip this — Bash can call codex directly.
If you want to say “generate an image” inside the Claude desktop App’s Cowork mode, you need the Control your Mac MCP so Claude can reach your local codex. Download the .mcpb file and double-click to install. The first call will trigger a macOS automation permission prompt — allow it.
Minimum viable version: just run it once first
If you want to confirm this actually works before building a Skill, here’s the smallest possible test.
Three steps:
- Install Codex CLI
- Run
codex login - In your project folder, run:
mkdir -p ./images
codex exec -C "$(pwd)" -s workspace-write \
--skip-git-repo-check \
"use the image generation tool to create a shiba inu wearing sunglasses, save to ./images/shiba.png"
If it works, you’ll find:
./images/shiba.png
Get this working first, then worry about building a Skill. Don’t try to debug Codex CLI, Skill, MCP, and Cowork all at once — you won’t know which layer broke.
What the actual output looks like
The test run took about a minute and produced a 1254×1254, ~2 MB PNG:

The point isn’t the shiba inu. The point is that the image landed in ./images/shiba.png — no browser, no pasting into a web UI, no manual download.
Two pitfalls I hit
Pitfall 1: First run blocked by .codex permissions
If you see:
Failed to create session: Operation not permitted
It’s usually a permissions issue on ~/.codex. Fix it with:
sudo chown -R $(whoami) ~/.codex
Then run the command again.
Pitfall 2: Image not where you expected it
-C "$(pwd)" means: use the folder you’re currently in as the working directory when you run the command.
So you need to cd into your project folder first:
cd your-project-folder
Then run codex exec. Otherwise the image may end up in your home directory, Downloads, or somewhere you didn’t intend.
Package it as a Skill: just say “generate an image”
The codex exec command works, but typing it out every time is tedious.
I packaged it into two Claude Skills:
| Where you’re using Claude | Which Skill | MCP needed? |
|---|---|---|
| Claude Code terminal | gen-image-cli | No |
| Claude desktop App / Cowork | gen-image-app | Yes — Control your Mac MCP |
Claude Code users: start with the CLI version
If you mainly work in Claude Code, this is the simpler path. Claude Code can run Bash natively, so gen-image-cli calls your local codex directly — no additional setup.
Claude App / Cowork users: the App version
If you want to say “generate an image” directly in the Claude desktop App or Cowork window, you need the “Control your Mac” MCP as a bridge. Because Claude App can’t run terminal commands directly, it uses MCP / osascript to ask your Mac to execute codex on its behalf.
Download and install
📦 Download: gen-image-skills.zip
mkdir -p ~/.claude/skills && unzip -o ~/Downloads/gen-image-skills.zip -d ~/.claude/skills/
Once installed, in either interface you can say “generate me a capybara wearing a hat” and Claude will pick whichever Skill matches the available tools.
If you want to write the CLI version yourself, the core of ~/.claude/skills/gen-image-cli/SKILL.md looks like this:
---
name: gen-image-cli
description: From within Claude Code (CLI), call the local Codex CLI via Bash to generate images (Image-2 underneath, API model gpt-image-2), saved to ./images/ in the current working directory. Triggers: generate image, draw something, create an image.
allowed-tools: Bash(codex:*) Bash(mkdir:*) Bash(ls:*) Bash(pwd:*)
---
# Image Generation Skill (Claude Code CLI version)
When the user says "generate image" or similar, follow these steps:
1. Confirm the current working directory (pwd)
2. Create the output folder: mkdir -p ./images
3. Extract the image description and an English filename from the user's message
4. Call:
codex exec -C "$(pwd)" -s workspace-write \
--skip-git-repo-check \
"use the image generation tool to create [description], save to ./images/[filename].png"
5. ls to confirm the file, report the absolute path
The App version swaps allowed-tools to mcp__Control_your_Mac__osascript and routes through osascript on the host Mac. Full content is in gen-image-app/SKILL.md inside the zip.
A few principles for both: write clear trigger phrases in the description so Claude knows when to use the Skill; lock down allowed-tools to only what’s necessary; step descriptions can be in plain language.
Who this is for — and who it isn’t
Good fit:
- People already working in Claude Code regularly
- Dual Claude + ChatGPT / OpenAI subscribers
- Anyone who frequently needs article covers, presentation graphics, product mockups, or course assets
- People who want repeatable AI workflows, not one-off manual operations
- Anyone curious about how Claude Skills, MCP, and local CLIs can be chained together
Not a great fit:
- People who generate images only occasionally (just use ChatGPT’s web UI)
- People who don’t want to touch the terminal
- Anyone who doesn’t need images to land in a specific project folder or be generated in batch
Conclusion: one fewer interruption
The real value here isn’t “I connected another AI tool.”
It’s that the workflow has one fewer interruption.
Claude stays the brain — understanding what I need, breaking down tasks, assembling prompts. Codex CLI is the hand — calling Image-2 and producing the image. The file lands in the project folder. No window switching, no downloading, no moving files.
If you’re paying for both Claude and ChatGPT, this is the smoothest integration I’ve found.
The subscription dollars don’t go to waste, and the workflow gets shorter.
I’ll keep writing about this kind of AI workflow integration at paulkuo.tw — not just what AI tools can do, but how to actually wire Claude, Codex, Skills, MCPs, knowledge management, and automation into daily work. If you’re turning AI into your second workbench, feel free to come back.
💬 Comments
Loading...