Google Gemini CLI Tutorial: Build Apps From Terminal (2027 Guide)

Natural daylight photograph of an aluminum laptop running a dark terminal workflow beside a second monitor, mechanical keyboard, and coffee mug.

Copying code blocks out of a browser chatbot, pasting snippets into VS Code, hitting a terminal stack trace, and pasting errors back into Chrome wastes half your coding momentum. Google Gemini CLI puts an open-source, autonomous engineering agent directly inside your terminal—reading entire repositories, drafting architecture blueprints, running unit tests, and tracking every token without leaving your command line.

Quick Summary: Google Gemini CLI (2027 Guide)

Install Google Gemini CLI via npm install -g @google/gemini-cli, authenticate free with a Google account or AI Studio key, switch to Flash Lite via /model for snappy 2-second turns, plan builds safely using /plan, persist repo rules inside GEMINI.md, and audit live cache and token counts on exit.

In this hands-on 2027 walkthrough—adapted from SquareBrackets’ comprehensive Gemini CLI terminal build alongside the official Google Gemini CLI GitHub repository and Gemini CLI documentation—we walk step by step from installation to shipping, testing, debugging, and optimizing token usage. If you are weighing terminal agents against visual editors, check our Claude Code vs Cursor workflow guide and Cursor AI beginner tutorial too.

Full video walkthrough by SquareBrackets (24:53) covering installation, Google AI Studio API authentication, Flash Lite speed tuning, /plan mode, automated npm test execution, and GEMINI.md context persistence.

TimestampTutorial ChapterWhat You Configure & Learn
00:00What Is Gemini CLI?Difference between passive chat copy-pasting and autonomous terminal agents
01:30Installation (Node.js + npm)Verifying Node.js and running global @google/gemini-cli setup
02:33Authentication & Free API KeyChoosing Google Login vs Google AI Studio API Key vs Vertex AI
04:14Switch to Flash Lite (/model)Fixing 15-second slow auto replies with instant Flash Lite selection
05:36Project Requirements SetupCreating project directories manually to avoid burning tokens
09:08Plan Mode (/plan)Reviewing multi-phase architecture plans before touching any files
12:25Phase Build & npm test LoopAccepting scoped tool permissions and executing unit tests
17:44Codebase Onboarding & DebuggingAnalyzing unfamiliar repos and catching subtle syntax bugs
21:11GEMINI.md & Exit Token TelemetryPersisting context rules and inspecting cache hit stats via /quit

Chatbot vs. CLI Agent: Why Developers Move Into the Terminal

A browser chatbot acts strictly as an advisor: it prints code snippets into a web window while you handle file creation, imports, test runners, and error tracing. By contrast, Google’s open-source agent launched in Google’s official Gemini CLI developer announcement runs locally inside your shell environment with tool-calling permissions.

That distinction unlocks four immediate capabilities for everyday engineering:

  • Direct Workspace File I/O: Reads, searches (grep), creates, and patches multi-file JavaScript, Python, HTML/CSS, and config files directly inside your repository.
  • Live Shell & Test Execution: Runs npm test, build scripts, or linters under explicit permission prompts and reads stderr logs to fix its own mistakes.
  • External Web & MCP Integration: Searches documentation live or connects to local Model Context Protocol servers alongside workflows covered in our n8n modular skills and MCP guide.
  • Zero-Cost Entry Tier: Works out of the box with a standard Google login before spending a single dollar on API billing.

Prerequisites Before Starting

  • Node.js 20+ and npm: Installed cleanly on macOS, Windows PowerShell, or Linux (`node -v` to confirm).
  • Terminal or VS Code Integrated Terminal: Any shell works; VS Code lets you watch code diffs open side-by-side live.
  • Google Account or Google AI Studio Key: Standard personal Gmail login unlocks the free tier, or generate a key inside Google AI Studio.

Step 1: Install Google Gemini CLI Globally via npm

Open your terminal inside VS Code or your OS shell, verify Node.js is ready, and install the official @google/gemini-cli package globally so the gemini command works inside any project directory:

