Gemini CLI
What you'll learn
~15 min- Install Gemini CLI globally via npm
- Authenticate with a Google account or API key
- Run your first task and view the output
- Understand when to choose Gemini CLI vs Claude Code
Google Cloud Shell at shell.cloud.google.com has Gemini CLI tooling pre-installed, or use Gemini Web at gemini.google.com for conversational tasks.
See the Cloud Sandbox Cheat Sheet
for current pricing, or set up your sandbox.
By the end of this lesson, you’ll have Gemini CLI running and understand why its large context window and generous daily allowance make it a strong everyday tool.
What is Gemini CLI?
Gemini CLI is Google’s open-source command-line AI tool. It has quickly become a very popular AI CLI tool, with tens of thousands of GitHub stars. It uses Google’s Gemini models and offers a generous usage allowance.
Key features:
- Up to 1,000 requests per day on the free Google-account tier (60 req/min, full model family)
- Massive context: 1 million tokens — it can read enormous codebases
- Plan mode: Built-in planning that lets you review and edit a strategy before execution
- Project context:
GEMINI.mdfiles give the model persistent project instructions (like Claude Code’sCLAUDE.md) - Open source: You can see exactly how it works, and the community contributes improvements
- MCP extensible: Can connect to external tools and services
- Multiple models: Access to Gemini 2.5 Pro, 3.1 Pro Preview, Flash, and more
Installation
Step 1: Install Gemini CLI
npm install -g @google/gemini-cliVerify:
gemini --versionGemini CLI runs on Windows native (PowerShell, CMD, or Git Bash) with no differences — it only needs Node.js. The install command is the same whether you’re in WSL or native Windows.
Step 2: Authenticate
Run Gemini CLI:
geminiIt will open your browser to authenticate with your Google account. Sign in, and you’re done.
If you’re on a remote server without a browser, Gemini CLI supports device flow authentication — it shows a URL and a code. Open the URL on your local machine’s browser, enter the code, and the remote tool authenticates. Alternatively, you can set a Gemini API key as an environment variable: export GEMINI_API_KEY="your-key". Get one from aistudio.google.com. If you already use Google Cloud, you can also authenticate via gcloud auth — see the official Gemini CLI docs for details.
Gemini CLI is under active development. If the install command above does not work, check the official repository for the latest instructions.
The free Google-account tier gives you 1,000 requests per day at 60 requests per minute, with access to the full Gemini model family. If you authenticate with an unpaid API key instead, you get a smaller allowance — 250 requests per day with Flash models only. For learning and real projects, the Google account tier is the way to go.
Your first interaction
Step 1: Create a project folder
mkdir hello-gemini && cd hello-geminiStep 2: Start Gemini CLI
geminiStep 3: Give it a task
Create a simple HTML page with a counter. It should have a darkbackground, a large number in the center, and + / - buttons toincrement and decrement. Use vanilla JavaScript — no frameworks.Watch as Gemini:
- Plans the approach
- Creates the file(s)
- Writes the HTML, CSS, and JavaScript
- Reports what it did
Step 4: Check the result
lscat index.htmlopen index.htmlFrom WSL:
explorer.exe index.htmlOr right-click the file in VS Code’s Explorer panel.
xdg-open index.htmlOn a remote server, use VS Code’s file explorer or download the file.
Gemini CLI vs Claude Code
Both are excellent tools. Here’s how they compare:
| Aspect | Gemini CLI | Claude Code |
|---|---|---|
| Access | Google account (generous free tier) | API key or subscription |
| Context window | 1M tokens | Large (varies by model) |
| Open source | Yes | No |
| Project context | GEMINI.md | CLAUDE.md |
| Best for | Large codebases, budget-conscious work | Complex reasoning, nuanced instructions |
| Setup | Google account | API key or subscription |
Context windows and model capabilities change frequently — check each tool’s official docs for current limits. Many developers use both — Gemini CLI for everyday tasks and Claude Code for complex, multi-step projects where reasoning quality matters most.
🧬In Your Field: Biotechclick to expand
Gemini CLI’s large context window is especially useful for bioinformatics. You can feed it an entire sequencing pipeline — dozens of scripts, config files, and documentation — and ask questions like “Trace the data flow from raw FASTQ files to the final variant call set” or “Which steps in this pipeline could be parallelized?” It is among the largest context windows currently available in popular CLI tools, making it ideal for understanding large, inherited analysis codebases.
🏛️In Your Field: Government / State Devclick to expand
For government and state development work, Gemini CLI’s free daily allowance is a significant advantage. When you’re working on internal tools and don’t have budget approval for API subscriptions yet, 1,000 requests per day lets you prototype and iterate without procurement paperwork. It’s also useful for analyzing large policy documents or legislative text — that million-token window can hold hundreds of pages of regulations at once.
Useful commands
In-session commands (type these while Gemini CLI is running):
| Command | What it does |
|---|---|
/help | Show available commands |
/plan | Enter Plan Mode — Gemini outlines a strategy before executing |
/model | Switch between Gemini models |
/memory show | View the memory Gemini has stored about your project |
/memory reload | Reload memory and GEMINI.md context files |
/clear | Clear conversation history |
Shift+Tab | Toggle Plan Mode on/off |
Ctrl+C | Exit Gemini CLI |
Startup flags (add these when launching):
| Flag | What it does |
|---|---|
--yolo | Launch in autonomous mode (auto-enables sandbox) |
Tips
-
Take advantage of the large context. Gemini CLI’s 1M-token context window can handle very large codebases — don’t hesitate to point it at big projects.
-
Experiment without hesitation. The free-tier daily allowance is generous — don’t worry about “wasting” requests while learning.
-
Set up a
GEMINI.mdearly. Even a few lines of project context (“This is a Python Flask app, we use pytest, follow PEP 8”) makes every response better. -
Use Plan Mode for anything non-trivial. It’s on by default, but get in the habit of reviewing the plan before letting Gemini execute. Press
Ctrl+Xto edit the plan externally if you want to adjust the approach. -
Try different models. Use
/modelto switch between available models — Pro for complex tasks, Flash for quick ones.
Power features
Plan Mode
Plan Mode is on by default as of v0.34.0. Gemini outlines a strategy before executing, so you can review and approve the approach. You can enter it explicitly with /plan, toggle it with Shift+Tab, or just phrase your request as a plan (“plan how to refactor the auth module”). Plans can be edited externally — press Ctrl+X to open the plan in your editor, tweak the steps, and Gemini follows your revised plan.
GEMINI.md project context
Just like Claude Code uses CLAUDE.md, Gemini CLI loads GEMINI.md files for persistent project instructions. It checks hierarchically — from ~/.gemini/GEMINI.md (global defaults) down through parent directories to your project root. Use these to set coding conventions, preferred libraries, or domain context that Gemini should always know about.
Thinking mode
Gemini CLI has a built-in thinking mode that may show planning and thought summaries depending on the model and your settings. This is enabled by default and helps you understand how it approaches a problem. For simple tasks where you do not need to see the reasoning, you can disable it in settings.
YOLO mode
Run gemini --yolo to enable autonomous mode. Gemini will execute file edits and commands without asking for confirmation. When YOLO mode is active, Gemini automatically enables sandbox isolation to contain any damage.
The sandbox protects your system, but the AI can still make changes inside the sandbox that are hard to undo. Use YOLO mode for quick prototypes and learning experiments, not for work you care about keeping.
Sandbox
Gemini CLI can run inside a sandbox that isolates file changes and commands from your real system. It supports Docker, gVisor (runsc), and experimental LXC container isolation. The sandbox is auto-enabled in YOLO mode, but you can also use it manually for extra safety on any task.
Memory and checkpointing
Gemini CLI remembers context across sessions. Use /memory show to see what it has stored and /memory reload to refresh. It also supports checkpointing — session snapshots you can rewind to if an approach goes wrong, similar to save points in a game.
Model switching
Use /model mid-session to switch between models. Gemini 2.5 Pro and 3.1 Pro Preview are the most capable and best for complex, multi-step tasks. The Flash model is faster and uses less of your daily allowance — good for simple edits and quick questions. Available models may change as Google releases new versions.
Headless mode
For scripting and automation, Gemini CLI supports headless mode — run it without an interactive session, pipe input/output, and integrate it into CI pipelines or shell scripts.
Verify it works
Paste this exact command to confirm everything is set up correctly:
gemini --versionYou should see a version number printed. If you get “command not found,” revisit the installation step above.
If the version check worked, try a quick test. You can pass a prompt directly as a command-line argument:
gemini "What is 2 + 2? Reply with just the number."If your version does not support one-shot prompts, start an interactive session with gemini and type your prompt there. If you see a response either way, congratulations — Gemini CLI is fully working.
When Things Go Wrong
Use the Symptom → Evidence → Request pattern: describe what you see, paste the error, then ask for a fix.
Each CLI tool you set up widens what you can do. Gemini CLI’s free tier means you can experiment without worrying about cost — and the skills transfer directly to any AI tool. You’re not just learning Gemini. You’re learning orchestration. The specific commands will change; the ability to direct an AI agent to do your work faster will not.
Key Takeaways
- Install with
npm install -g @google/gemini-cli— a Google account gets you 1,000 requests/day with the full model family - Plan Mode is on by default — review the strategy before execution, edit plans with
Ctrl+X GEMINI.mdgives persistent project context — hierarchical loading from global to project directory- The 1M-token context window lets Gemini CLI read more of your project than most other tools
- Use
/modelto switch models — Pro for complex tasks, Flash for quick ones - Pair it with Claude Code — use Gemini for broad exploration and Claude for precision reasoning