An open-source AI agent that brings the power of Gemini directly into your terminal.
Find a file
Sandy Tao ddc6a7465b refactor(memory): replace MemoryManagerAgent with prompt-driven memory editing across four tiers
The MemoryManagerAgent was a save_memory subagent that was slow, spent many turns on simple operations, and offered little visibility into how memories were being updated. Reshape experimental.memoryManager to remove the subagent and let the main agent persist memories itself by editing markdown files directly across four explicit tiers — each fact lives in exactly one tier:

- **Project Instructions** (`./GEMINI.md`): team-shared architecture/conventions/workflows, committed to the repo.
- **Subdirectory Instructions** (e.g. `./src/GEMINI.md`): scoped to one part of the project, committed.
- **Private Project Memory** (`~/.gemini/tmp/<hash>/memory/MEMORY.md` + sibling `*.md` notes): personal-to-the-user, project-specific notes that never get committed.
- **Global Personal Memory** (`~/.gemini/GEMINI.md`): cross-project personal preferences that follow the user into every workspace.

Core changes:

- Delete MemoryManagerAgent and its registration. The agent and its test file are removed entirely. The built-in MemoryTool remains suppressed by the flag (unchanged), so save_memory is still gone when the flag is on — the agent now handles memory persistence directly via edit/write_file.

- Rewrite the operational system prompt branch (snippets.ts and snippets.legacy.ts) to teach the main agent the four-tier model. snippets.ts adds explicit per-tier routing rules with concrete cue phrases, a one-tier-per-fact mutual-exclusion rule that explicitly covers all four tiers, and a tightly scoped MEMORY.md role (index for sibling *.md notes only, never a pointer to any GEMINI.md). snippets.legacy.ts (a frozen historical snapshot per packages/core/GEMINI.md) gets the structural three-tier rewrite only — no new prompt-engineering verbiage, no Global Personal tier.

- Surface both the Private Project Memory file (~/.gemini/tmp/<hash>/memory/MEMORY.md) and the Global Personal Memory file (~/.gemini/GEMINI.md) to the prompt only when memoryManagerEnabled is true. The Private bullet only renders when userProjectMemoryPath is provided; the Global bullet + cross-project routing rule only renders when globalMemoryPath is provided. Legacy callers that don't pass either path get a sensible 2-tier prompt.

- Extend Config.isPathAllowed with a surgical allowlist for ~/.gemini/GEMINI.md so the agent can edit the global personal memory file via edit/write_file. Critically, this is **least-privilege**: an exact-path comparison against `Storage.getGlobalGeminiDir() + getCurrentGeminiMdFilename()`, so settings.json, keybindings.json, oauth_creds.json, and the rest of ~/.gemini/ remain unreachable. The workspace context itself is still NOT broadened to include ~/.gemini/.

- Introduce PROJECT_MEMORY_INDEX_FILENAME = 'MEMORY.md' and rename getProjectMemoryFilePath -> getProjectMemoryIndexFilePath. Split memoryTool's append logic into computeGlobalMemoryContent (preserves the legacy '## Gemini Added Memories' header behavior) and computeProjectMemoryContent (plain bullet append, no header) routed by the scope parameter. Extract sanitizeFact for reuse.

- memoryDiscovery.getUserProjectMemoryPaths prefers MEMORY.md, falling back to a legacy GEMINI.md in the same folder so projects that have not been migrated still load their existing private memory.

- Update settingsSchema.ts (rename label to 'Memory Manager', rewrite description to reflect the 4-tier model and the surgical ~/.gemini/GEMINI.md allowlist) and regenerate schemas/settings.schema.json plus the auto-generated settings docs (docs/cli/settings.md, docs/reference/configuration.md).

Tests and evals:

- snippets-memory-manager.test.ts: assert the new memoryManager-mode prompt structure, including the conditional Private Project Memory bullet, the conditional Global Personal Memory bullet + cross-project routing rule, the per-tier routing block, the four-tier mutual-exclusion rule, and the scoped MEMORY.md role.

- config.test.ts: keep the existing negative test that workspace context does NOT broaden to ~/.gemini/, and add two new tests around the surgical isPathAllowed allowlist — a positive case (~/.gemini/GEMINI.md is allowed) and a least-privilege case (settings.json, keybindings.json, oauth_creds.json under ~/.gemini/ remain disallowed).

- memoryTool.test.ts: cover the new project-scope content path (no header, plain bullet append).

