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:
npm install -g @google/gemini-cliOr run it instantly without a global install using npx:
npx @google/gemini-cliVerify the installation worked:
gemini --versionStep 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.
gemini auth loginVerify your authentication status at any time:
gemini auth statusStep 3 — Your First Prompt
Ask Gemini a question directly from the command line:
gemini "How do I reverse a string in JavaScript?"Start an interactive chat session (useful for multi-turn conversations):
geminiHave Gemini explain your entire project by running it inside your repo:
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:
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:
git diff | gemini "Review this diff and suggest improvements"Generate unit tests for a file:
gemini -f src/lib/database.ts "Write comprehensive Jest unit tests for all exported functions"Debug an error from your logs:
cat error.log | gemini "What does this error mean and how do I fix it?"Generate a README for your project:
gemini "Write a comprehensive README.md for this project" > README.mdUse the faster Flash model for quick questions:
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:
# 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":
{
"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:
# Press Ctrl+Shift+P, then type:
> Tasks: Run Task → Ask GeminiMethod 3: Shell Aliases for Speed
Add these aliases to your `.bashrc` or `.zshrc` for supercharged workflows in the VS Code 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:
source ~/.bashrc
# or
source ~/.zshrcNow you can use them anywhere in VS Code 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:
{
"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