# Verify Node.js version (v20+ recommended)
node -v

# Install Google Gemini CLI globally
npm install -g @google/gemini-cli

# Launch interactive session inside your project root
gemini

Prefer zero global installation for quick tests? Run npx @google/gemini-cli directly instead—ideal on locked corporate laptops.

Step 2: Configure Authentication (Free Login vs. AI Studio API Key)

On first launch—or anytime later by typing /auth inside the prompt bar—Gemini CLI presents three authentication options:

Auth MethodSetup SpeedCost & Quota Tier (2027)Best Use Case
1. Login with GoogleInstant OAuth browser popupFree ($0 / ₹0) — high daily capSolo developers, students, daily side projects
2. Gemini API Key (AI Studio)Copy-paste env/UI keyFree rate-limited tier or pay-per-tokenExplicit model switching, reproducible billing & CI
3. Vertex AIGCP project IAM setupEnterprise Google Cloud billingCorporate security compliance & data residency

For rapid prototyping without touching Google Cloud IAM, pick Login with Google for zero-cost exploration, or grab a free Gemini API Key inside Google AI Studio when you want fine-grained control over Flash Lite and Pro previews.

Step 3: Fix Slow First Replies Using /model (Switch to Flash Lite)

Here is the #1 beginner snag you will hit within your first sixty seconds: leaving Gemini CLI on default auto model routing. Because auto frequently routes simple greetings or file reads through heavy Pro reasoning passes, straightforward prompts can hang for 15–20 seconds.

Fix that latency bottleneck immediately by typing /model and pressing Enter:

Annotated Gemini CLI /model menu highlighting gemini-3.5-flash-lite and persistence flag
Step 3 in practice: Run /model, select a fast Flash Lite model for responsive ~2-second terminal iterations, and press Tab to remember your selection across sessions.

Look closely at two helpful shortcuts visible inside that selector:

  1. Toggle Flash Lite (`gemini-3.5-flash-lite` or `gemini-3-flash-preview` depending on your account roster) when doing rapid exploration, boilerplate generation, or CSS tweaks—response times drop from 15 seconds down to ~2–3 seconds.
  2. Press Tab to toggle Remember model for future sessions to true, or launch directly from shell with gemini --model gemini-3.5-flash-lite.

Step 4: Prepare Clean Requirements & Lock Architecture With /plan Mode

Avoid asking an AI CLI agent to create empty folders and guess an open-ended project stack in a single messy prompt—every shell round-trip burns input tokens unnecessarily. Create your project folder manually first (`mkdir gemini-task-manager && cd gemini-task-manager`), then drop a concise specification file named req.txt inside the root:

Project Requirements: Task Manager App
1. Add a task with title and optional description.
2. List all tasks with unique generated IDs.
3. Mark any task as completed and filter by All / Active / Completed.
4. Delete a task cleanly by ID.
5. Persist task data reliably in browser localStorage.
6. Use modular ES6 JavaScript, JSDoc type hints, error handling, and OOP classes.
7. Create automated unit tests covering core manager logic.
8. Include a README.md with installation and usage steps.

Tech Stack:
- HTML5
- CSS3
- Vanilla JavaScript (no React build step)

Notice specifying vanilla HTML5/CSS3/JS prevents the agent from defaulting into a bloated 400MB node_modules framework stack you did not request. Now trigger Gemini CLI’s built-in Plan Mode before letting it create a single source file:

Annotated VS Code workspace showing req.txt specification above Gemini CLI running /plan mode
Step 4: Prefixing your prompt with /plan forces Gemini CLI to inspect req.txt via read/grep tools and propose a complete phase-by-phase file blueprint before editing code.
/plan create an implementation plan for requirement written in the file req.txt

Gemini CLI scans req.txt, maps out the exact folder tree (`src/Task.js`, `src/TaskManager.js`, `src/app.js`, `tests/TaskManager.test.js`, `index.html`, `styles.css`, `package.json`, `README.md`), splits execution into discrete phases, and pauses to ask: Does this plan look good to you? Read every line carefully—this review gate catches wrong libraries and missing unit tests while fixing anything is still free.