- save_memory.eval.ts:
  * Update the proactive long-session eval so it now asserts the "I always prefer Vitest ... in all my projects" preference is routed to the global personal memory file (its correct destination under the 4-tier model), and is NOT mirrored into a committed project GEMINI.md or the private project memory folder.
  * Add an eval verifying that team-shared project conventions ("our project uses X", "the team always Y") route to the project-root ./GEMINI.md and are NOT mirrored into the private memory folder (the mutual-exclusion guarantee).
  * Add an eval verifying that personal-to-user project notes ("on my machine", "do not commit this") route to the private project memory folder, with substantial detail captured in a sibling *.md note and MEMORY.md updated as the index.
  * Add an eval verifying that cross-project personal preferences ("across all my projects", "I always prefer X", "in every workspace") route to the global ~/.gemini/GEMINI.md and are NOT mirrored into a committed project GEMINI.md or the private memory folder.

Validation: lint, typecheck, the affected unit tests in @google/gemini-cli-core (snippets-memory-manager.test.ts, memoryTool.test.ts, config.test.ts, promptProvider.test.ts — 267/267 pass), the schema/docs in-sync check tests, and the full save_memory.eval.ts suite (15/15 pass) all pass. 10x reliability loops on all four memoryManager-mode evals are 10/10 against the final prompt (40/40 total).

Security hardening (PR review feedback):

