GEMINI LABJP
ROBOTICS — The ER 1.6 preview that shut down on August 31 does have a successor. Gemini Robotics ER 2 is in public preview, in both standard and streaming variantsVIDEO — ER 2 judges success and failure from live video rather than still snapshots, which is what lets it catch spills, slips, and misalignments while a task is still runningDEADLINE — Next up is September 30, when gemini-omni-flash-preview is retired. The target is gemini-omni-1.1-flash, GA since August 27, and there are now under four weeks leftAPIKEY — Every remaining standard API key, restricted ones included, stops working during September. The replacement is an auth key bound to a Google Cloud service accountPRICE — Gemini 3.7 Flash keeps its introductory $0.75/$3.75 per 1M through December 31, then moves to $1.50/$7.50 on January 1, 2027. Any estimate crossing the year needs both figuresAUDIO — Gemini 3.5 Transcribe handles language detection across 85+ languages, speaker diarization, word-level timestamps, and custom vocabulary biasing of up to 1,000 termsROBOTICS — The ER 1.6 preview that shut down on August 31 does have a successor. Gemini Robotics ER 2 is in public preview, in both standard and streaming variantsVIDEO — ER 2 judges success and failure from live video rather than still snapshots, which is what lets it catch spills, slips, and misalignments while a task is still runningDEADLINE — Next up is September 30, when gemini-omni-flash-preview is retired. The target is gemini-omni-1.1-flash, GA since August 27, and there are now under four weeks leftAPIKEY — Every remaining standard API key, restricted ones included, stops working during September. The replacement is an auth key bound to a Google Cloud service accountPRICE — Gemini 3.7 Flash keeps its introductory $0.75/$3.75 per 1M through December 31, then moves to $1.50/$7.50 on January 1, 2027. Any estimate crossing the year needs both figuresAUDIO — Gemini 3.5 Transcribe handles language detection across 85+ languages, speaker diarization, word-level timestamps, and custom vocabulary biasing of up to 1,000 terms
Articles/Dev Tools
Dev Tools/2026-03-11Advanced

Wiring Gemini CLI into Your Shell and CI — Headless Runs and Session Resume

Move past interactive use of Gemini CLI: headless runs, JSON output, session resume, approval modes, and MCP. Includes the five ways headless runs break and a measured pro/flash comparison.

Gemini CLI8headlessMCP4automation52CI7

Premium Article

Type gemini, press enter, and an interactive screen quietly comes to life. Most of you have probably been here already.

What genuinely helped me, though, was realizing I could call Gemini CLI as a single line inside a shell script. Handing my morning skim of build logs across four sites over to gemini -p visibly shrank the time I spent checking them.

This article focuses on Gemini CLI as a tool rather than a chat window: headless execution, JSON output, session resume, approval modes, and MCP integration. We'll walk through the spots that tend to trip people up when they actually embed it into scripts.

Start with the correct install and auth

Gemini CLI is Google's open-source terminal agent, published on npm as @google/gemini-cli. You'll want Node.js 20 or higher — ideally the 22 LTS.

# Global install
npm install -g @google/gemini-cli
 
# Try it once without a permanent install
npx @google/gemini-cli
 
# Check the version
gemini --version

There are two ways to authenticate. On first launch, gemini prompts you to sign in with a Google account, and you can start on the free tier right away. In environments that can't show an interactive prompt — CI or scripts — passing an API key via an environment variable is the reliable path.

# API key auth (for CI and automation)
export GEMINI_API_KEY="YOUR_API_KEY"

Keep the key in .env and always add it to .gitignore. Skip this and you risk pushing your key straight into a public repository.

echo 'GEMINI_API_KEY=YOUR_API_KEY' > .env
echo '.env' >> .gitignore

Separate interactive mode from headless mode

Gemini CLI's invocations split broadly into "interactive" and "headless." Just being aware of that boundary makes the right choice obvious.

GoalCommandBehavior
Think through somethinggeminiStarts the interactive REPL
Get just the answergemini -p "..."Runs one turn and exits (non-interactive)
Feed standard inputcat file | geminiProcesses piped content
Run, then keep goinggemini -i "..."Executes, then drops into interactive mode
Machine-process the resultgemini -p "..." -o jsonEmits JSON

For automation, the keys are -p (--prompt) and -o (--output-format). -p returns a single turn to stdout without entering the REPL, and adding -o json gives you structured data that tools like jq can handle.

# Pull only the critical errors out of a log
cat build.log | gemini -p "List up to 3 fatal errors from this log, each with a guessed cause"
 
# Receive the result as JSON and pass it downstream
gemini -p "Summarize README.md in one sentence" -o json | jq -r '.response'

You pick the model with -m (--model). Aliases are provided: pro for complex reasoning, flash as a speed-and-quality balance, and flash-lite as the fastest for simple tasks. For batch work like triaging many logs, leaning on the flash family tightens both cost and latency.

# Push light classification tasks to the flash family
cat access.log | gemini -m flash -p "Group requests by country and show the top 5"

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
When to use interactive vs headless mode (gemini -p / -o json), and how to decide before wiring it into CI
Concrete steps to keep automation safe and reproducible with session resume, GEMINI.md, and approval modes
A ready-to-run pre-push hook plus a headless wrapper that absorbs empty stdin, 429s, and broken JSON
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Gemini Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $15 for lifetime access
View Membership →

Related Articles

Dev Tools2026-05-04
Gemini CLI with MCP Servers: A from File I/O to Database Queries
Learn how to connect MCP servers to Gemini CLI for hands-on file operations and database integration. Covers GEMINI.md configuration, filesystem, SQLite, and GitHub MCP with working examples.
Dev Tools2026-06-18
Keeping Nightly Batches Alive After the Gemini CLI Stops Responding: A google-genai SDK Fallback
On June 18 the Gemini CLI stops answering requests. Here is a small fallback harness that probes whether the CLI can still respond and quietly reroutes unattended batch jobs to the google-genai SDK, built from my own automation.
Dev Tools2026-06-15
Getting Ready for the Gemini CLI and Code Assist Personal Shutdown: A June 18 Migration Inventory
On June 18, personal access to Gemini CLI and Code Assist stops. Here is how I found every place I depended on it and moved each one to either Antigravity CLI or direct API calls, using my own setup as the example.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →