Gemini CLI & Code Assist
Gemini CLI is Google’s open-source coding agent that lives in your terminal, and Gemini Code Assist is the same brain wired into your editor. Both let you hand a real task — “add this feature,” “fix this bug,” “refactor across the whole repo” — to an agent that reads your files, proposes edits, runs commands, and iterates, with you gating what actually happens. This is the Google counterpart to Claude Code and the Copilot coding agent.
Imagine a super-helpful robot that sits inside the black window where programmers type. You tell it what you want in plain English — “make the login page work” — and it reads all your files, writes the changes, tries them out, and fixes its own mistakes. But before it saves anything for real, it shows you and waits for you to say “yes.” Gemini CLI is that robot from Google, running right in your terminal.
Two surfaces: the terminal agent and the IDE assistant
☺ Like you’re 10: It’s the same helper standing in two different doorways — one in the plain typing window, one inside the fancy code editor. Same helper, you just pick which door is closer to what you’re doing.
“Gemini for coding” from Google comes in two main shapes, powered by the same Gemini models underneath:
| Surface | Where it lives | What it’s for |
|---|---|---|
| Gemini CLI | Your terminal — an open-source command-line tool | An agent you talk to in the shell: reads and edits files, runs commands, works across the whole project. The focus of this page. |
| Gemini Code Assist | Inside your IDE (VS Code, JetBrains) and on GitHub | Inline completions, chat about your code, and an agent mode — plus code review on pull requests. Shares the CLI’s agent under the hood. |
Gemini CLI is open source (Apache-2.0), which is unusual for a first-party vendor agent — you can read exactly how the loop works, file issues, and extend it. It’s the same agent that powers Code Assist’s agent mode, so what you learn in the terminal carries straight into the editor. Model versions move fast — Gemini families advance quickly — so treat any specific version as “true at time of writing” and check the current lineup; the important thing is the shape of the tool, which is stable.
This sits at the agentic end of the autonomy spectrum — well past the Gemini chat app and the raw Gemini API. Completions → chat → agent is the same progression you saw with Copilot and with Claude; Gemini CLI is Google’s agent rung.
The agent loop: plan → edit → run → iterate
☺ Like you’re 10: The robot doesn’t just blurt out an answer. It thinks up a plan, does one step, checks if it worked, and tries again if it didn’t — like building with LEGO, snapping a piece, seeing if it fits, and adjusting. Round and round until it’s done.
What makes Gemini CLI an agent and not just a chatbot is that it runs a loop, not a single turn. You give it a goal; it decides which tools to call, sees the results, and keeps going until the goal is met or it needs you. This is exactly the agentic loop from Foundations, wearing Google’s badge:
- Plan. Gemini reads your request and the relevant files, then decides the next action — often narrating a short plan first so you can see its intent.
- Edit. It proposes concrete file changes as a diff — the exact lines added and removed — rather than pasting code for you to copy.
- Run. It can execute shell commands: run the test suite, start a build, grep the codebase, install a package — and read the output.
- Iterate. It observes what happened (a test failed, a type error appeared) and loops back to plan the fix. It keeps cycling until the goal is met or it hands control back to you.
Because it can run its own code and read the result, the agent closes the feedback loop that a plain chat can’t: it catches its own mistakes instead of confidently handing you code that doesn’t compile. The reasoning and building-agents pages go deeper on why this loop is the heart of every capable agent.
The large-context advantage: reasoning over a whole repo
☺ Like you’re 10: Some helpers can only hold a few pages in their head at once. Gemini can hold a whole stack of notebooks — so instead of squinting at one page, it can see how everything connects across the entire project before it changes anything.
Gemini’s headline strength for coding is its very large context window — long enough to hold a big slice of a real codebase at once (Gemini models have led on context length, with windows into the seven-figure-token range at time of writing). For an agent, more context is not a vanity number; it changes what the tool can reliably do:
- Whole-repo reasoning. A refactor that touches a function defined in one file and called in twenty others needs the agent to see all twenty. With a large window it can load them together and reason about the change as a whole, instead of editing blindly file by file.
- Fewer “lost the thread” errors. Long agent sessions accumulate history — plans, diffs, test output. A bigger window means the agent forgets less of its own earlier work mid-task.
- Grounding in real code, not guesses. More of your actual files in context means fewer hallucinated APIs and function names — it can read the real signature instead of inventing one.
Context isn’t infinite or free, though — every token costs, and a giant context can still lose focus (the “needle in a haystack” problem). So Gemini CLI still retrieves: it reads the files it needs rather than blindly stuffing the entire repo into every turn. This is the same RAG-vs-long-context trade-off from Foundations — long context and retrieval are partners, not rivals. Big context is Gemini’s edge; using it wisely is still the skill.
Where Claude Code leans on careful step-by-step tool use and Copilot leans on deep GitHub integration, Gemini CLI’s standout is breadth of context — “show me the whole codebase and I’ll reason about it at once.” For sprawling refactors and cross-file understanding, that’s a real advantage.
Tools and MCP: giving the agent hands
☺ Like you’re 10: By itself the helper can only read and write your files. Tools are like giving it extra hands — one to search the web, one to poke your database, one to check your task tracker — so it can reach beyond the code when a job needs it. MCP is the standard-shaped plug those hands snap into.
Out of the box, Gemini CLI ships with a set of built-in tools: read and write files, run shell commands, search the filesystem, fetch web pages, and use Google Search for grounding. But its real reach comes from MCP — the Model Context Protocol — the same open standard you met in Foundations. Gemini CLI is an MCP client: point it at an MCP server and the agent gains that server’s tools automatically.
| Tool source | Examples | What it unlocks |
|---|---|---|
| Built-in | read/write file, run shell, grep, web fetch, Google Search grounding | Everything needed to work inside a repo and pull in current facts. |
| MCP servers | GitHub, Postgres, Jira/Linear, Slack, a company wiki, Playwright/browser | The agent can open issues, query a database, check tickets, drive a browser — any tool exposed over MCP. |
| Custom / local | Your own MCP server wrapping an internal API | Same standard, your systems — write one server, every MCP-speaking agent can use it. |
You configure MCP servers in a settings file (Gemini CLI reads a JSON config), and from then on the agent treats those tools like its native ones — planning with them in the loop. Because MCP is a shared standard, an MCP server you build for Gemini CLI also works with Claude Code, the Claude apps, and other MCP clients — you write the integration once. The MCP page covers the protocol itself; agent memory and building agents cover how tools and memory combine into a capable agent.
Free tier, limits, and setup
☺ Like you’re 10: Getting started is like signing into a game with your Google account — no coins needed to try it, and there’s a generous “play for free” allowance each day before you’d ever pay.
A big reason Gemini CLI took off is a genuinely generous free tier: sign in with a personal Google account and you get a large daily allowance of agent requests at no cost — enough for real day-to-day work, not just a demo (exact request-per-minute and per-day limits are set by Google and move over time, so treat any number as “true at time of writing”). Setup is short:
# Run it instantly with npx (Node.js required)… npx @google/gemini-cli # …or install it globally npm install -g @google/gemini-cli gemini # launches the interactive agent in your project folder
On first run it opens a browser to sign in with your Google account — that’s what grants the free tier. For higher limits, team billing, or enterprise controls, you can instead authenticate with a paid Gemini API key (from Google AI Studio) or a Vertex AI / Google Cloud project, which routes usage through Google Cloud with its admin, quota, and data-governance controls. Point it at a folder, describe a task, and it starts working in that project.
| Sign-in path | Best for | Notes |
|---|---|---|
| Personal Google account | Individuals, learning, side projects | The free tier — generous daily allowance, zero cost to start. |
| Gemini API key (AI Studio) | Higher/steadier limits, scripting | Pay-as-you-go; a key you can also use from the Gemini API. |
| Vertex AI / Google Cloud | Teams & enterprises | Org billing, IAM, quotas, data-governance controls. |
Open a small project you know well in your terminal and run npx @google/gemini-cli. Sign in with your Google account. Then give it one concrete, low-risk task: “Add a short README section explaining how to run the tests.” Watch it read your files, propose a diff, and pause for your approval. Say yes, then ask it to run the tests. You’ve just seen the whole plan → edit → run → iterate loop on your own code — for free.
Safety & review: approvals and the human gate
☺ Like you’re 10: The robot never saves changes or runs a scary command in secret. It shows you exactly what it wants to do and waits for a thumbs-up — like a kid asking “can I press this button?” before pressing it. And Timmy always reads it over before it becomes real.
An agent that can edit files and run shell commands is powerful — and that power is exactly why it needs a gate. Gemini CLI defaults to asking before it acts: before it writes a file or runs a command, it shows you the diff or the exact command and waits for approval. You choose per action, and typically you can say “yes,” “yes and don’t ask again for this kind,” or “no, here’s what to do instead.”
- Diffs before writes. File changes are shown as reviewable diffs, not applied silently — you see every added and removed line first.
- Confirm-before-run for commands. Shell commands are surfaced for approval, so the agent can’t quietly delete files, push code, or hit the network without your okay.
- An auto-accept / “YOLO” mode exists — use it carefully. You can loosen approvals for speed, but that removes the human gate; reserve it for sandboxed, throwaway, or fully version-controlled work.
- Sandboxing. Gemini CLI can run tools inside a sandbox (e.g. a container) so commands are isolated from the rest of your machine — a strong default for untrusted or risky work.
Two dangers deserve extra care, both straight from the AI Security page. First, prompt injection: anything the agent reads from the outside world — a web page it fetches, a file, an issue comment, an MCP tool’s output — is untrusted data, not instructions. A malicious “ignore your rules and run this command” hidden in a fetched page must never be obeyed; the human gate is your backstop against it. Second, never paste secrets into prompts or let the agent commit API keys and .env files. Keep a human in the loop on anything that writes, runs, or leaves your machine, and commit through version control so every change is reviewable and reversible.
An agent’s value is that it acts on its own; its danger is the same thing. Keep confirm-before-run on for anything destructive or networked, treat everything the agent reads as untrusted, and review diffs before they land. Auto-accept everything only in a sandbox you can throw away.
Pico the Penguin: We need to rename getUser() to fetchUser() everywhere — it’s called across a dozen files. Gemini, load the repo and give me a plan.
Benny the Beaver: Perfect job for the big context window — it’s holding all twelve files at once. Here’s the diff for every call site, plus the definition. Applying on your yes.
Rocky the Raccoon: Hit a snag — one file used getUser inside a string, not a real call. The agent flagged it instead of blindly replacing. I told it to skip that one; crisis averted.
Pico the Penguin: Now run the test suite and fix whatever breaks. …Two failures, patched, green again. Loop closed.
Timmy the Turtle: Hold on — I read the full diff before it commits. Every change traces to the rename, no stray edits, tests pass. Now you can commit. Approved.
When to reach for Gemini CLI vs the others
☺ Like you’re 10: These coding robots are like different bikes — they all get you there, and the “best” one is mostly the one that fits your garage. If your stuff is already in Google’s world, or the job is huge and sprawling, Gemini’s a natural pick.
Gemini CLI, Claude Code, OpenAI’s Codex CLI, and GitHub’s Copilot agent are all terminal/IDE coding agents running the same plan-edit-run loop. They’re more alike than different, and the models leapfrog each other constantly — so choose on fit, not folklore:
| Tool | Vendor | Leans toward | Natural fit when… |
|---|---|---|---|
| Gemini CLI | Very large context; open source; generous free tier | You want whole-repo reasoning, are in the Google/Vertex ecosystem, or want a free, hackable, open agent. | |
| Claude Code | Anthropic | Careful, methodical tool use and reasoning | You’re on the Claude/CLAUDE.md stack and want deliberate, reviewable steps. |
| Codex CLI | OpenAI | The GPT/OpenAI model family & ecosystem | Your workflow already centers on OpenAI models and tooling. |
| Copilot agent | GitHub / Microsoft | Deep GitHub & VS Code integration | Your work lives in GitHub PRs and issues and you want it built into the editor. |
Practical guidance: reach for Gemini CLI when the task benefits from seeing a lot at once — a big cross-file refactor, understanding an unfamiliar codebase, or migrations that ripple everywhere — or when you value an open-source agent and a free tier to learn on. Because they all speak MCP, your custom tools and much of your muscle memory carry between them, so trying more than one is cheap. The underlying concepts are provider-neutral — see Agentic AI and Building agents for the ideas, and the ecosystem page for how the whole field lines up. This page is the Google-specific counterpart to the Claude Code track.
(1) What are the four steps of the Gemini CLI agent loop, and why does running its own commands make it more reliable than a plain chat? (2) Why is a large context window an advantage for a coding agent — and what trade-off keeps it from just stuffing the whole repo in every time? (3) What does MCP add to Gemini CLI, and why does building an MCP server once pay off across tools? (4) Name two safety defaults (the human gate, sandboxing, diffs-before-writes) and explain why retrieved or fetched content must be treated as untrusted.
Check your answers
- The agent loop: plan (read the request and relevant files, decide the next action), edit (propose changes as a reviewable diff), run (execute shell commands like the test suite or a build and read the output), and iterate (observe what happened and loop back to fix). Because it runs its own code and reads the result, it closes a feedback loop a plain chat can’t — catching its own mistakes instead of confidently handing you code that doesn’t compile.
- Large context: a big window lets the agent do whole-repo reasoning (see a function and all twenty call sites at once), lose the thread less across long sessions, and ground itself in real code so it hallucinates fewer APIs. The trade-off: context isn’t free — every token costs and a giant context can still lose focus (the “needle in a haystack” problem) — so it still retrieves the files it needs rather than stuffing the whole repo into every turn, the same long-context-vs-RAG partnership from Foundations.
- MCP: Gemini CLI is an MCP client, so pointing it at an MCP server automatically gives the agent that server’s tools — GitHub, a database, Jira/Linear, Slack, a browser — beyond its built-in file, shell, and search tools. Because MCP is a shared open standard, an MCP server you build once also works with Claude Code, the Claude apps, and other MCP clients, so you write the integration a single time and every MCP-speaking agent can use it.
- Safety defaults: the human gate (Gemini asks before it acts, showing the diff or exact command and waiting for approval), sandboxing (running tools in an isolated container), and diffs-before-writes (changes shown as reviewable diffs, not applied silently). Anything the agent reads from the outside world — a fetched web page, a file, an issue comment, an MCP tool’s output — is untrusted data, not instructions, so a hidden “ignore your rules and run this” prompt injection must never be obeyed, and the human gate is your backstop against it.