- sanitizeFact (memoryTool.ts) now also collapses `<` and `>` to spaces. Without this, a malicious fact (or a malicious repo's MEMORY.md content surfaced through save_memory) could carry an XML closing tag like `</user_project_memory>` past the existing newline/markdown sanitization, get persisted to disk, and on every future session that loads the memory file the renderUserMemory injection would let the payload break out of the surrounding context block. Symmetric with the existing newline collapse, minimal content loss for typical durable preferences. memoryTool.test.ts adds an explicit XML-tag-breakout test case asserting the payload is neutralised end-to-end (write_file content + success message).

CI fix:

- path-validation.test.ts: the existing test "should allow access to ~/.gemini if it is added to the workspace" used `~/.gemini/GEMINI.md` as its example file to demonstrate the workspace-addition semantic, but that file is now reachable unconditionally via the new surgical isPathAllowed allowlist. Switch the example to `~/.gemini/settings.json` (NOT on the allowlist), preserving the original "denied -> add to workspace -> allowed" flow the test was written to verify, and double-asserting the least-privilege guarantee that the allowlist does not leak access to other files under ~/.gemini/. Rename the test to reflect the more general intent.
2026-04-20 16:33:11 -07:00
.allstar Downgrade branch_protection to log (#2934) 2025-08-26 11:24:24 +00:00
.gcp feat(gcp): add development worker infrastructure (#23814) 2026-03-26 19:01:37 +00:00
.gemini docs: migrate installation and authentication to mdx with tabbed layouts (#25155) 2026-04-17 18:07:07 +00:00
.github fix(evals): add typecheck coverage for evals, integration-tests, and memory-tests (#25480) 2026-04-16 18:20:27 +00:00
.husky fix(pre-commit): improve monorepo handling and failure messaging (#9123) 2025-09-23 15:57:24 +00:00
.vscode chore(dev): update vscode settings for typescriptreact (#19907) 2026-03-04 16:25:33 +00:00
docs refactor(memory): replace MemoryManagerAgent with prompt-driven memory editing across four tiers 2026-04-20 16:33:11 -07:00
evals refactor(memory): replace MemoryManagerAgent with prompt-driven memory editing across four tiers 2026-04-20 16:33:11 -07:00
integration-tests fix(evals): add typecheck coverage for evals, integration-tests, and memory-tests (#25480) 2026-04-16 18:20:27 +00:00
memory-tests fix(evals): add typecheck coverage for evals, integration-tests, and memory-tests (#25480) 2026-04-16 18:20:27 +00:00
packages refactor(memory): replace MemoryManagerAgent with prompt-driven memory editing across four tiers 2026-04-20 16:33:11 -07:00
perf-tests feat(test): add large conversation scenario for performance test (#25331) 2026-04-15 18:08:43 +00:00
schemas refactor(memory): replace MemoryManagerAgent with prompt-driven memory editing across four tiers 2026-04-20 16:33:11 -07:00
scripts fix(extensions): fix bundling for examples (#25542) 2026-04-16 19:11:03 +00:00
sea Unused error variables in catch block are not allowed (#24487) 2026-04-02 04:33:07 +00:00
third_party/get-ripgrep Fix Windows ripgrep detection (#11492) 2025-10-20 23:17:44 +00:00
.editorconfig chore: add .editorconfig (#2572) 2025-06-29 19:40:32 +00:00
.geminiignore feat(core): implement native Windows sandboxing (#21807) 2026-03-19 22:25:22 +00:00
.gitattributes Adding .gitattributes (#1303) 2025-06-23 06:58:41 +00:00
.gitignore feat(test-utils): add CPU performance integration test harness (#24951) 2026-04-08 21:50:29 +00:00
.lycheeignore Fix broken links in documentation (#11789) 2025-10-23 13:48:24 +00:00
.npmrc fix: prepublish changes to package names (#1420) 2025-06-25 12:41:11 +00:00
.nvmrc chore: Expand node version test matrix (#2700) 2025-07-21 16:33:54 -07:00
.prettierignore docs: migrate installation and authentication to mdx with tabbed layouts (#25155) 2026-04-17 18:07:07 +00:00
.prettierrc.json cleanup(markdown): Prettier format all markdown @ 80 char width (#10714) 2025-10-09 12:17:37 +00:00
.yamllint.yml Release Process vNext (#8152) 2025-09-10 08:28:58 +00:00
CONTRIBUTING.md docs(contributing): clarify self-assignment policy for issues (#23087) 2026-04-13 17:15:54 +00:00
Dockerfile fix(sandbox): harden image packaging integrity checks (#19552) 2026-02-23 21:02:42 +00:00
esbuild.config.js chore: switch from keytar to @github/keytar (#25143) 2026-04-10 21:20:26 +00:00
eslint.config.js Unused error variables in catch block are not allowed (#24487) 2026-04-02 04:33:07 +00:00
GEMINI.md feat(test-utils): add CPU performance integration test harness (#24951) 2026-04-08 21:50:29 +00:00
LICENSE Revert to default LICENSE (Revert #13449) (#13876) 2025-11-27 02:23:08 +00:00
Makefile Fix duplicate help text for build targets in Makefile (#4092) 2025-07-14 04:42:07 +00:00
package-lock.json fix(extensions): fix bundling for examples (#25542) 2026-04-16 19:11:03 +00:00
package.json fix(extensions): fix bundling for examples (#25542) 2026-04-16 19:11:03 +00:00
README.md Update README.md for links. (#22759) 2026-04-01 19:15:44 +00:00
ROADMAP.md cleanup(markdown): Prettier format all markdown @ 80 char width (#10714) 2025-10-09 12:17:37 +00:00
SECURITY.md cleanup(markdown): Prettier format all markdown @ 80 char width (#10714) 2025-10-09 12:17:37 +00:00
tsconfig.json Explict imports & exports with type modifier (#3774) 2025-08-25 22:04:53 +00:00

Gemini CLI

Gemini CLI CI Gemini CLI E2E (Chained) Version License View Code Wiki

Gemini CLI Screenshot

Gemini CLI is an open-source AI agent that brings the power of Gemini directly into your terminal. It provides lightweight access to Gemini, giving you the most direct path from your prompt to our model.

Learn all about Gemini CLI in our documentation.

🚀 Why Gemini CLI?

  • 🎯 Free tier: 60 requests/min and 1,000 requests/day with personal Google account.
  • 🧠 Powerful Gemini 3 models: Access to improved reasoning and 1M token context window.
  • 🔧 Built-in tools: Google Search grounding, file operations, shell commands, web fetching.
  • 🔌 Extensible: MCP (Model Context Protocol) support for custom integrations.
  • 💻 Terminal-first: Designed for developers who live in the command line.
  • 🛡️ Open source: Apache 2.0 licensed.

📦 Installation

See Gemini CLI installation, execution, and releases for recommended system specifications and a detailed installation guide.

Quick Install

Run instantly with npx

# Using npx (no installation required)
npx @google/gemini-cli

Install globally with npm

npm install -g @google/gemini-cli

Install globally with Homebrew (macOS/Linux)

brew install gemini-cli

Install globally with MacPorts (macOS)

sudo port install gemini-cli

Install with Anaconda (for restricted environments)

# Create and activate a new environment
conda create -y -n gemini_env -c conda-forge nodejs
conda activate gemini_env

# Install Gemini CLI globally via npm (inside the environment)
npm install -g @google/gemini-cli

Release Channels

See Releases for more details.

Preview

New preview releases will be published each week at UTC 23:59 on Tuesdays. These releases will not have been fully vetted and may contain regressions or other outstanding issues. Please help us test and install with preview tag.

npm install -g @google/gemini-cli@preview

Stable

  • New stable releases will be published each week at UTC 20:00 on Tuesdays, this will be the full promotion of last week's preview release + any bug fixes and validations. Use latest tag.
npm install -g @google/gemini-cli@latest

Nightly

  • New releases will be published each day at UTC 00:00. This will be all changes from the main branch as represented at time of release. It should be assumed there are pending validations and issues. Use nightly tag.
npm install -g @google/gemini-cli@nightly

📋 Key Features

Code Understanding & Generation

  • Query and edit large codebases
  • Generate new apps from PDFs, images, or sketches using multimodal capabilities
  • Debug issues and troubleshoot with natural language

Automation & Integration

  • Automate operational tasks like querying pull requests or handling complex rebases
  • Use MCP servers to connect new capabilities, including media generation with Imagen, Veo or Lyria
  • Run non-interactively in scripts for workflow automation

Advanced Capabilities

  • Ground your queries with built-in Google Search for real-time information
  • Conversation checkpointing to save and resume complex sessions
  • Custom context files (GEMINI.md) to tailor behavior for your projects

GitHub Integration

Integrate Gemini CLI directly into your GitHub workflows with Gemini CLI GitHub Action:

  • Pull Request Reviews: Automated code review with contextual feedback and suggestions
  • Issue Triage: Automated labeling and prioritization of GitHub issues based on content analysis
  • On-demand Assistance: Mention @gemini-cli in issues and pull requests for help with debugging, explanations, or task delegation
  • Custom Workflows: Build automated, scheduled and on-demand workflows tailored to your team's needs

🔐 Authentication Options

Choose the authentication method that best fits your needs:

Option 1: Sign in with Google (OAuth login using your Google Account)

Best for: Individual developers as well as anyone who has a Gemini Code Assist License. (see quota limits and terms of service for details)

Benefits:

  • Free tier: 60 requests/min and 1,000 requests/day
  • Gemini 3 models with 1M token context window
  • No API key management - just sign in with your Google account
  • Automatic updates to latest models

Start Gemini CLI, then choose Sign in with Google and follow the browser authentication flow when prompted

gemini

If you are using a paid Code Assist License from your organization, remember to set the Google Cloud Project

# Set your Google Cloud Project
export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
gemini

Option 2: Gemini API Key

Best for: Developers who need specific model control or paid tier access

Benefits:

  • Free tier: 1000 requests/day with Gemini 3 (mix of flash and pro)
  • Model selection: Choose specific Gemini models
  • Usage-based billing: Upgrade for higher limits when needed
# Get your key from https://aistudio.google.com/apikey
export GEMINI_API_KEY="YOUR_API_KEY"
gemini

Option 3: Vertex AI

Best for: Enterprise teams and production workloads

Benefits:

  • Enterprise features: Advanced security and compliance
  • Scalable: Higher rate limits with billing account
  • Integration: Works with existing Google Cloud infrastructure
# Get your key from Google Cloud Console
export GOOGLE_API_KEY="YOUR_API_KEY"
export GOOGLE_GENAI_USE_VERTEXAI=true
gemini

For Google Workspace accounts and other authentication methods, see the authentication guide.

🚀 Getting Started

Basic Usage

Start in current directory

gemini

Include multiple directories

gemini --include-directories ../lib,../docs

Use specific model

gemini -m gemini-2.5-flash

Non-interactive mode for scripts

Get a simple text response:

gemini -p "Explain the architecture of this codebase"

For more advanced scripting, including how to parse JSON and handle errors, use the --output-format json flag to get structured output:

gemini -p "Explain the architecture of this codebase" --output-format json

For real-time event streaming (useful for monitoring long-running operations), use --output-format stream-json to get newline-delimited JSON events:

gemini -p "Run tests and deploy" --output-format stream-json

Quick Examples

Start a new project

cd new-project/
gemini
> Write me a Discord bot that answers questions using a FAQ.md file I will provide

Analyze existing code

git clone https://github.com/google-gemini/gemini-cli
cd gemini-cli
gemini
> Give me a summary of all of the changes that went in yesterday

📚 Documentation

Getting Started

Core Features

Tools & Extensions

Advanced Topics

Troubleshooting & Support

  • Troubleshooting Guide - Common issues and solutions.
  • FAQ - Frequently asked questions.
  • Use /bug command to report issues directly from the CLI.

Using MCP Servers

Configure MCP servers in ~/.gemini/settings.json to extend Gemini CLI with custom tools:

> @github List my open pull requests
> @slack Send a summary of today's commits to #dev channel
> @database Run a query to find inactive users

See the MCP Server Integration guide for setup instructions.

🤝 Contributing

We welcome contributions! Gemini CLI is fully open source (Apache 2.0), and we encourage the community to:

  • Report bugs and suggest features.
  • Improve documentation.
  • Submit code improvements.
  • Share your MCP servers and extensions.

See our Contributing Guide for development setup, coding standards, and how to submit pull requests.

Check our Official Roadmap for planned features and priorities.

📖 Resources

Uninstall

See the Uninstall Guide for removal instructions.


Built with ❤️ by Google and the open source community