A small tool for macOS
ChatGPT Image CLI
Generate images from your terminal. Use the ChatGPT session already open in Safari and save the result straight to your Mac.
Get started
From prompt to PNG.
Run this in Terminal. The installer downloads the source, builds it on your Mac, and installs the command in ~/.local/bin.
curl -fsSL https://wezen.tech/downloads/chatgpt-image-installer.sh | bash Prefer to inspect it first? Download the installer.
Before your first image
- Open Safari and sign in to ChatGPT.
- In Safari Settings → Advanced, enable Show features for web developers. Then in Developer, enable Allow JavaScript from Apple Events.
- Run a prompt below. Allow Terminal to control Safari when macOS asks.
~/.local/bin/chatgpt-image --prompt "A tiny robot tending a rooftop garden" --output ~/Desktop/robot.png Your image is saved as robot.png on your Desktop. The temporary chat is archived after a successful save.
Behind the tool
A shorter path to your next image.
Built to keep small image tasks close to the rest of the work: send a prompt, save a PNG, and keep going. Add a reference image when you want a variation.
Use --reference-image /path/to/image.png with your prompt, or run ~/.local/bin/chatgpt-image --help to see all options.
How it’s built
Design decisions
- Kept the CLI in Swift to match the repo rule that tools should be written in Swift when possible.
- Used Safari plus AppleScript instead of a separate browser profile so the tool could reuse the same signed-in ChatGPT subscription already active on the machine.
- Archived the temporary conversation after a successful save and added reference-image support so the tool stays useful beyond one-off prompts.
Engineering challenges
- Driving a modern web app from Swift while still using the real Safari session that already holds the authenticated ChatGPT account.
- Picking the generated image reliably when the conversation may also contain uploaded reference images and overlay variants.
- Cleaning up after each run so the tool does not leave a trail of throwaway chats in the sidebar.