How to Automate Instagram Posting from the Terminal with AI Agents

You already live in the terminal. Your code editor, your git workflow, your deployment pipeline, it's all right there. But the moment you need to post something on Instagram, you're dragged into a browser, a scheduling tool, or Canva. That context switch kills your flow.
What if you could generate an image with AI, write a caption, and publish it to Instagram without ever leaving the command line?
That's exactly what we'll build in this tutorial. By the end, you'll have a repeatable workflow: five commands that take you from idea to published Instagram post.
Key Takeaways
- A scriptable Instagram workflow removes the tab-switching that slows down consistent publishing.
- The Wonda CLI lets you generate images, write captions, and publish to Instagram from a single terminal session.
- Once auth and prompts are set up, the generation-to-publish loop can run in just a few minutes.
What Does a CLI-First Instagram Workflow Look Like?
The advantage of a terminal-based workflow is not that it magically makes Instagram easy. It is that it removes the operational friction: generate, review, publish, done. That matters when you are posting repeatedly, testing different visuals, or turning content production into something you can actually script.
Here's the full flow in five steps:
- Install Wonda: one curl command
- Authenticate: connect your Instagram Business account
- Generate an image: pick an AI model, write a prompt
- Write a caption: use AI text generation or write your own
- Publish: push to Instagram with one command
Each step produces an output that feeds into the next. No file juggling, no drag-and-drop uploading. Let's walk through it.
How Do You Install Wonda?
Getting started takes about 30 seconds. Wonda ships as a single binary with no runtime dependencies, no Docker, no node_modules.
macOS and Linux
curl -fsSL https://wonda.sh/install.sh | bashHomebrew
brew tap degausai/tap && brew install wondanpx
npx @degausai/wonda --helpVerify the installation:
wonda --versionYou should see a version number printed to stdout. If you're running this inside Claude Code or Cursor's terminal, it works identically. Wonda doesn't care about your shell environment.
How Do You Connect Your Instagram Account?
Before publishing, you need to link your Instagram Business or Creator account. Wonda uses Meta's official Instagram Graph API, the same one Buffer, Hootsuite, and Later use under the hood.
First, log in to Wonda:
wonda auth loginThis opens a browser window for authentication. Once logged in, connect your Instagram account:
wonda accounts instagramThis lists your connected Instagram accounts with their account IDs. You'll need the account ID for publishing later, so note it down. If you haven't connected an Instagram account yet, head to wonda.sh and link one in your dashboard settings.
Quick sanity check: pull your recent analytics to make sure everything's wired up:
wonda analytics instagramYou should see your recent post performance, reach, and engagement metrics. If that works, you're ready to create content.
How Do You Generate an Image with AI?
This is where it gets fun. Wonda gives you access to 25+ AI models for image generation, but for most Instagram content, the default model, NanoBanana 2, produces excellent results.
Why this matters: Most social media tools treat AI image generation and publishing as separate products. Wonda chains them together in a single pipeline, so the output of one command feeds directly into the next.
Generate a single image
wonda generate image \
--model nano-banana-2 \
--prompt "minimalist flat lay of a coffee cup and laptop on a marble desk, morning light, soft shadows" \
--aspect-ratio 1:1 \
--wait \
-o product-shot.pngLet's break down the flags:
--model nano-banana-2is the default image model. Fast, high quality, and cost-effective.--promptdescribes what you want. Be specific about composition, lighting, and mood.--aspect-ratio 1:1sets square for Instagram feed posts. Use9:16for Stories and Reels.--waitblocks until the image is ready (typically 30 seconds to 2 minutes).-o product-shot.pngdownloads the result to a local file.
Generate a carousel series
Carousels are one of the most useful formats to automate because the asset structure is repeatable: multiple square images, one caption, one publish action. You can generate the slides one by one and publish them as a single carousel:
# Generate three variations for a carousel
wonda generate image --model nano-banana-2 \
--prompt "minimalist coffee flat lay, morning light, marble desk" \
--aspect-ratio 1:1 --wait -o slide-1.png
wonda generate image --model nano-banana-2 \
--prompt "overhead shot of an open notebook next to coffee, natural light" \
--aspect-ratio 1:1 --wait -o slide-2.png
wonda generate image --model nano-banana-2 \
--prompt "close-up of latte art in a ceramic cup, warm tones" \
--aspect-ratio 1:1 --wait -o slide-3.pngEdit an existing image
Already have a product photo? Use image-to-image editing:
MEDIA=$(wonda media upload ./my-product.jpg --quiet)
wonda generate image --model nano-banana-2 \
--prompt "change the background to a clean white studio" \
--attach $MEDIA --aspect-ratio auto --wait -o edited.pngThe --aspect-ratio auto flag preserves the original dimensions. The --attach flag tells the model to use your image as a reference.
Remove a background
Need a cutout for a graphic? There's a dedicated model for that:
MEDIA=$(wonda media upload ./product.jpg --quiet)
wonda generate image --model birefnet-bg-removal \
--attach $MEDIA --wait -o no-bg.pngHow long does this take? Image generation runs between 30 seconds and 2 minutes depending on the model and queue. Plan for about a minute per image.
How Do You Write a Caption with AI?
Wonda's text generation can draft your caption:
wonda generate text \
--model <model> \
--prompt "Write a short, engaging Instagram caption for a minimalist coffee flat lay photo. Include a call to action. Keep it under 150 words. Add 5 relevant hashtags." \
--waitThe output prints to stdout. You can pipe it, save it to a file, or just copy the text you like.
If you want to inspect the available text models in your account first, run wonda models list.
Of course, you don't have to use AI for captions. If you already know what you want to say, skip this step and write the caption directly in the publish command.
From our team: We've found that AI-generated captions work best as drafts. Let the model handle the hashtag research and structure, then tweak the voice to match your brand. It's faster than starting from scratch, but the human touch still matters.
How Do You Publish to Instagram from the Terminal?
This is the payoff. You've got your image and your caption. Time to ship it.
Upload your image
First, upload the generated image to Wonda's media library:
MEDIA_ID=$(wonda media upload ./product-shot.png --quiet)
echo $MEDIA_IDThe --quiet flag outputs only the media ID, no extra formatting. That makes it easy to capture in a variable for the next command.
Publish a single image post
wonda publish instagram \
--media $MEDIA_ID \
--account <your-account-id> \
--caption "Morning rituals. ☕ What's the first thing you reach for?
#morningroutine #coffeelovers #minimalist #flatlay #contentcreator" \
--alt-text "Minimalist flat lay of a coffee cup and laptop on a marble desk" \
--product IMAGE \
--share-to-feedThat is the full publish path. Once the account is connected and the prompt is stable, the whole loop can run very quickly.
Publish a carousel
Got those three carousel images from earlier? Upload them all, then publish as a carousel:
SLIDE1=$(wonda media upload ./slide-1.png --quiet)
SLIDE2=$(wonda media upload ./slide-2.png --quiet)
SLIDE3=$(wonda media upload ./slide-3.png --quiet)
wonda publish instagram-carousel \
--media $SLIDE1,$SLIDE2,$SLIDE3 \
--account <your-account-id> \
--caption "Three ways to start your morning right. Swipe through 👉
Which one is your vibe?
#morningroutine #coffeelovers #carousel #contentcreator #minimalist"Carousels perform best for engagement on Instagram, so this workflow is worth building into your regular cadence.
Check your publishing history
Want to see what you've already posted?
wonda publish history instagram --limit 10This shows your recent publications with their status and engagement data.
How Do You Build a Full Automation Script?
Here's where CLI-based workflows really shine. Everything we've done so far is composable, meaning you can chain it into a single script.
The real advantage isn't speed; it's repeatability. A GUI workflow dies the moment you close the browser. A terminal workflow is a script you can run on Monday, tweak on Tuesday, and schedule for Wednesday.
Here's a complete end-to-end script:
#!/bin/bash
set -e
ACCOUNT_ID="your-instagram-account-id"
# Step 1: Generate the image
echo "Generating image..."
wonda generate image \
--model nano-banana-2 \
--prompt "minimalist product flat lay, morning light, marble surface" \
--aspect-ratio 1:1 \
--wait -o /tmp/ig-post.png
# Step 2: Upload to media library
echo "Uploading..."
MEDIA_ID=$(wonda media upload /tmp/ig-post.png --quiet)
# Step 3: Generate a caption
echo "Writing caption..."
CAPTION=$(wonda generate text \
--model <model> \
--prompt "Write a short Instagram caption for a minimalist product photo. Under 100 words. Include 5 hashtags." \
--wait --quiet)
# Step 4: Publish
echo "Publishing to Instagram..."
wonda publish instagram \
--media $MEDIA_ID \
--account $ACCOUNT_ID \
--caption "$CAPTION" \
--alt-text "Minimalist product flat lay on marble surface" \
--product IMAGE \
--share-to-feed
echo "Done! Post is live."Save this as post-to-ig.sh, run chmod +x post-to-ig.sh, and you've got a one-command Instagram publisher.
If you're using Claude Code, you can go further: ask Claude to run this script, review the generated image before publishing, and iterate on the prompt if the first result doesn't look right. The AI agent becomes your creative assistant inside the terminal.
For Instagram Reels and video content, you can extend this workflow with AI UGC-style video generation that produces authentic-looking short-form content directly from the terminal.
What About Competitive Research Before Posting?
Smart content starts with context. Before you generate anything, you might want to see what's working in your niche. Wonda has scraping and analytics built in:
# See what a competitor is posting
wonda scrape social --handle @competitor --platform instagram --wait
# Check what ads are running in your space
wonda scrape ads --query "coffee brand" --country US --wait
# Pull your own performance data
wonda analytics instagramIf you are thinking beyond Instagram, the same model shows up in How AI Agents Are Replacing Social Media Managers: the important shift is not just faster asset generation, but moving the whole workflow from dashboards into a command surface.
Frequently Asked Questions
Do I need an Instagram Business account to publish from the CLI?
Yes. Wonda uses Meta's official Instagram Graph API, which requires either a Business or Creator account. Personal accounts can't publish through the API. The switch is free, and you can convert your existing account in Instagram's settings under "Account type and tools."
How much does it cost to generate images and publish?
Wonda offers a free tier that includes media uploads, editing, and social publishing. Image generation with NanoBanana 2 requires a free account. The exact credit cost depends on the model, so run wonda pricing list to see current rates.
Can I schedule posts for later instead of publishing immediately?
The wonda publish instagram command publishes immediately. For scheduled posting, you can wrap the publish command in a cron job or use a task scheduler. The CLI is designed to be scriptable, so any scheduling tool that can run a shell command will work.
Does this work inside Claude Code or Cursor?
Wonda runs anywhere you have a terminal. If you're inside Claude Code, Cursor, Warp, iTerm, or a plain bash session, the commands are identical. AI coding agents can also invoke these commands directly as part of an automated workflow.
Can I publish videos and Reels too?
Yes. Wonda supports video generation with models like Sora 2, and you can publish video content to Instagram the same way. Use wonda generate video for creation and wonda publish instagram with a video media ID for distribution.
What's Next?
You've now got a complete workflow for generating AI images and publishing them to Instagram from the terminal.
The commands we covered work as standalone one-liners or as parts of a larger automation script. If you're building content at scale (multiple brands, daily posts, A/B testing different visuals) this kind of pipeline is what separates a manual workflow from a sustainable one.
To get started:
curl -fsSL https://wonda.sh/install.sh | bash
wonda auth loginIf your next step is short-form video instead of images, pair this with How to Build a TikTok Autopilot Pipeline in 30 Days. If your next step is choosing the right generation model, read The Developer's Guide to AI Video Generation in 2026.