Gemini CLI offers several ways to configure its behavior, including environment variables, command-line arguments, and settings files. This document outlines the different configuration methods and available settings.
Configuration is applied in the following order of precedence (lower numbers are overridden by higher numbers):
.env
files.Gemini CLI uses settings.json
files for persistent configuration. There are three locations for these files:
~/.gemini/settings.json
(where ~
is your home directory)..gemini/settings.json
within your project’s root directory./etc/gemini-cli/settings.json
(Linux), C:\ProgramData\gemini-cli\settings.json
(Windows) or /Library/Application Support/GeminiCli/settings.json
(macOS). The path can be overridden using the GEMINI_CLI_SYSTEM_SETTINGS_PATH
environment variable.Note on environment variables in settings: String values within your settings.json
files can reference environment variables using either $VAR_NAME
or ${VAR_NAME}
syntax. These variables will be automatically resolved when the settings are loaded. For example, if you have an environment variable MY_API_TOKEN
, you could use it in settings.json
like this: "apiKey": "$MY_API_TOKEN"
.
.gemini
directory in your projectIn addition to a project settings file, a project’s .gemini
directory can contain other project-specific files related to Gemini CLI’s operation, such as:
.gemini/sandbox-macos-custom.sb
, .gemini/sandbox.Dockerfile
).settings.json
:contextFileName
(string or array of strings):
GEMINI.md
, AGENTS.md
). Can be a single filename or a list of accepted filenames.GEMINI.md
"contextFileName": "AGENTS.md"
bugCommand
(object):
/bug
command."urlTemplate": "https://github.com/google-gemini/gemini-cli/issues/new?template=bug_report.yml&title={title}&info={info}"
urlTemplate
(string): A URL that can contain {title}
and {info}
placeholders."bugCommand": {
"urlTemplate": "https://bug.example.com/new?title={title}&info={info}"
}
fileFiltering
(object):
"respectGitIgnore": true, "enableRecursiveFileSearch": true
respectGitIgnore
(boolean): Whether to respect .gitignore patterns when discovering files. When set to true
, git-ignored files (like node_modules/
, dist/
, .env
) are automatically excluded from @ commands and file listing operations.enableRecursiveFileSearch
(boolean): Whether to enable searching recursively for filenames under the current tree when completing @ prefixes in the prompt."fileFiltering": {
"respectGitIgnore": true,
"enableRecursiveFileSearch": false
}
coreTools
(array of strings):
ShellTool
. For example, "coreTools": ["ShellTool(ls -l)"]
will only allow the ls -l
command to be executed."coreTools": ["ReadFileTool", "GlobTool", "ShellTool(ls)"]
.excludeTools
(array of strings):
excludeTools
and coreTools
is excluded. You can also specify command-specific restrictions for tools that support it, like the ShellTool
. For example, "excludeTools": ["ShellTool(rm -rf)"]
will block the rm -rf
command."excludeTools": ["run_shell_command", "findFiles"]
.excludeTools
for run_shell_command
are based on simple string matching and can be easily bypassed. This feature is not a security mechanism and should not be relied upon to safely execute untrusted code. It is recommended to use coreTools
to explicitly select commands
that can be executed.allowMCPServers
(array of strings):
--allowed-mcp-server-names
is set."allowMCPServers": ["myPythonServer"]
.mcpServers
at the system settings level such that the user will not be able to configure any MCP servers of their own. This should not be used as an airtight security mechanism.excludeMCPServers
(array of strings):
excludeMCPServers
and allowMCPServers
is excluded. Note that this will be ignored if --allowed-mcp-server-names
is set."excludeMCPServers": ["myNodeServer"]
.mcpServers
at the system settings level such that the user will not be able to configure any MCP servers of their own. This should not be used as an airtight security mechanism.autoAccept
(boolean):
true
, the CLI will bypass the confirmation prompt for tools deemed safe.false
"autoAccept": true
theme
(string):
"Default"
"theme": "GitHub"
vimMode
(boolean):
false
"vimMode": true
sandbox
(boolean or string):
true
, Gemini CLI uses a pre-built gemini-cli-sandbox
Docker image. For more information, see Sandboxing.false
"sandbox": "docker"
toolDiscoveryCommand
(string):
stdout
a JSON array of function declarations. Tool wrappers are optional."toolDiscoveryCommand": "bin/get_tools"
toolCallCommand
(string):
toolDiscoveryCommand
. The shell command must meet the following criteria:
name
(exactly as in function declaration) as first command line argument.stdin
, analogous to functionCall.args
.stdout
, analogous to functionResponse.response.content
."toolCallCommand": "bin/call_tool"
mcpServers
(object):
serverAlias__actualToolName
) to avoid conflicts. Note that the system might strip certain schema properties from MCP tool definitions for compatibility.<SERVER_NAME>
(object): The server parameters for the named server.
command
(string, required): The command to execute to start the MCP server.args
(array of strings, optional): Arguments to pass to the command.env
(object, optional): Environment variables to set for the server process.cwd
(string, optional): The working directory in which to start the server.timeout
(number, optional): Timeout in milliseconds for requests to this MCP server.trust
(boolean, optional): Trust this server and bypass all tool call confirmations.includeTools
(array of strings, optional): List of tool names to include from this MCP server. When specified, only the tools listed here will be available from this server (whitelist behavior). If not specified, all tools from the server are enabled by default.excludeTools
(array of strings, optional): List of tool names to exclude from this MCP server. Tools listed here will not be available to the model, even if they are exposed by the server. Note: excludeTools
takes precedence over includeTools
- if a tool is in both lists, it will be excluded."mcpServers": {
"myPythonServer": {
"command": "python",
"args": ["mcp_server.py", "--port", "8080"],
"cwd": "./mcp_tools/python",
"timeout": 5000,
"includeTools": ["safe_tool", "file_reader"],
},
"myNodeServer": {
"command": "node",
"args": ["mcp_server.js"],
"cwd": "./mcp_tools/node",
"excludeTools": ["dangerous_tool", "file_deleter"]
},
"myDockerServer": {
"command": "docker",
"args": ["run", "-i", "--rm", "-e", "API_KEY", "ghcr.io/foo/bar"],
"env": {
"API_KEY": "$MY_API_TOKEN"
}
}
}
checkpointing
(object):
{"enabled": false}
enabled
(boolean): When true
, the /restore
command is available.preferredEditor
(string):
vscode
"preferredEditor": "vscode"
telemetry
(object)
{"enabled": false, "target": "local", "otlpEndpoint": "http://localhost:4317", "logPrompts": true}
enabled
(boolean): Whether or not telemetry is enabled.target
(string): The destination for collected telemetry. Supported values are local
and gcp
.otlpEndpoint
(string): The endpoint for the OTLP Exporter.logPrompts
(boolean): Whether or not to include the content of user prompts in the logs."telemetry": {
"enabled": true,
"target": "local",
"otlpEndpoint": "http://localhost:16686",
"logPrompts": false
}
usageStatisticsEnabled
(boolean):
true
"usageStatisticsEnabled": false
hideTips
(boolean):
false
Example:
"hideTips": true
hideBanner
(boolean):
false
Example:
"hideBanner": true
maxSessionTurns
(number):
-1
(unlimited)"maxSessionTurns": 10
summarizeToolOutput
(object):
tokenBudget
setting.run_shell_command
tool is supported.{}
(Disabled by default)"summarizeToolOutput": {
"run_shell_command": {
"tokenBudget": 2000
}
}
excludedProjectEnvVars
(array of strings):
.env
files. This prevents project-specific environment variables (like DEBUG=true
) from interfering with gemini-cli behavior. Variables from .gemini/.env
files are never excluded.["DEBUG", "DEBUG_MODE"]
"excludedProjectEnvVars": ["DEBUG", "DEBUG_MODE", "NODE_ENV"]
includeDirectories
(array of strings):
~
to refer to the user’s home directory. This setting can be combined with the --include-directories
command-line flag.[]
"includeDirectories": [
"/path/to/another/project",
"../shared-library",
"~/common-utils"
]
loadMemoryFromIncludeDirectories
(boolean):
/memory refresh
command. If set to true
, GEMINI.md
files should be loaded from all directories that are added. If set to false
, GEMINI.md
should only be loaded from the current directory.false
"loadMemoryFromIncludeDirectories": true
chatCompression
(object):
contextPercentageThreshold
(number): A value between 0 and 1 that specifies the token threshold for compression as a percentage of the model’s total token limit. For example, a value of 0.6
will trigger compression when the chat history exceeds 60% of the token limit."chatCompression": {
"contextPercentageThreshold": 0.6
}
showLineNumbers
(boolean):
true
"showLineNumbers": false
settings.json
:{
"theme": "GitHub",
"sandbox": "docker",
"toolDiscoveryCommand": "bin/get_tools",
"toolCallCommand": "bin/call_tool",
"mcpServers": {
"mainServer": {
"command": "bin/mcp_server.py"
},
"anotherServer": {
"command": "node",
"args": ["mcp_server.js", "--verbose"]
}
},
"telemetry": {
"enabled": true,
"target": "local",
"otlpEndpoint": "http://localhost:4317",
"logPrompts": true
},
"usageStatisticsEnabled": true,
"hideTips": false,
"hideBanner": false,
"maxSessionTurns": 10,
"summarizeToolOutput": {
"run_shell_command": {
"tokenBudget": 100
}
},
"excludedProjectEnvVars": ["DEBUG", "DEBUG_MODE", "NODE_ENV"],
"includeDirectories": ["path/to/dir1", "~/path/to/dir2", "../path/to/dir3"],
"loadMemoryFromIncludeDirectories": true
}
The CLI keeps a history of shell commands you run. To avoid conflicts between different projects, this history is stored in a project-specific directory within your user’s home folder.
~/.gemini/tmp/<project_hash>/shell_history
<project_hash>
is a unique identifier generated from your project’s root path.shell_history
..env
FilesEnvironment variables are a common way to configure applications, especially for sensitive information like API keys or for settings that might change between environments.
The CLI automatically loads environment variables from an .env
file. The loading order is:
.env
file in the current working directory..env
file or reaches the project root (identified by a .git
folder) or the home directory.~/.env
(in the user’s home directory).Environment Variable Exclusion: Some environment variables (like DEBUG
and DEBUG_MODE
) are automatically excluded from being loaded from project .env
files to prevent interference with gemini-cli behavior. Variables from .gemini/.env
files are never excluded. You can customize this behavior using the excludedProjectEnvVars
setting in your settings.json
file.
GEMINI_API_KEY
(Required):
~/.bashrc
, ~/.zshrc
) or an .env
file.GEMINI_MODEL
:
export GEMINI_MODEL="gemini-2.5-flash"
GOOGLE_API_KEY
:
export GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY"
.GOOGLE_CLOUD_PROJECT
:
GOOGLE_CLOUD_PROJECT
set in your global environment in Cloud Shell, it will be overridden by this default. To use a different project in Cloud Shell, you must define GOOGLE_CLOUD_PROJECT
in a .env
file.export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
.GOOGLE_APPLICATION_CREDENTIALS
(string):
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/credentials.json"
OTLP_GOOGLE_CLOUD_PROJECT
:
export OTLP_GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
.GOOGLE_CLOUD_LOCATION
:
export GOOGLE_CLOUD_LOCATION="YOUR_PROJECT_LOCATION"
.GEMINI_SANDBOX
:
sandbox
setting in settings.json
.true
, false
, docker
, podman
, or a custom command string.SEATBELT_PROFILE
(macOS specific):
sandbox-exec
) profile on macOS.permissive-open
: (Default) Restricts writes to the project folder (and a few other folders, see packages/cli/src/utils/sandbox-macos-permissive-open.sb
) but allows other operations.strict
: Uses a strict profile that declines operations by default.<profile_name>
: Uses a custom profile. To define a custom profile, create a file named sandbox-macos-<profile_name>.sb
in your project’s .gemini/
directory (e.g., my-project/.gemini/sandbox-macos-custom.sb
).DEBUG
or DEBUG_MODE
(often used by underlying libraries or the CLI itself):
true
or 1
to enable verbose debug logging, which can be helpful for troubleshooting..env
files by default to prevent interference with gemini-cli behavior. Use .gemini/.env
files if you need to set these for gemini-cli specifically.NO_COLOR
:
CLI_TITLE
:
CODE_ASSIST_ENDPOINT
:
Arguments passed directly when running the CLI can override other configurations for that specific session.
--model <model_name>
(-m <model_name>
):
npm start -- --model gemini-1.5-pro-latest
--prompt <your_prompt>
(-p <your_prompt>
):
--prompt-interactive <your_prompt>
(-i <your_prompt>
):
gemini -i "explain this code"
--sandbox
(-s
):
--sandbox-image
:
--debug
(-d
):
--all-files
(-a
):
--help
(or -h
):
--show-memory-usage
:
--yolo
:
--approval-mode <mode>
:
default
: Prompt for approval on each tool call (default behavior)auto_edit
: Automatically approve edit tools (replace, write_file) while prompting for othersyolo
: Automatically approve all tool calls (equivalent to --yolo
)--yolo
. Use --approval-mode=yolo
instead of --yolo
for the new unified approach.gemini --approval-mode auto_edit
--telemetry
:
--telemetry-target
:
--telemetry-otlp-endpoint
:
--telemetry-log-prompts
:
--checkpointing
:
--extensions <extension_name ...>
(-e <extension_name ...>
):
gemini -e none
to disable all extensions.gemini -e my-extension -e my-other-extension
--list-extensions
(-l
):
--proxy
:
--proxy http://localhost:7890
.--include-directories <dir1,dir2,...>
:
--include-directories /path/to/project1,/path/to/project2
or --include-directories /path/to/project1 --include-directories /path/to/project2
--version
:
While not strictly configuration for the CLI’s behavior, context files (defaulting to GEMINI.md
but configurable via the contextFileName
setting) are crucial for configuring the instructional context (also referred to as “memory”) provided to the Gemini model. This powerful feature allows you to give project-specific instructions, coding style guides, or any relevant background information to the AI, making its responses more tailored and accurate to your needs. The CLI includes UI elements, such as an indicator in the footer showing the number of loaded context files, to keep you informed about the active context.
GEMINI.md
)Here’s a conceptual example of what a context file at the root of a TypeScript project might contain:
# Project: My Awesome TypeScript Library
## General Instructions:
- When generating new TypeScript code, please follow the existing coding style.
- Ensure all new functions and classes have JSDoc comments.
- Prefer functional programming paradigms where appropriate.
- All code should be compatible with TypeScript 5.0 and Node.js 20+.
## Coding Style:
- Use 2 spaces for indentation.
- Interface names should be prefixed with `I` (e.g., `IUserService`).
- Private class members should be prefixed with an underscore (`_`).
- Always use strict equality (`===` and `!==`).
## Specific Component: `src/api/client.ts`
- This file handles all outbound API requests.
- When adding new API call functions, ensure they include robust error handling and logging.
- Use the existing `fetchWithRetry` utility for all GET requests.
## Regarding Dependencies:
- Avoid introducing new external dependencies unless absolutely necessary.
- If a new dependency is required, please state the reason.
This example demonstrates how you can provide general project context, specific coding conventions, and even notes about particular files or components. The more relevant and precise your context files are, the better the AI can assist you. Project-specific context files are highly encouraged to establish conventions and context.
GEMINI.md
) from several locations. Content from files lower in this list (more specific) typically overrides or supplements content from files higher up (more general). The exact concatenation order and final context can be inspected using the /memory show
command. The typical loading order is:
~/.gemini/<contextFileName>
(e.g., ~/.gemini/GEMINI.md
in your user home directory)..git
folder) or your home directory.node_modules
, .git
, etc.). The breadth of this search is limited to 200 directories by default, but can be configured with a memoryDiscoveryMaxDirs
field in your settings.json
file.@path/to/file.md
syntax. For more details, see the Memory Import Processor documentation./memory refresh
to force a re-scan and reload of all context files from all configured locations. This updates the AI’s instructional context./memory show
to display the combined instructional context currently loaded, allowing you to verify the hierarchy and content being used by the AI./memory
command and its sub-commands (show
and refresh
).By understanding and utilizing these configuration layers and the hierarchical nature of context files, you can effectively manage the AI’s memory and tailor the Gemini CLI’s responses to your specific needs and projects.
The Gemini CLI can execute potentially unsafe operations (like shell commands and file modifications) within a sandboxed environment to protect your system.
Sandboxing is disabled by default, but you can enable it in a few ways:
--sandbox
or -s
flag.GEMINI_SANDBOX
environment variable.--yolo
or --approval-mode=yolo
by default.By default, it uses a pre-built gemini-cli-sandbox
Docker image.
For project-specific sandboxing needs, you can create a custom Dockerfile at .gemini/sandbox.Dockerfile
in your project’s root directory. This Dockerfile can be based on the base sandbox image:
FROM gemini-cli-sandbox
# Add your custom dependencies or configurations here
# For example:
# RUN apt-get update && apt-get install -y some-package
# COPY ./my-config /app/my-config
When .gemini/sandbox.Dockerfile
exists, you can use BUILD_SANDBOX
environment variable when running Gemini CLI to automatically build the custom sandbox image:
BUILD_SANDBOX=1 gemini -s
To help us improve the Gemini CLI, we collect anonymized usage statistics. This data helps us understand how the CLI is used, identify common issues, and prioritize new features.
What we collect:
What we DON’T collect:
How to opt out:
You can opt out of usage statistics collection at any time by setting the usageStatisticsEnabled
property to false
in your settings.json
file:
{
"usageStatisticsEnabled": false
}