Step 5: Execute Phase-by-Phase With Safe Permissions & Automated Testing

Never turn blind auto-execution on for unfamiliar tasks. Approve implementation phase-by-phase (Let's start with Phase 1 — stop after each phase for review), or use Shift + Tab to toggle controlled auto-accept edits strictly on safe greenfield scaffolds while confirming shell runs (npm test) individually.

Inside our test workflow, Gemini CLI wrote the modular domain classes (Task and TaskManager), generated DOM bindings in index.html and styles.css, created unit tests in tests/TaskManager.test.js, requested shell confirmation to run npm test, and verified all 11 core tests passed before declaring the app ready to preview.

Step 6: Onboard to Unfamiliar Codebases & Debug Failing Tests

Where terminal agents truly earn their keep isn’t just toy greenfield apps—it is jumping cold into an unfamiliar repository or debugging cryptic test failures. Open a clean terminal inside any inherited codebase and paste these two prompts:

# Prompt A: Instant Repository Onboarding Map
Analyze this project and explain its folder structure, the purpose of each important file, and how data flows from startup to test execution.

# Prompt B: Root-Cause Unit Test Debugging
Run the test suite, investigate the failing assertions, pinpoint the exact file and line root cause, and propose the minimal fix.

During the SquareBrackets demo test—after injecting a deliberate typo referencing singular task instead of plural tasks on line 14—Gemini CLI re-ran tests, saw 7 tests fail out of 11, traced the exact broken property mismatch in TaskManager.js, and proposed the exact single-word patch within seconds.

Step 6B: Connect External MCP Servers (~/.gemini/settings.json)

Once local file editing clicks, the next power multiplier in Google Gemini CLI is the Model Context Protocol (MCP). Instead of copying database schemas, GitHub pull requests, or browser console errors manually into your terminal, MCP servers expose live external tools straight to Gemini CLI inside a single workspace.

To wire up a local filesystem or GitHub MCP bridge—following the same principles explained in our step-by-step MCP integration guide for AI agents—create or edit ~/.gemini/settings.json (or your project-level .gemini/settings.json) like this:

{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "YOUR_SCOPED_TOKEN"
      }
    },
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/dev_db"]
    }
  }
}

Restart gemini and type /mcp to verify every connected server’s health status and exposed tool count. One crucial 2027 hygiene tip: keep inactive MCP servers commented out or scoped strictly to project-level config files, because every registered MCP tool schema counts toward initial context tokens on startup.

Step 7: Persist Rules With GEMINI.md & Audit Exit Token Telemetry

Without persistent memory, every new developer or fresh terminal window forces Gemini CLI to scan your whole codebase from scratch—spending 100,000+ input tokens repeatedly on files that haven’t changed. Fix that permanently by telling the agent to generate a root GEMINI.md rules file:

Create a GEMINI.md file at the project root persisting this architecture overview, folder structure, mandatory OOP + JSDoc rules, and npm test verification commands.

Next time anyone runs gemini inside that folder, the agent reads GEMINI.md automatically as its single source of truth. Even better, look what happens the instant you type /quit at the end of a session:

Annotated VS Code window showing GEMINI.md rules alongside Gemini CLI /quit performance and token usage breakdown
Step 7: On exit (/quit), Gemini CLI prints exact tool success rate, wall vs API time, cache-read token savings, and your one-line gemini –resume command.

That built-in session audit panel solves one of the biggest headaches in terminal AI coding—showing exact Input Tokens (154,267), Cache Reads (99,515), Output Tokens (1,570), active API vs. local tool time, plus the exact gemini --resume <uuid> command so you never lose session context.

Real Workflow Test & Limitations (2027 Pricing in USD & INR)

