Back to Gemini CLI
Gemini CLIBeginner4 min read

Getting Started with Gemini CLI

Install Gemini CLI, choose the right authentication flow, and master the core Research -> Strategy -> Execution workflow

setupauthenticationgemini-mdworkflowplan-mode

Official References: Overview · Installation · Authentication · GEMINI.md

Why Gemini CLI feels different

Gemini CLI is Google's open-source terminal agent. Its current positioning is simple: bring Gemini models, local tools, web access, and project context into one CLI that works well for both interactive sessions and automation.

For this project, Gemini CLI matters most in three situations:

  1. Large-repo understanding — the 1M-token context window is good for broad architectural passes.
  2. Mixed local + web workflows — the tool system can read files, run shell commands, and fetch current information.
  3. Reusable project guidanceGEMINI.md gives you persistent instructions without rewriting the same prompt every time.

Install it the practical way

Gemini CLI currently recommends Node.js 20+.

# npm global install
npm install -g @google/gemini-cli
 
# macOS / Linux
brew install gemini-cli
 
# no permanent install
npx @google/gemini-cli

Pick the right authentication path

The official docs split auth into a few clear cases:

Situation Best option Notes
Personal local usage Sign in with Google Simplest default flow
Headless scripts / CI Gemini API key Easy env-var based setup
GCP-heavy org setup Vertex AI Fits existing Google Cloud controls
Workspace / school account Google sign-in + project config Often needs a Cloud project

1) Sign in with Google

gemini

Then choose the Google sign-in flow in the CLI.

2) Use a Gemini API key

Best for scripts, headless jobs, or minimal local setup:

export GEMINI_API_KEY="YOUR_GEMINI_API_KEY"
gemini

3) Use Vertex AI

Best when your team already manages models through Google Cloud:

export GOOGLE_CLOUD_PROJECT="your-project-id"
export GOOGLE_CLOUD_LOCATION="us-central1"
gemini

First commands and Core Workflows

Gemini CLI is strongest when you use its tool syntax instead of writing giant prompts manually.

Basic Interaction

# Start interactive mode
gemini
 
# Include files or directories with @
gemini "@package.json @src explain the app architecture"
 
# Run shell commands with !
!npm test

The Core Workflow: Research -> Strategy -> Execution

Instead of just chatting, guide the agent through explicit phases:

  1. Research: Ask the agent to explore (grep_search, glob) and map the codebase.
  2. Strategy: Ask it to design an approach before making changes.
  3. Execution: Let it apply surgical changes (replace, write_file) and validate via shell tools.

Utilizing Plan Mode (/plan)

For large refactoring or architectural decisions, it is risky to let the agent start editing immediately. Use the /plan command to enter Plan Mode. In this read-only state, the agent cannot modify files or run destructive commands. It focuses entirely on navigating the code and drafting a rigorous design document. Once the plan is verified, switch back to the default mode to execute the changes safely.

GEMINI.md is the real unlock

Gemini CLI loads GEMINI.md hierarchically:

  1. ~/.gemini/GEMINI.md (global preferences)
  2. workspace context files (project-wide rules)
  3. JIT context files inside subdirectories

Example project file

# Project: AI Native Notes
 
## Stack
- Next.js 16
- TypeScript
- next-intl
- MDX content under /content
 
## Content rules
- Keep frontmatter consistent across locales
- Prefer practical examples over marketing copy
- Preserve slug parity between ko/en/es

Gemini CLI vs Claude Code vs GPT Codex

Feature Claude Code GPT Codex Gemini CLI
Main instruction file CLAUDE.md AGENTS.md GEMINI.md
Context style strong conversational memory task-scoped execution hierarchical memory + large context
Local tooling local + MCP sandbox/container oriented local + web + MCP + sub-agents
Best first use guided editing bounded implementation tasks repository understanding + large refactors

Connected Guides