🪞 GPT Image 2 — Image Generation via Your ChatGPT Subscription agentspace.so · GitHub Generate images with GPT Image 2 (ChatGPT Images 2.0) inside your agent, using your existing ChatGPT Plus or Pro subscription — no separate OpenAI access, no Fal or Replicate tokens, no per-image billing. Text-to-image, image-to-image editing, style transfer, and multi-reference composition. Runs entirely through the local CLI you're already logged into. Heads up — this skill requires a ChatGPT Plus or Pro subscription plus the Codex CLI installed locally. If you have neither, you can use GPT Image 2 in the…

\\nRequirements: generate the image directly, return only the image, no explanation.\\n\\nRequest:\\n'\"$PROMPT\"\n\n# `-i` is a variadic flag (\u003cFILE>...), so passing the prompt as the trailing\n# positional would be consumed as another image file. Feed the prompt via\n# stdin instead (codex exec reads from stdin when no prompt positional is\n# given).\n\nTO=\"\"\nif command -v timeout >/dev/null 2>&1; then TO=\"timeout\"\nelif command -v gtimeout >/dev/null 2>&1; then TO=\"gtimeout\"\nfi\n\nset +e\nif [[ -n \"$TO\" ]]; then\n printf '%s' \"$instruction\" | \"$TO\" \"$TIMEOUT_SEC\" codex \"${args[@]}\" >\"$stdout_log\" 2>\"$stderr_log\"\nelse\n printf '%s' \"$instruction\" | codex \"${args[@]}\" >\"$stdout_log\" 2>\"$stderr_log\"\nfi\nrc=$?\nset -e\n\nif [[ $rc -ne 0 ]]; then\n echo \"codex exec failed (exit=$rc). stderr tail:\" >&2\n tail -n 40 \"$stderr_log\" >&2 || true\n exit 5\nfi\n\nfind \"$SESSIONS_ROOT\" -type f -name 'rollout-*.jsonl' -print 2>/dev/null | sort > \"$after\" || true\n\n# Collect ALL new session files. A single `codex exec` call can spawn more\n# than one session rollout (e.g. when the imagegen tool runs in a sub-turn),\n# so we must scan every new one rather than blindly picking the last.\nnew_sessions_file=\"$(mktemp)\"\ntrap 'rm -f \"$before\" \"$after\" \"$stdout_log\" \"$stderr_log\" \"$new_sessions_file\"' EXIT\ncomm -13 \"$before\" \"$after\" > \"$new_sessions_file\" || true\n\nif [[ ! -s \"$new_sessions_file\" ]]; then\n echo \"No new session rollout file under $SESSIONS_ROOT\" >&2\n tail -n 40 \"$stderr_log\" >&2 || true\n exit 6\nfi\n\n# Extract the image from the new session rollout(s). Extraction logic lives\n# in a separate Python module; see scripts/extract_image.py for details.\nset +e\npython3 \"$SCRIPT_DIR/extract_image.py\" \"$OUT\" \"$new_sessions_file\"\npy_rc=$?\nset -e\n\nif [[ $py_rc -ne 0 ]]; then\n echo \"Image payload not found in any new session file\" >&2\n echo \"(imagegen likely did not run; stderr tail:)\" >&2\n tail -n 30 \"$stderr_log\" >&2 || true\n exit 7\nfi\n","content_type":"application/x-sh; charset=utf-8","language":"bash","size":4666,"content_sha256":"17de0964038fe2dd34f4f5724853ff92de54ca52dfdd569088122e7816f20e78"}],"content_json":{"type":"doc","content":[{"type":"heading","attrs":{"level":1},"content":[{"text":"🪞 GPT Image 2 — Image Generation via Your ChatGPT Subscription","type":"text"}]},{"type":"paragraph","content":[{"text":"agentspace.so","type":"text","marks":[{"type":"link","attrs":{"href":"https://agentspace.so/?utm_source=skills.sh&utm_medium=skill&utm_campaign=gpt-image-2","title":null}}]},{"text":" · ","type":"text"},{"text":"GitHub","type":"text","marks":[{"type":"link","attrs":{"href":"https://github.com/agentspace-so/agent-skills/tree/main/gpt-image-2","title":null}}]}]},{"type":"paragraph","content":[{"text":"Generate images with ","type":"text"},{"text":"GPT Image 2","type":"text","marks":[{"type":"strong"}]},{"text":" (ChatGPT Images 2.0) inside your agent, using your existing ChatGPT Plus or Pro subscription — ","type":"text"},{"text":"no separate OpenAI access, no Fal or Replicate tokens, no per-image billing.","type":"text","marks":[{"type":"strong"}]}]},{"type":"paragraph","content":[{"text":"Text-to-image, image-to-image editing, style transfer, and multi-reference composition. Runs entirely through the local ","type":"text"},{"text":"codex","type":"text","marks":[{"type":"code_inline"}]},{"text":" CLI you're already logged into.","type":"text"}]},{"type":"blockquote","content":[{"type":"paragraph","content":[{"text":"Heads up — this skill requires a ChatGPT Plus or Pro subscription ","type":"text","marks":[{"type":"strong"}]},{"text":"plus","type":"text","marks":[{"type":"strong"},{"type":"em"}]},{"text":" the Codex CLI installed locally.","type":"text","marks":[{"type":"strong"}]},{"text":" If you have neither, you can use GPT Image 2 in the browser via RunComfy instead — hosted, no ChatGPT subscription or local install needed (RunComfy account required):","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Text-to-image:","type":"text","marks":[{"type":"strong"}]},{"text":" ","type":"text"},{"text":"runcomfy.com/models/openai/gpt-image-2/text-to-image","type":"text","marks":[{"type":"link","attrs":{"href":"https://www.runcomfy.com/models/openai/gpt-image-2/text-to-image","title":null}}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Image edit (i2i):","type":"text","marks":[{"type":"strong"}]},{"text":" ","type":"text"},{"text":"runcomfy.com/models/openai/gpt-image-2/edit","type":"text","marks":[{"type":"link","attrs":{"href":"https://www.runcomfy.com/models/openai/gpt-image-2/edit","title":null}}]}]}]}]},{"type":"paragraph","content":[{"text":"The rest of this document covers the local Codex CLI flow for agents whose user has a ChatGPT subscription.","type":"text"}]}]},{"type":"paragraph","content":[{"type":"image","attrs":{"alt":"GPT Image 2 example — flat-color lobster repainted as a 1950s ukiyo-e woodblock print","src":"https://raw.githubusercontent.com/agentspace-so/agent-skills/main/gpt-image-2/gallery/d-ukiyoe.png","title":null,"source":null,"layoutClass":null}}]},{"type":"paragraph","content":[{"text":"Example output: a plain flat-color icon repainted via ","type":"text","marks":[{"type":"em"}]},{"text":"--ref","type":"text","marks":[{"type":"code_inline"},{"type":"em"}]},{"text":" in ukiyo-e style — composition preserved, rendering swapped, period-appropriate red seal added by the model unprompted.","type":"text","marks":[{"type":"em"}]}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"When to trigger","type":"text"}]},{"type":"paragraph","content":[{"text":"Trigger when the user explicitly asks for GPT Image 2 via their ChatGPT subscription, for example:","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"\"use GPT Image 2\" / \"use gpt-image-2\" / \"use ChatGPT Images 2.0\"","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"\"use Image 2\" / \"image 2 this\"","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"attached a reference image and asked to remix / edit / restyle it","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"Do ","type":"text"},{"text":"not","type":"text","marks":[{"type":"strong"}]},{"text":" auto-trigger for a plain \"generate an image\" request if the user didn't specify this route. If they did specify it, do not silently fall back to HTML mockups, screenshots, or a different image model.","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"How to invoke","type":"text"}]},{"type":"paragraph","content":[{"text":"A single bash script handles everything: runs ","type":"text"},{"text":"codex exec","type":"text","marks":[{"type":"code_inline"}]},{"text":" with the right flags, then decodes the generated image from the persisted session rollout.","type":"text"}]},{"type":"paragraph","content":[{"text":"Text-to-image:","type":"text","marks":[{"type":"strong"}]}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"bash scripts/gen.sh \\\n --prompt \"\u003cuser's raw prompt>\" \\\n --out \u003cabsolute/path/to/output.png>","type":"text"}]},{"type":"paragraph","content":[{"text":"Image-to-image","type":"text","marks":[{"type":"strong"}]},{"text":" (reference flag is repeatable for multi-reference composition):","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"bash scripts/gen.sh \\\n --prompt \"\u003cuser's raw prompt, e.g. 'repaint in watercolor'>\" \\\n --ref /absolute/path/to/reference.png \\\n --out \u003cabsolute/path/to/output.png>","type":"text"}]},{"type":"paragraph","content":[{"text":"Optional: ","type":"text"},{"text":"--timeout-sec 300","type":"text","marks":[{"type":"code_inline"}]},{"text":" (default 300).","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Default behavior","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Pass the user's prompt through raw.","type":"text","marks":[{"type":"strong"}]},{"text":" Do not translate, polish, or add style modifiers unless the user asked for it.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Choose the output path.","type":"text","marks":[{"type":"strong"}]},{"text":" Default to ","type":"text"},{"text":"./image-\u003cYYYYMMDD-HHMMSS>.png","type":"text","marks":[{"type":"code_inline"}]},{"text":" in the current working directory if the user didn't specify.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Deliver the image.","type":"text","marks":[{"type":"strong"}]},{"text":" After the script succeeds, display / attach the output file. Do not stop at \"done, see path X\".","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Text-heavy layouts are fine.","type":"text","marks":[{"type":"strong"}]},{"text":" Image 2 handles infographics and timeline prompts well. Do not preemptively warn just because a prompt has a lot of text.","type":"text"}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Hard constraints","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Do not switch routes without permission. If the user said \"use GPT Image 2\", do not substitute DALL·E, Midjourney, an HTML mockup, or a manual screenshot workflow.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Do not rewrite the prompt unless asked.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Do not imply this skill works without a local ","type":"text"},{"text":"codex","type":"text","marks":[{"type":"code_inline"}]},{"text":" login and a valid ChatGPT subscription with image-generation entitlement.","type":"text"}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Prerequisites","type":"text"}]},{"type":"ordered_list","attrs":{"order":1,"listStyle":"number"},"content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"codex","type":"text","marks":[{"type":"code_inline"}]},{"text":" CLI installed — ","type":"text"},{"text":"brew install codex","type":"text","marks":[{"type":"code_inline"}]},{"text":" or see ","type":"text"},{"text":"openai/codex","type":"text","marks":[{"type":"link","attrs":{"href":"https://github.com/openai/codex","title":null}}]},{"text":".","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Logged in with a ChatGPT plan that includes Image 2 — ","type":"text"},{"text":"codex login","type":"text","marks":[{"type":"code_inline"}]},{"text":".","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"python3","type":"text","marks":[{"type":"code_inline"}]},{"text":" on PATH (ships with macOS; ","type":"text"},{"text":"apt install python3","type":"text","marks":[{"type":"code_inline"}]},{"text":" on Linux).","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"This skill does ","type":"text"},{"text":"not","type":"text","marks":[{"type":"strong"}]},{"text":" grant image-generation capability on its own. It exposes the capability the user already has through their ChatGPT subscription.","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Exit codes","type":"text"}]},{"type":"table","attrs":{"layout":null},"content":[{"type":"tr","content":[{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"code","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"meaning","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"0","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"success — output path printed on stdout","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"2","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"bad args","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"3","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"codex","type":"text","marks":[{"type":"code_inline"}]},{"text":" or ","type":"text"},{"text":"python3","type":"text","marks":[{"type":"code_inline"}]},{"text":" CLI missing","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"4","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"--ref","type":"text","marks":[{"type":"code_inline"}]},{"text":" file does not exist","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"5","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"codex exec","type":"text","marks":[{"type":"code_inline"}]},{"text":" failed (auth? network? model?)","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"6","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"no new session file detected","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"7","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"imagegen did not produce an image payload (feature not enabled, quota, or capability refused)","type":"text"}]}]}]}]},{"type":"paragraph","content":[{"text":"On failure, name the layer in one sentence instead of dumping the full stderr at the user.","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"How it works","type":"text"}]},{"type":"paragraph","content":[{"text":"The ","type":"text"},{"text":"codex","type":"text","marks":[{"type":"code_inline"}]},{"text":" CLI reuses the logged-in ChatGPT session and exposes an ","type":"text"},{"text":"imagegen","type":"text","marks":[{"type":"code_inline"}]},{"text":" tool (gated behind the ","type":"text"},{"text":"image_generation","type":"text","marks":[{"type":"code_inline"}]},{"text":" feature flag). The script:","type":"text"}]},{"type":"ordered_list","attrs":{"order":1,"listStyle":"number"},"content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"snapshots ","type":"text"},{"text":"~/.codex/sessions/","type":"text","marks":[{"type":"code_inline"}]},{"text":" before the run","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"runs ","type":"text"},{"text":"codex exec --enable image_generation --sandbox read-only ...","type":"text","marks":[{"type":"code_inline"}]},{"text":" (with ","type":"text"},{"text":"-i \u003cfile>","type":"text","marks":[{"type":"code_inline"}]},{"text":" for each reference image)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"diffs the sessions directory, then invokes ","type":"text"},{"text":"scripts/extract_image.py","type":"text","marks":[{"type":"code_inline"}]},{"text":" to scan every new rollout JSONL for a base64 image payload (PNG / JPEG / WebP magic-header match)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"decodes the largest matching blob and writes it to ","type":"text"},{"text":"--out","type":"text","marks":[{"type":"code_inline"}]}]}]}]},{"type":"paragraph","content":[{"text":"Two non-obvious flags other wrappers get wrong on codex-cli 0.111.0+:","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"--enable image_generation","type":"text","marks":[{"type":"code_inline"}]},{"text":" is ","type":"text"},{"text":"required","type":"text","marks":[{"type":"strong"}]},{"text":"; the feature is still under-development and off by default.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"--ephemeral","type":"text","marks":[{"type":"code_inline"}]},{"text":" ","type":"text"},{"text":"must not","type":"text","marks":[{"type":"strong"}]},{"text":" be used — ephemeral sessions aren't persisted, so the image payload has nowhere to live.","type":"text"}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Data handling","type":"text"}]},{"type":"paragraph","content":[{"text":"The script is narrowly scoped on purpose:","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"It reads ","type":"text"},{"text":"only","type":"text","marks":[{"type":"strong"}]},{"text":" session rollout files created by its own ","type":"text"},{"text":"codex exec","type":"text","marks":[{"type":"code_inline"}]},{"text":" invocation. The sessions directory is snapshotted before the call and diffed after, so any prior ","type":"text"},{"text":"~/.codex/sessions/*","type":"text","marks":[{"type":"code_inline"}]},{"text":" files (which may contain unrelated Codex conversations) are never touched, read, or transmitted.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"It writes only two kinds of file: the output PNG at the caller's ","type":"text"},{"text":"--out","type":"text","marks":[{"type":"code_inline"}]},{"text":" path, and short-lived ","type":"text"},{"text":"mktemp","type":"text","marks":[{"type":"code_inline"}]},{"text":" logs that are auto-deleted on exit via a trap.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"No environment variables are read. No credentials are requested. No other paths under ","type":"text"},{"text":"~/.codex/","type":"text","marks":[{"type":"code_inline"}]},{"text":" are accessed.","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"No network calls leave this skill. The only outbound traffic is the one made by the ","type":"text"},{"text":"codex","type":"text","marks":[{"type":"code_inline"}]},{"text":" CLI itself (to OpenAI, using the user's existing ChatGPT login) — this skill does not add endpoints, telemetry, or callbacks.","type":"text"}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"What this skill is not","type":"text"}]},{"type":"paragraph","content":[{"text":"Not a direct OpenAI API client. Not a capability grant — it depends on the user's working Codex CLI login. Not a multi-tenant service (one call per invocation; concurrent calls are serialized by the filesystem-snapshot diff).","type":"text"}]}]},"metadata":{"date":"2026-11-02","name":"gpt-image-2","emoji":"🪞","author":"@skillopedia","source":{"stars":17,"repo_name":"agent-skills","origin_url":"https://github.com/agentspace-so/agent-skills/blob/HEAD/gpt-image-2/SKILL.md","repo_owner":"agentspace-so","body_sha256":"8cfdf901253aa93c680b705af7eaba6611c3b65d2f4a433fc53277e05833cedf","cluster_key":"b26693c5703549a171a14039dd0289f0e939f7a1c1f464f3b2a059bf5d49f3b8","clean_bundle":{"format":"clean-skill-bundle-v1","source":"agentspace-so/agent-skills/gpt-image-2/SKILL.md","text_bytes":8288,"source_commit":"18d61002379d024d8754318171479968c68ff6c4","skills_sh_rank":16479,"attachment_count":2,"text_attachments":2,"attachment_storage":"skill_attachments","binary_attachments":0},"cluster_size":1,"skill_md_path":"gpt-image-2/SKILL.md","import_metadata":{"date":"2026-11-02","author":"@skillopedia","version":"v1","category":"media-content","category_label":"Media"},"exact_dupes_collapsed_into_this":0},"license":"MIT","version":"v1","category":"media-content","homepage":"https://agentspace.so","import_tag":"skills-sh-top20k-2026-11","description":"Generate images with GPT Image 2 (ChatGPT Images 2.0) inside Claude Code, using your existing ChatGPT Plus or Pro subscription — no separate OpenAI access, no per-image billing. Supports text-to-image, image-to-image editing, style transfer, and multi-reference composition via the local Codex CLI. Triggers on \"gpt image 2\", \"gpt-image-2\", \"ChatGPT Images 2.0\", \"image 2\", or any explicit ask to generate or edit an image through the user's ChatGPT plan.\n","displayName":"🪞 GPT Image 2 — Image Generation via Your ChatGPT Subscription"}},"renderedAt":1793671758458}

🪞 GPT Image 2 — Image Generation via Your ChatGPT Subscription agentspace.so · GitHub Generate images with GPT Image 2 (ChatGPT Images 2.0) inside your agent, using your existing ChatGPT Plus or Pro subscription — no separate OpenAI access, no Fal or Replicate tokens, no per-image billing. Text-to-image, image-to-image editing, style transfer, and multi-reference composition. Runs entirely through the local CLI you're already logged into. Heads up — this skill requires a ChatGPT Plus or Pro subscription plus the Codex CLI installed locally. If you have neither, you can use GPT Image 2 in the…