Developer Tools· 10 min read·January 8, 2026

Gemini CLI: The Complete Setup & Usage Guide for Developers

Google's Gemini CLI brings the full power of Gemini AI directly into your terminal — letting you summarize files, write code, debug errors, and query your entire codebase without ever leaving the command line.

Hritik Raj

Hritik Raj

AI Full Stack Developer

Share:
Gemini CLI: The Complete Setup & Usage Guide for Developers

What is Gemini CLI?

Gemini CLI is a free, open-source command-line tool developed by Google that lets you interact with Gemini AI models directly from your terminal. It can read your project files, understand your entire codebase context, run shell commands, and even browse the web — all from a single prompt.

With a massive 1 million token context window and Google's generous free tier (up to 60 requests/minute and 1,500 requests/day), it's one of the most powerful free AI tools available to developers today.

Prerequisites

Before installing, make sure you have the following ready:

  • Node.js 18 or higher installed on your machine
  • npm or npx available in your terminal
  • A Google account (for authentication)
  • An active internet connection

Step 1 — Install Gemini CLI

Install globally via npm so you can use it from any directory:

Terminal
npm install -g @google/gemini-cli

Or run it instantly without a global install using npx:

Terminal
npx @google/gemini-cli

Verify the installation worked:

Terminal
gemini --version

Step 2 — Authenticate with Google

Run the login command. This opens your browser to authenticate with your Google account. Once done, an auth token is stored locally on your machine.

Terminal
gemini auth login

Verify your authentication status at any time:

Terminal
gemini auth status

Step 3 — Your First Prompt

Ask Gemini a question directly from the command line:

Terminal
gemini "How do I reverse a string in JavaScript?"

Start an interactive chat session (useful for multi-turn conversations):

Terminal
gemini

Have Gemini explain your entire project by running it inside your repo:

Terminal
cd my-project && gemini "Explain what this codebase does"

Step 4 — Key Flags & Options

These are the most useful flags you will use constantly:

  • -f <file> — attach a file as context for your prompt
  • --model <name> — choose a specific Gemini model (e.g. gemini-2.5-pro, gemini-2.5-flash)
  • --yolo — auto-approve all tool actions without prompting (useful in CI)
  • --debug — show detailed logs for troubleshooting
  • --help — list all available commands and flags

Step 5 — Real-World Developer Commands

Ask Gemini to explain a specific file in your codebase:

Terminal
gemini -f src/utils/auth.ts "Explain what this file does and identify any security issues"

Review your git diff before committing — catch bugs before they ship:

Terminal
git diff | gemini "Review this diff and suggest improvements"

Generate unit tests for a file:

Terminal
gemini -f src/lib/database.ts "Write comprehensive Jest unit tests for all exported functions"

Debug an error from your logs:

Terminal
cat error.log | gemini "What does this error mean and how do I fix it?"

Generate a README for your project:

Terminal
gemini "Write a comprehensive README.md for this project" > README.md

Use the faster Flash model for quick questions:

Terminal
gemini --model gemini-2.5-flash "What is the difference between useState and useReducer in React?"

Step 6 — Integrate Gemini CLI into VS Code

VS Code integration lets you access Gemini without leaving your editor. Here are four ways to set it up:

Method 1: VS Code Integrated Terminal (Zero Setup)

The simplest approach — open VS Code's built-in terminal and use Gemini CLI just like you would anywhere else:

Terminal
# Open terminal in VS Code: Ctrl+` (Windows/Linux) or Cmd+` (Mac)
gemini -f src/components/Button.tsx "Refactor this component to use TypeScript generics"

Method 2: VS Code Task (Run via Command Palette)

Create a `.vscode/tasks.json` file in your project root. This lets you trigger Gemini with Ctrl+Shift+P → "Run Task":

JSON
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Ask Gemini",
      "type": "shell",
      "command": "gemini",
      "args": ["${input:geminiPrompt}"],
      "group": "none",
      "presentation": {
        "reveal": "always",
        "panel": "shared",
        "focus": true
      }
    }
  ],
  "inputs": [
    {
      "id": "geminiPrompt",
      "type": "promptString",
      "description": "Ask Gemini anything about your project…"
    }
  ]
}

Run it anytime with:

Terminal
# Press Ctrl+Shift+P, then type:
> Tasks: Run Task → Ask Gemini

Method 3: Shell Aliases for Speed

Add these aliases to your `.bashrc` or `.zshrc` for supercharged workflows in the VS Code terminal:

Terminal
# Add to ~/.bashrc or ~/.zshrc
alias ask="gemini"
alias review="git diff | gemini 'Review this diff and list improvements'"
alias explain="gemini -f"
alias tests="gemini -f $1 'Write unit tests for this file'"
alias readme="gemini 'Write a README.md for this project' > README.md"

Reload your shell to activate the aliases:

Terminal
source ~/.bashrc
# or
source ~/.zshrc

Now you can use them anywhere in VS Code terminal:

Terminal
ask "What is the best way to handle auth in Next.js?"
review
explain src/pages/api/auth.ts "What does this endpoint do?"

Method 4: Custom Keyboard Shortcut

Open VS Code keyboard shortcuts JSON (Ctrl+Shift+P → "Open Keyboard Shortcuts JSON") and add:

JSON
{
  "key": "ctrl+shift+g",
  "command": "workbench.action.terminal.sendSequence",
  "args": { "text": "gemini \u0000" }
}

Tips & Best Practices

  • Be specific — "Fix the null pointer bug in the fetchUser function" beats "fix the bug"
  • Always use -f to give Gemini the actual file context instead of pasting code in prompts
  • Pipe git diff before every commit for an instant AI code review
  • Use gemini-2.5-flash for speed, gemini-2.5-pro for complex reasoning tasks
  • Run Gemini from inside your project directory — it will index your files automatically
  • Use --yolo in CI/CD scripts to bypass interactive confirmation prompts
  • Create project-specific aliases in .env or shell scripts for repeated workflows
"

The developers who ship fastest are not those who type the most — they are those who ask the right questions to the right tools.

Topics

Gemini CLIAI ToolsVS CodeTerminalGoogle AIProductivity
Hritik Raj

Hritik Raj

AI Full Stack Dev

Building AI-powered web experiences. Creator of DevLearnHub — where developers learn by building.