Skip to content

feat: add Codex CLI image generation bridge for non-Codex agents - #6

Closed
tznthou wants to merge 3 commits into
0x0funky:mainfrom
tznthou:feat/codex-imagegen-bridge
Closed

feat: add Codex CLI image generation bridge for non-Codex agents#6
tznthou wants to merge 3 commits into
0x0funky:mainfrom
tznthou:feat/codex-imagegen-bridge

Conversation

@tznthou

@tznthou tznthou commented Jun 30, 2026

Copy link
Copy Markdown

Closes #7

What

Adds scripts/call-codex-imagegen.sh — a shell bridge that lets non-Codex agents (Claude Code, Cursor, etc.) call Codex CLI's built-in image_gen to generate images, then hand off to the existing postprocess scripts unchanged.

Why

The skills currently require Codex's built-in image_gen, making them Codex-only. This bridge takes a different approach from #2: instead of calling the OpenAI/Gemini API directly from Python, it wraps Codex CLI itself as the image generation backend. This means:

  • Same model, same output — built-in image_gen uses gpt-image-2, so generated images are identical to native Codex runs. No prompt adjustments needed.
  • No new SDK dependencies — requires only Codex CLI (npm i -g @openai/codex), no openai or google-genai Python packages.
  • Existing scripts untouchedgenerate2dsprite.py, extract_prop_pack.py, and compose_layered_preview.py work as-is.

This is complementary to #2, not a replacement — #2 covers the "no Codex CLI" scenario (pure API), while this covers the "has Codex CLI but orchestrating from another agent" scenario.

How

Any AI agent / CLI
  │
  │  call-codex-imagegen.sh -o output.png --bg "#FF00FF" "art prompt"
  │
  ├─ Builds meta-prompt → codex exec --sandbox workspace-write
  │                         └─ image_gen (gpt-image-2)
  │                         └─ Saves PNG + prints IMAGE_PATH: marker
  │
  ├─ 4-layer fallback path extraction
  │   (marker → regex → output check → find in $CODEX_HOME)
  │
  └─ stdout: absolute path of generated image

Features

  • -i <file> reference image support (passes through to codex exec -i)
  • -o <path> output path with auto mkdir -p
  • --size, --quality, --bg options
  • Soft timeout with heartbeat logging (default 300s)
  • Structured error classification (TIMEOUT / RATE_LIMIT / AUTH_ERROR / NETWORK / SANDBOX)
  • --dry-run for prompt inspection without API calls
  • Observability via log file (tag: [codex-imagegen])

Verified

End-to-end pipeline tested on macOS (Codex CLI 0.142.3):

  1. call-codex-imagegen.sh → gpt-image-2 generates 2×2 pixel art idle sprite (1024×1024, #FF00FF background)
  2. generate2dsprite.py process --rows 2 --cols 2 --shared-scale --component-mode largest → chroma-key → frame extraction → QC
  3. Result: 4 clean frames (92×108), transparent sheet, animated GIF, edge_touch_frames: []

Pipeline output

Step 1 — Raw gpt-image-2 output (via call-codex-imagegen.sh):

Raw gpt-image-2 output

Step 2 — Chroma-keyed transparent sheet (via generate2dsprite.py process):

Transparent sprite sheet

Step 3 — Animated GIF:

Animation GIF

Map pipeline output (generate2dmap)

Also verified with the map pipeline — base map generation, 3×3 prop pack extraction (9/9 accepted, 0 rejected, 0 edge touch), and layered preview composition:

Foundation-only base 3×3 prop pack (raw) Layered preview

Relation to existing issues

Backwards compatibility

  • requirements.txt unchanged.
  • No changes to generate2dsprite.py, extract_prop_pack.py, compose_layered_preview.py, or either SKILL.md.
  • Existing Codex workflows are unaffected — the bridge script is additive.
  • .gitignore additions (.venv/, test-output/, .claude/) are for development only.

tznthou added 3 commits June 30, 2026 14:45
Bridge script that calls Codex CLI's built-in image_gen (gpt-image-2)
from any AI agent or CLI. Enables Claude Code and other non-Codex
agents to use the same image generation pipeline.

Features:
- Reference image support (-i) for style matching
- Output path control (-o) with auto directory creation
- Size, quality, and background color options
- 4-layer fallback for generated image path extraction
- Soft timeout with heartbeat logging
- Structured error classification
- Full observability via multi-ai.log

Verified end-to-end: image gen → chroma-key → frame split → QC → GIF
using the existing generate2dsprite.py process pipeline.
Raw gpt-image-2 output, chroma-keyed transparent sheet, and animated
GIF from the end-to-end call-codex-imagegen.sh pipeline test.
Foundation-only base map, 3x3 prop pack (raw + extracted), and
layered preview from the end-to-end generate2dmap pipeline test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support non-Codex agents via Codex CLI bridge (Claude Code, Cursor, etc.)

1 participant