After putting Google Gemini CLI through end-to-end builds, onboarding analysis, and intentional unit-test debugging, here is the honest cost and limitation breakdown for solo builders and engineering teams heading into 2027:

  • Free Google Login Tier ($0 USD / ₹0 INR): Authenticating with a personal Google account remains one of the highest-value free tiers in developer tooling (~60 requests/min and up to 1,000 requests/day under standard consumer usage policies)—plenty for multi-file builds, refactoring sprints, and daily code reviews without a credit card.
  • Google AI Studio Pay-As-You-Go ($ USD / ₹ INR): If you switch to an API key for high-volume automation or Pro models beyond free rate limits, Flash Lite / Flash turns cost fractions of a cent per loop (~$0.01–$0.04 USD / ~₹0.85–₹3.40 INR per typical 150k cached session), while sustained Pro coding sessions remain noticeably cheaper than competing flagship terminal tools.
  • Latency Caveat (#1): Default auto model routing feels sluggish (~15s delays) on simple prompts—always switch to Flash Lite via /model for routine exploration and switch up to Pro only for gnarly multi-file debugging.
  • Permission & Security Caveat (#2): Avoid running auto-accept shell permissions inside directories holding sensitive .env secrets or production SSH configs. Use Gemini CLI’s --sandbox flag or approve shell commands manually (allow once) when running tests.
  • Token Telemetry Caveat (#3): Long unpruned sessions steadily inflate context (150k+ input tokens fast). Save durable guidelines into GEMINI.md and start clean sessions cleanly instead of dragging dead logs for hours.

Common Gemini CLI Mistakes & Quick Fixes

Symptom / ErrorWhy It HappensExact Fix
15–20 second delay on simple chat promptsDefault Auto mode selects slower heavy Pro reasoning modelType /model, select Flash Lite, press Tab to persist
Agent generates unwanted React/Next.js boilerplateTech stack left unspecified in prompt or req.txtExplicitly state stack constraints & start with /plan mode
Every new terminal wastes 100k tokens re-reading repoNo persistent repository memory file existsGenerate GEMINI.md at repo root with stack + test commands
gemini command not found after npm installGlobal npm bin directory missing from shell PATHVerify node -v / npm bin -g PATH or run npx @google/gemini-cli

If you want autonomous terminal coding with transparent token telemetry, persistent GEMINI.md memory, custom Model Context Protocol integrations, and a generous free starting tier before committing to monthly IDE subscriptions, Google Gemini CLI belongs at the center of your 2027 developer toolkit. Bookmark this workflow checklist, test /plan mode on your next greenfield utility, and inspect your first /quit cache telemetry report to see how much latency and budget disciplined context hygiene saves.

Frequently Asked Questions

Is Google Gemini CLI really free to use in 2027?

Yes. Signing in with a standard personal Google account grants free access to Google Gemini CLI with generous daily limits (60 requests per minute and up to 1,000 requests per day on Gemini’s 1M-token context tier) at $0 USD / ₹0 INR.

Why does Gemini CLI respond slowly on first run and how do I fix it?

By default, Gemini CLI leaves model routing on Auto, which often picks heavier Pro reasoning models that take 15–20 seconds per prompt. Run /model inside the prompt bar and select gemini-3.5-flash-lite (or Press Tab to remember your choice) for 2-second replies.

What is Plan Mode (/plan) in Gemini CLI?

Typing /plan before your task locks Gemini CLI into read-only planning mode. Instead of modifying source files blindly, it inspects your workspace, outputs a multi-phase architecture checklist, and asks for approval before generating code.

How does GEMINI.md save tokens across sessions?

GEMINI.md sits at your repository root and stores tech stack rules, folder layouts, coding conventions, and testing mandates. Every fresh Gemini CLI session reads GEMINI.md immediately instead of wasting tens of thousands of input tokens re-scanning your repo.

How does Gemini CLI compare to Claude Code and Cursor AI?

Cursor offers full IDE visual diffs for $20/mo and Claude Code delivers top-tier agentic reasoning via paid Anthropic tiers. Gemini CLI is open-source, lightweight in any VS Code or OS terminal, shows detailed exit token telemetry, and starts free with a Google account.

Can Gemini CLI resume previous terminal coding sessions?

Yes. Whenever you type /quit or exit Gemini CLI, the summary panel prints an exact gemini –resume command so you can restore full session context right where you stopped.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top