Adds a generate_image tool: Claude hands image requests to the local Codex (ChatGPT) CLI and gets back the saved file.

🇬🇧 English · 🇹🇭 ภาษาไทย
A Claude Code mod that lets Claude generate images through ChatGPT. It adds a generate_image tool; when you ask Claude to create an image, Claude hands the request to your local Codex CLI (signed in with your ChatGPT account), and Codex saves the image to disk.
D:\images\cat.png".generate_image tool with a prompt and an output_path.codex exec with that request. Codex generates the image with its image tool and saves it at output_path.codex login status)At the prompt of a Claude Code terminal session:
/plugin install codex-imagegen --marketplace bngxyz/codex-imagegen
From a shell:
claude plugin install codex-imagegen --marketplace bngxyz/codex-imagegen
Answer y to "Add marketplace?", pick a scope (user scope = every session), then enter the option below when asked.
In the desktop app, where /plugin does not run: click + next to the prompt box, then Plugins, Add marketplace with bngxyz/codex-imagegen, then Add plugin.
The mod has one required option, codexPath: the full path to the Codex executable. Without it the mod refuses to load (it never guesses a path).
Find it:
(Get-Command codex).SourceC:\Users\<you>\AppData\Local\Programs\OpenAI\Codex\bin\codex.exewhich codexSet it in the plugin's config screen at install time, or in ~/.claude/settings.json:
{
"pluginConfigs": {
"codex-imagegen": {
"options": {
"codexPath": "C:\\Users\\<you>\\AppData\\Local\\Programs\\OpenAI\\Codex\\bin\\codex.exe"
}
}
}
}
Just ask Claude for an image and say where to save it:
Generate a watercolor mountain landscape and save it to
D:\images\mountain.png
--sandbox workspace-write and --skip-git-repo-check. Generation can take a while (timeout: 10 minutes).mod สำหรับ Claude Code ที่ทำให้ Claude สร้างรูปผ่าน ChatGPT ได้ โดยเพิ่มเครื่องมือ generate_image เมื่อคุณสั่งให้ Claude สร้างรูป Claude จะส่งงานต่อให้ Codex CLI ในเครื่องคุณ (ล็อกอินด้วยบัญชี ChatGPT) แล้ว Codex จะบันทึกรูปลงไฟล์ให้
D:\images\cat.png"generate_image พร้อม prompt และ output_pathcodex exec ส่งคำขอนั้นให้ Codex สร้างรูปและบันทึกไว้ที่ output_pathcodex login status)พิมพ์ใน Claude Code (เทอร์มินัล):
/plugin install codex-imagegen --marketplace bngxyz/codex-imagegen
หรือจาก shell:
claude plugin install codex-imagegen --marketplace bngxyz/codex-imagegen
ตอบ y เมื่อถามว่า "Add marketplace?" เลือก scope (user scope = ใช้ได้ทุก session) แล้วใส่ค่า option ด้านล่างเมื่อถูกถาม
ถ้าใช้แอป desktop ซึ่งไม่รองรับ /plugin: กดปุ่ม + ข้างช่องพิมพ์ → Plugins → Add marketplace ใส่ bngxyz/codex-imagegen → Add plugin
mod มี option ที่ต้องกรอกหนึ่งตัวคือ codexPath (path เต็มของไฟล์ Codex) ถ้าไม่ตั้ง mod จะไม่โหลด เพราะไม่เดา path ให้
วิธีหา path:
(Get-Command codex).SourceC:\Users\<ชื่อคุณ>\AppData\Local\Programs\OpenAI\Codex\bin\codex.exewhich codexตั้งค่าในหน้า config ตอนติดตั้ง หรือแก้ ~/.claude/settings.json:
{
"pluginConfigs": {
"codex-imagegen": {
"options": {
"codexPath": "C:\\Users\\<ชื่อคุณ>\\AppData\\Local\\Programs\\OpenAI\\Codex\\bin\\codex.exe"
}
}
}
}
สั่ง Claude ให้สร้างรูปและบอกที่เซฟได้เลย เช่น
สร้างรูปภูเขาสไตล์สีน้ำ เซฟที่
D:\images\mountain.png
--sandbox workspace-write และ --skip-git-repo-check การสร้างรูปอาจใช้เวลานาน (timeout 10 นาที)hooks/register.ts 74 lines1import type { Register } from 'claude-code'
2
3const TOOL = 'mcp__codex-imagegen__generate_image'
4
5export const register: Register = (on, options) => {
6 const codexPath = options.codexPath
7 if (typeof codexPath !== 'string' || codexPath === '') {
8 throw new Error('codex-imagegen: option "codexPath" is required (full path to codex.exe)')
9 }
10
11 on('session.start', async ($, e, next) => {
12 await $.tool.register({
13 name: 'generate_image',
14 description:
15 'Generate an image by delegating to ChatGPT via the local Codex CLI. ' +
16 'Use this whenever the user asks to create/draw/generate an image. ' +
17 'Codex saves the image to output_path; the tool returns that path.',
18 inputSchema: {
19 type: 'object',
20 properties: {
21 prompt: { type: 'string', description: 'Detailed description of the image to generate.' },
22 output_path: {
23 type: 'string',
24 description: 'Absolute path of the PNG file to save, e.g. D:\\images\\cat.png.',
25 },
26 },
27 required: ['prompt', 'output_path'],
28 },
29 isDeferred: false,
30 })
31 return next(e)
32 })
33
34 on('tool.call', { tool: TOOL }, async ($, e) => {
35 const { prompt, output_path } = e as unknown as { prompt?: unknown; output_path?: unknown }
36 if (typeof prompt !== 'string' || prompt === '') {
37 return { deny: 'generate_image: "prompt" is required.' }
38 }
39 if (typeof output_path !== 'string' || output_path === '') {
40 return { deny: 'generate_image: "output_path" is required.' }
41 }
42
43 $.ui.status('Codex: generating image…')
44 try {
45 const instruction =
46 'Use your image generation tool to create the following image, then save the ' +
47 `resulting image file exactly at this absolute path: ${output_path}\n` +
48 'Reply with only the final saved path, or an error message if you could not.\n\n' +
49 `Image request:\n${prompt}`
50
51 const run = await $.process.run(
52 [
53 codexPath,
54 'exec',
55 '--skip-git-repo-check',
56 '--sandbox',
57 'workspace-write',
58 '--color',
59 'never',
60 '-',
61 ],
62 { stdin: instruction, timeoutMs: 600000 },
63 )
64
65 if (run.exitCode !== 0) {
66 return { result: `Codex failed (exit ${run.exitCode}): ${run.stderr.slice(-2000)}`, isError: true }
67 }
68 return { result: `Codex finished. Output:\n${run.stdout.trim()}\nExpected file: ${output_path}` }
69 } finally {
70 $.ui.status(undefined)
71 }
72 })
73}
74