Script Gemini CLI in your terminal: explain logs, write commits, document files
Gemini CLI's headless mode takes piped input and returns plain text or JSON. That makes it usable inside shell scripts, aliases and CI jobs.
The problem
Copying logs and diffs into a chat window is slow and can't be repeated reliably. Calling the agent as a normal Unix command lets you automate log explanations, commit messages and batch documentation.
Steps
- Install and sign in to Gemini CLI.
- Run one-off prompts with the -p flag, so no interactive session opens.
- Pipe in context, such as an error log or the output of git diff.
- Add --output-format json and parse .response with jq when another tool needs the result.
- Loop over files in a script, or wrap a diff-to-commit prompt in a shell alias.
From the official docs
cat error.log | gemini -p "Explain why this failed"
git diff | gemini -p "Write a commit message for these changes"
Results as reported by Google
- Explanations of failures from piped logs, and commit messages generated from staged diffs.
- Batch Markdown documentation for a folder of Python scripts.
- Exit codes your scripts can check, such as 53 when the turn limit is exceeded.
These figures are as reported by Google in Gemini CLI docs ↗. Google sells the product used here. AgentGid did not measure or independently verify them.
Suits anyone comfortable with shell scripting, pipes and jq, from solo developers to CI owners. The thing to watch is billing: AgentGid's data shows Gemini CLI's free individual tier ended on 2026-06-18, so scripted loops now run on pay-as-you-go API keys or a paid license. Pi is free and MIT-licensed (Free (OSS)), though you still pay your model provider.
The agent used here
Similar use cases
How Rescale built a test-failure triage agent with Strands Agents and AI-DLC
Rescale, a digital engineering platform company, built an agent that classifies and routes failures from its nightly end-to-end tests, using the AI-DLC methodology and the Strands…
As reported by AWS, classification agreement with human triage rose from 44% at initial deployment to 68% today.
How Cornerstone OnDemand cut database diagnosis time with Strands Agents on Amazon Bedrock
Cornerstone OnDemand's three-person Enterprise DataOps team built Orion AI, a multi-agent system on Amazon Bedrock and Strands Agents, in six months. It speeds up database inciden…
As reported by AWS, database diagnosis time dropped from 45 minutes to 10 minutes, a 78% reduction.
Automate remediation after an AWS DevOps Agent investigation with Lambda Durable Functions
An AWS blog post shows how to pair AWS DevOps Agent, which only observes and reports, with a Lambda Durable Functions workflow that uses Amazon Bedrock to propose and apply fixes.…
In the demo, a function with a 3-second timeout was diagnosed, and Bedrock proposed raising it to 30 seconds. (as reported by AWS)