Post

Gemini CLI

An open-source, terminal-native AI agent powered by Gemini that investigates code, executes searches, fetches web content, and runs shell commands -- enabling hands-free technical workflows from the command line.

Gemini CLI

An open-source, terminal-native AI agent powered by Gemini that investigates code, executes searches, fetches web content, and runs shell commands — enabling hands-free technical workflows from the command line.


What Is Gemini CLI?

Gemini CLI is an open-source terminal application that brings the Gemini model’s reasoning directly into your shell. It operates as a ReAct agent – Reasoning and Acting in loops – with built-in tools for code investigation, file manipulation, shell execution, and web search.

Key Philosophy: Terminal-first design, open-source (Apache 2.0), model-agnostic via MCP, privacy-respecting.


Core Architecture: ReAct Loop

1
2
3
4
5
6
7
8
9
10
11
User asks: "Debug why my API crashes when processing 100K+ items"
    |
THINK: "I need to see the code, check error logs, search for known issues"
    |
ACT: Execute tools sequentially
  1. find source files
  2. read api.py (identify crash point)
  3. web-search "Python OOM handling 100K"
  4. test fix locally
    |
RESPOND: "Found it. The issue is memory allocation on line 142."

Built-In Tools

Codebase Investigator

AST-based code understanding, intelligent file discovery, dependency graph visualization, symbol search.

File Operations

Read, edit/replace, write, find/glob – all with AI-driven context.

Shell Command Execution

Execute arbitrary shell commands including interactive sessions (vim, git rebase -i, ssh).

Google Search Grounding

Built-in real-time web search with citations on every query.

WebFetch

Fetch and extract content from URLs for documentation and research.

SaveMemory and WriteTodos

Persistent conversation state and task tracking across sessions.


MCP Integration

1
2
3
4
5
6
7
8
9
# Custom tool example
from mcp.server import Server

class DatabaseQueryTool:
    async def execute_query(self, sql: str):
        return results

server = Server("database-query")
server.add_tool(DatabaseQueryTool.execute_query)

Usage Patterns

Code Exploration

1
gemini-cli "Map out the user authentication flow."

Debugging

1
gemini-cli "Debug: POST /api/payments fails with 'insufficient funds' even though account has $1000."

Non-Interactive Automation (CI/CD)

1
2
gemini-cli --non-interactive --model "gemini-2.5-flash" \
  "Analyze code changes for security issues" > analysis_report.md

Gemini CLI vs Alternatives

Feature Gemini CLI Claude Code Cursor
Access Model Open-source (free) Commercial Commercial ($20/month)
Terminal-Native Yes No (API-based) Partial
Web Search Grounding Built-in External API required Limited
Interactive Shell Yes (vim, git rebase) No No
Extensibility (MCP) Yes Yes Limited

Verdict:

  • Gemini CLI: Best for DevOps, automation, free/open-source requirement
  • Claude Code: Best for deep multi-file reasoning
  • Cursor: Best for IDE-integrated development

Performance and Cost

1
2
3
For 100 engineers running 20 ops/day:
100 x 20 x 2K tokens x $0.30/M = $1.20/day = $36/month
= $0.36 per engineer per month (practically free)

Installation

1
2
npm install -g @google-gemini/gemini-cli
gemini-cli --set-api-key "YOUR_GOOGLE_API_KEY"

References

This post is licensed under CC BY 4.0 by the author.