YOLO mode is Gemini CLI's auto-approval feature that bypasses interactive confirmation prompts. While powerful for automation, it requires careful consideration of when and how to use it safely. This guide covers everything you need to know about YOLO mode, from basic usage to CI/CD integration.
Understanding YOLO Mode
By default, Gemini CLI prompts you before executing shell commands, modifying files, or performing potentially destructive operations. YOLO mode (short for "You Only Live Once") disables these safety prompts and auto-approves all operations.
When YOLO mode is enabled:
- File operations proceed without confirmation: Creates, edits, and deletions happen automatically
- Shell commands execute immediately: No review step before running commands
- Network requests are allowed: API calls and downloads proceed uninterrupted
- Destructive operations are not blocked: Commands like
rm -rfexecute without warning
This makes YOLO mode extremely efficient for trusted workflows but potentially dangerous in the wrong context.
Enabling YOLO Mode
There are three ways to enable YOLO mode in Gemini CLI.
Command-Line Flag
The most common method is using the --yolo or -y flag:
# Full flag
gemini --yolo "refactor all TypeScript files to use strict mode"
# Short flag
gemini -y "update all package.json dependencies"
Environment Variable
For persistent YOLO mode across multiple sessions:
# macOS/Linux
export GEMINI_YOLO_MODE=true
gemini "run database migrations"
# Windows PowerShell
$env:GEMINI_YOLO_MODE="true"
gemini "run database migrations"
Configuration File
Add YOLO mode to your settings file for permanent enablement (not recommended):
{
"yolo": true
}
The settings file is located at ~/.gemini/settings.json on macOS/Linux or %USERPROFILE%\.gemini\settings.json on Windows.
Safe Use Cases for YOLO Mode
YOLO mode is appropriate in these scenarios:
1. CI/CD Pipelines
Automated pipelines cannot respond to interactive prompts. YOLO mode enables fully automated workflows:
# GitHub Actions example
- name: AI Code Review
run: |
gemini --yolo "analyze this PR for security issues and add comments"
2. Disposable Development Environments
When working in containers or VMs that can be destroyed and recreated:
# Docker development container
docker run -it --rm mydev-image bash -c "gemini --yolo 'set up development environment'"
3. Automated Testing
Running test suites where Gemini generates or modifies test files:
gemini --yolo "generate unit tests for all functions in src/utils/"
4. Batch Operations on Reviewed Code
When you have already reviewed the task and understand what operations will occur:
# After reviewing the codebase and understanding the scope
gemini --yolo "add JSDoc comments to all exported functions"
5. Sandboxed Environments
Working in isolated environments where damage is contained (see next section).
Dangerous Scenarios to Avoid
Never use YOLO mode in these situations:
- Production systems: Auto-approved commands could delete data or break services
- Systems with sensitive credentials: Commands might accidentally expose or modify secrets
- Unfamiliar codebases: You cannot predict what operations Gemini might attempt
- Prompts from untrusted sources: Malicious prompts could exploit YOLO mode to execute harmful commands
- Shared development machines: Other users' files or processes could be affected
- When working with databases: Unreviewed SQL commands could corrupt or delete data
Combining YOLO Mode with Sandbox
The safest way to use YOLO mode is with sandbox restrictions still in place. This provides auto-approval within defined boundaries:
{
"sandbox": {
"enabled": true,
"allowedDirectories": [
"~/projects/my-app"
],
"blockedDirectories": [
"~/.ssh",
"~/.aws",
"/etc"
],
"allowedCommands": [
"npm *",
"git *",
"node *"
],
"blockedCommands": [
"rm -rf /",
"sudo *"
]
},
"yolo": true
}
With this configuration, YOLO mode auto-approves operations, but the sandbox still blocks access to sensitive directories and dangerous commands.
Recommended Sandbox + YOLO Configuration
For CI/CD environments, this configuration provides good balance:
{
"sandbox": {
"enabled": true,
"allowedDirectories": ["$WORKSPACE"],
"blockedCommands": ["sudo *", "rm -rf /*", "chmod 777 *"]
},
"yolo": true
}
YOLO Mode in CI/CD Pipelines
Here are examples for common CI/CD platforms.
GitHub Actions
name: AI-Assisted Code Review
on: [pull_request]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Gemini CLI
run: npm install -g @google/gemini-cli
- name: Run AI Review
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
GEMINI_YOLO_MODE: true
run: |
gemini "review the changes in this PR and suggest improvements"
GitLab CI
ai-review:
image: node:20
script:
- npm install -g @google/gemini-cli
- export GEMINI_YOLO_MODE=true
- gemini "analyze code quality and generate report"
variables:
GEMINI_API_KEY: $GEMINI_API_KEY
Alternatives to YOLO Mode
If YOLO mode feels too risky, consider these alternatives:
Pre-Approved Command Lists
Configure specific commands to auto-approve while prompting for others:
{
"sandbox": {
"allowedCommands": [
"git add *",
"git commit *",
"npm run *",
"npx prettier *"
]
}
}
Interactive Approval with Defaults
Use the --default-yes flag to auto-approve after a timeout:
gemini --default-yes --timeout 5 "refactor code"
This shows the prompt but proceeds automatically after 5 seconds if no response.
Dry Run Mode
Preview operations without executing them:
gemini --dry-run "delete all temporary files"
This shows what would happen without making changes.
Recovery if Something Goes Wrong
If YOLO mode causes unintended changes, here are recovery options:
Git Recovery
If working in a git repository:
# Discard all uncommitted changes
git checkout -- .
# Reset to a specific commit
git reset --hard HEAD~1
# View what changed
git diff HEAD~1
File System Recovery
For non-git directories:
# Check if macOS Time Machine has backups
tmutil listbackups
# On Linux, check for snapshots
sudo btrfs subvolume list /
Database Recovery
If database changes occurred:
- Restore from the most recent backup
- Check transaction logs for rollback options
- Contact your DBA if using managed databases
Prevention Strategy
Always ensure you have recovery options before using YOLO mode:
- Commit or stash changes before running YOLO operations
- Create backups of critical files
- Use version control for all code directories
- Test in isolated environments first
Next Steps
- Learn how to fix sandboxing permission errors for fine-grained control
- Explore MCP integrations for extended Gemini CLI capabilities
- Read about batch code analysis for large-scale operations