Skip to content

Gemini CLI — Google's AI in Your Terminal

Gemini CLI is Google’s open-source command-line AI agent, powered by Gemini 2.5 Pro with a 1 million token context window. It brings the same powerful AI that drives Google’s products to your terminal for coding, analysis, and automation tasks.

Gemini CLI is free and open-source — Google offers a generous free tier via Google AI Studio API keys.

Terminal window
# Install via npm
npm install -g @google/gemini-cli
# Or run without installing (npx)
npx @google/gemini-cli
# Authenticate
gemini auth login
# Follow the browser flow to connect your Google account / API key
Terminal window
# Start interactive session in your project
cd my-project
gemini
# Ask a one-shot question
gemini "Explain what this codebase does"
# Give it a task
gemini "Add input validation to all API endpoints and write tests"

With Gemini 2.5 Flash’s 1 million token window, Gemini CLI can:

  • Load your entire project — not just open files
  • Process large log files or exported data
  • Read multiple repositories simultaneously
  • Understand complex dependency graphs
Terminal window
# Load an entire large project
gemini --include "**/*.ts,**/*.json" "Find all security vulnerabilities"

Gemini CLI can search Google in real time during tasks:

Terminal window
gemini "Update the AWS SDK v2 calls to v3 syntax"
# → Searches for AWS SDK v3 migration guide
# → Applies up-to-date patterns to your code

Gemini CLI can take autonomous actions:

  • Read and write files
  • Run shell commands
  • Execute tests and fix failures
  • Navigate directory structures
Terminal window
gemini "Refactor the authentication module to use JWT and add comprehensive tests"
# Reads auth files → Plans changes → Edits files → Runs tests → Fixes failures

Gemini CLI supports the Model Context Protocol (MCP), allowing it to connect to:

  • Databases (read schema, query data)
  • APIs (fetch live data)
  • Documentation servers
  • Internal tools
Terminal window
# Start with MCP server for database access
gemini --mcp-server postgres://localhost/mydb "Optimize these slow queries"
FeatureGemini CLIClaude Code
Context window1M tokens (Flash) / 2M (Pro)200K tokens
Search groundingYes (Google Search)Yes (Web search)
ModelGemini 2.5 Flash/ProClaude 3.7 Sonnet
MCP supportYesYes
Open sourceYesYes
Free tierYes (generous via AI Studio)Requires Claude Pro
File operationsYesYes
Shell commandsYesYes
Best forLarge repos, GCP projectsGeneral coding, AWS

Gemini CLI is free to use with Google AI Studio API keys:

  • Gemini 2.5 Flash: Free tier includes 1,500 requests/day
  • Gemini 2.5 Pro: Free tier includes 50 requests/day

For heavier usage, the Gemini API is billed per token (significantly cheaper than OpenAI).

Terminal window
# Set default model
gemini config set model gemini-2.5-flash
# Set your project context file (like CLAUDE.md)
cat > GEMINI.md << 'EOF'
# Project Context
- Stack: Node.js + TypeScript + PostgreSQL
- Test runner: Jest
- Lint: ESLint + Prettier
- Always run `npm test` after changes
EOF
# Enable Google Search grounding
gemini config set search true
Terminal window
# Understand a new codebase
gemini "Give me a tour of this codebase — what does it do, how is it structured?"
# Fix a failing test
gemini "The test in auth.test.ts line 42 is failing. Fix the underlying issue."
# Security audit
gemini "Review this codebase for OWASP Top 10 vulnerabilities"
# Generate documentation
gemini "Generate OpenAPI 3.0 spec for all API routes in src/routes/"
# Upgrade dependencies
gemini "Upgrade all dependencies to latest versions and fix any breaking changes"