GEMINI LABJP
NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaplyOMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflowsAGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactionsMEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuouslyTHROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and regionDEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaplyOMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflowsAGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactionsMEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuouslyTHROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and regionDEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20
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 integration. A practical guide to embedding it in shell scripts and CI, with lessons from real use.

Gemini CLI8headlessMCP4automation51CI5

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
Ready-to-run shell scripts that hand a git pre-push hook and log triage to Gemini CLI
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 $10 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 →