微算力 · API 导航与自营网关
API 接入 EN
未登录登录
🪞

用 ChatGPT 订阅本地生图,零 API 成本

🪞 GPT Image 2 — Image Generation via Your ChatGPT Subscription · v1.0.5
专业技能 安全 A 级 作者 kalvinrv 公开目录收录
4.6k 下载 5 安装 11.5k 收藏 324 浏览

简介

将 ChatGPT Plus/Pro 的 GPT Image 2 能力接入 Claude Code,支持文生图、图生图编辑及风格迁移,无需额外 API 密钥,依赖本地 Codex CLI 运行。

原始描述

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, n...

通过你的 Agent 添加

安装目录:gpt-image-2/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。

点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。

或者手动安装

Claude Code~/.claude/skills/gpt-image-2-image-generation-via-your-chatgpt-subscription/
Codex CLI~/.codex/skills/gpt-image-2-image-generation-via-your-chatgpt-subscription/
DeepSeek Harness~/.agents/skills/gpt-image-2-image-generation-via-your-chatgpt-subscription/

包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可; 目录名不用换,也不要把包直接解压到 skills 根目录。 技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。

中文使用说明 来自收录源

核心用法

gpt-image-2 是一个桥接型 Skill,允许用户在 Claude Code 环境中通过本地 Codex CLI 调用 ChatGPT Plus/Pro 订阅内置的 GPT Image 2(ChatGPT Images 2.0)图像生成功能。用户无需单独申请 OpenAI API Key、无需按量计费、无需第三方推理服务(如 Fal/Replicate)的 Token。

触发条件:用户明确提及 "gpt image 2"、"gpt-image-2"、"ChatGPT Images 2.0"、"image 2" 或明确要求通过 ChatGPT 订阅生成/编辑图片时触发。Skill 不会自动介入普通的 "generate an image" 请求。

调用方式:

  • 文生图:bash scripts/gen.sh --prompt "..." --out /path/to/output.png
  • 图生图/风格迁移:bash scripts/gen.sh --prompt "..." --ref /path/to/ref.png --out /path/to/output.png
  • 支持多参考图组合(--ref 可重复)

技术原理:脚本先快照 ~/.codex/sessions/ 目录,执行 codex exec --enable image_generation --sandbox read-only(必须启用该功能标志,且禁用 --ephemeral 以便持久化会话),然后通过差异比对定位新生成的 rollout JSONL,由 Python 脚本提取 base64 编码的最大图像 blob 并解码保存。

显著优点

  1. 零额外成本:直接复用现有的 ChatGPT Plus/Pro 订阅,无按图像计费、无 API 账单
  2. 本地执行:所有操作通过用户本地已登录的 Codex CLI 完成,无外部服务托管风险
  3. 功能完整:支持文本生成图像、图像编辑(inpainting/outpainting)、风格迁移、多参考图合成
  4. 文本渲染优秀:Image 2 在信息图、时间轴等含大量文字的布局上表现良好
  5. 数据隔离:通过目录快照机制确保仅读取本次调用产生的会话数据,不触碰历史记录

潜在缺点与局限性

  1. 硬性依赖门槛:必须同时具备 (a) ChatGPT Plus/Pro 订阅且含图像生成权益;(b) 本地安装并登录 Codex CLI。两者缺一不可
  2. 功能标志限制:--enable image_generation 处于开发阶段,可能不稳定或被调整
  3. 单租户序列化:并发调用会被文件系统快照机制序列化,不适合高并发场景
  4. 无直接 API 兜底:若用户无 ChatGPT 订阅,需改用 RunComfy 等托管方案(文档已提供链接),无法通过本 Skill 降级处理
  5. 平台限制:Codex CLI 主要支持 macOS(Homebrew)和 Linux,Windows 支持有限

适合人群

  • 已有 ChatGPT Plus/Pro 订阅的开发者/创作者,希望在不增加开支的前提下将图像生成整合到 Claude Code 工作流
  • 需要频繁进行图生图编辑(风格迁移、局部重绘)且偏好本地执行的用户
  • 对数据隐私敏感,希望图像生成过程完全在本地环境完成、不经过第三方托管服务的团队
  • 制作信息图、时间轴、含文字布局等 Image 2 擅长领域的用户

常规风险

  • 订阅失效风险:ChatGPT 订阅过期或图像生成功能被调整时,Skill 将返回 exit code 7(无图像负载)
  • 功能标志变更:OpenAI 可能调整 image_generation 功能的可用性或参数要求
  • 路径遍历风险:已通过 FORBIDDEN_OUTPUT_PREFIXES 白名单机制缓解(安全认证确认)
  • 依赖项风险:Codex CLI 版本更新可能引入不兼容变更,需保持更新
  • 无运行时沙箱:虽然调用时使用 --sandbox read-only,但 Skill 本身以用户权限运行,需信任来源(已通过 T2 级可信组织认证)

技能正文


name: gpt-image-2 displayName: "🪞 GPT Image 2 — Image Generation via Your ChatGPT Subscription" 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. emoji: "🪞" homepage: https://agentspace.so license: MIT clawdis: requires: bins: - codex - python3 config: - ~/.codex/sessions

🪞 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 codex 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 browser via RunComfy instead — hosted, no ChatGPT subscription or local install needed (RunComfy account required):

The rest of this document covers the local Codex CLI flow for agents whose user has a ChatGPT subscription.

GPT Image 2 example — flat-color lobster repainted as a 1950s ukiyo-e woodblock print

Example output: a plain flat-color icon repainted via --ref in ukiyo-e style — composition preserved, rendering swapped, period-appropriate red seal added by the model unprompted.

When to trigger

Trigger when the user explicitly asks for GPT Image 2 via their ChatGPT subscription, for example:

  • "use GPT Image 2" / "use gpt-image-2" / "use ChatGPT Images 2.0"
  • "use Image 2" / "image 2 this"
  • attached a reference image and asked to remix / edit / restyle it

Do not 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.

How to invoke

A single bash script handles everything: runs codex exec with the right flags, then decodes the generated image from the persisted session rollout.

Text-to-image:

bash scripts/gen.sh \
  --prompt "<user's raw prompt>" \
  --out <absolute/path/to/output.png>

Image-to-image (reference flag is repeatable for multi-reference composition):

bash scripts/gen.sh \
  --prompt "<user's raw prompt, e.g. 'repaint in watercolor'>" \
  --ref /absolute/path/to/reference.png \
  --out <absolute/path/to/output.png>

Optional: --timeout-sec 300 (default 300).

Default behavior

  • Pass the user's prompt through raw. Do not translate, polish, or add style modifiers unless the user asked for it.
  • Choose the output path. Default to ./image-<YYYYMMDD-HHMMSS>.png in the current working directory if the user didn't specify.
  • Deliver the image. After the script succeeds, display / attach the output file. Do not stop at "done, see path X".
  • Text-heavy layouts are fine. Image 2 handles infographics and timeline prompts well. Do not preemptively warn just because a prompt has a lot of text.

Hard constraints

  • 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.
  • Do not rewrite the prompt unless asked.
  • Do not imply this skill works without a local codex login and a valid ChatGPT subscription with image-generation entitlement.

Prerequisites

  1. codex CLI installed — brew install codex or see openai/codex.
  2. Logged in with a ChatGPT plan that includes Image 2 — codex login.
  3. python3 on PATH (ships with macOS; apt install python3 on Linux).

This skill does not grant image-generation capability on its own. It exposes the capability the user already has through their ChatGPT subscription.

Exit codes

code meaning
0 success — output path printed on stdout
2 bad args
3 codex or python3 CLI missing
4 --ref file does not exist
5 codex exec failed (auth? network? model?)
6 no new session file detected
7 imagegen did not produce an image payload (feature not enabled, quota, or capability refused)

On failure, name the layer in one sentence instead of dumping the full stderr at the user.

How it works

The codex CLI reuses the logged-in ChatGPT session and exposes an imagegen tool (gated behind the image_generation feature flag). The script:

  1. snapshots ~/.codex/sessions/ before the run
  2. runs codex exec --enable image_generation --sandbox read-only ... (with -i <file> for each reference image)
  3. diffs the sessions directory, then invokes scripts/extract_image.py to scan every new rollout JSONL for a base64 image payload (PNG / JPEG / WebP magic-header match)
  4. decodes the largest matching blob and writes it to --out

Two non-obvious flags other wrappers get wrong on codex-cli 0.111.0+:

  • --enable image_generation is required; the feature is still under-development and off by default.
  • --ephemeral must not be used — ephemeral sessions aren't persisted, so the image payload has nowhere to live.

Data handling

The script is narrowly scoped on purpose:

  • It reads only session rollout files created by its own codex exec invocation. The sessions directory is snapshotted before the call and diffed after, so any prior ~/.codex/sessions/* files (which may contain unrelated Codex conversations) are never touched, read, or transmitted.
  • It writes only two kinds of file: the output PNG at the caller's --out path, and short-lived mktemp logs that are auto-deleted on exit via a trap.
  • No environment variables are read. No credentials are requested. No other paths under ~/.codex/ are accessed.
  • No network calls leave this skill. The only outbound traffic is the one made by the codex CLI itself (to OpenAI, using the user's existing ChatGPT login) — this skill does not add endpoints, telemetry, or callbacks.

What this skill is not

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).

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

标签

image-generationchatgptgpt-image-2codex-clilocal-executionstyle-transferimage-editing

同类 Skill