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
- 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.
As reported by the source (Gemini CLI docs); AgentGid did not measure these figures.
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
Build a CI-health monitoring agent with the Claude Agent SDK and GitHub MCP
In this Anthropic cookbook notebook, an agent gets the official GitHub MCP server and is told to look over recent CI runs. It reports failing jobs, flaky patterns and recommended …
A status summary of recent CI runs and what triggered them.
How Empower cut incident response time with Factory Droids
Fintech company Empower used Factory's platform and Review Droid for incident diagnostics, QA impact analysis, product questions and automated code review. As reported by Factory,…
As reported by Factory: incident response time was reduced 'by up to 40%'.
How Datadog tested Codex code review by replaying past incidents
Datadog ran Codex against old pull requests that had contributed to incidents, to check whether AI review would have caught the risk. After the test, it rolled Codex review out wi…
As reported by OpenAI: Codex 'found more than 10 cases, or roughly 22% of the incidents' examined, where engineers said its feedback would have made …