Gemini CLI Cheatsheet
Your quick reference guide for the most common Gemini CLI commands and flags.
Basic Usage
gemini "Your prompt here"
The most basic command. Sends a prompt to the Gemini model and prints the response.
Example: gemini "What are the 5 largest cities in the world?"
npx @google/generative-ai '...'
Run Gemini CLI without a permanent installation. Perfect for quick tests or infrequent use.
Example: npx @google/generative-ai "Suggest a good name for a tech blog."
File & Input Handling
gemini -f [FILE_PATH] '...'
Includes the content of a file as part of the prompt context. The file content is prefixed to your prompt.
Example: gemini -f readme.md "Summarize this README file."
cat [FILE_PATH] | gemini '...'
Pipes the content of a file (or any standard output) directly to Gemini CLI as its context.
Example: cat package.json | gemini 'Explain the purpose of these dependencies.'
gemini --files="file1.py,file2.py" "Compare these files"
Send multiple files to Gemini for analysis.
Example: gemini --files="v1.js,v2.js" "What changed between versions?"
Output Control
gemini --json "Extract data from this text"
Request output in JSON format for easy parsing in scripts.
Example: gemini --json "Extract name, email, and phone from: John Doe, john@example.com, 555-1234"
gemini --markdown "Generate documentation"
Request output in Markdown format.
Example: gemini --markdown "Write documentation for a REST API"
gemini --code-only "Generate a function"
Output only code blocks without explanatory text.
Example: gemini --code-only "Write a Python function to calculate Fibonacci numbers"
Model Control
gemini --model=gemini-1.5-pro "Complex question"
Specify which Gemini model to use.
Example: gemini --model=gemini-1.5-flash "Summarize this paragraph"
gemini --temperature=0.7 "Creative story"
Control randomness in responses (0.0-1.0). Lower values are more deterministic.
Example: gemini --temperature=0.9 "Write a sci-fi short story"
gemini --max-tokens=500 "Long response"
Limit the length of the response.
Example: gemini --max-tokens=100 "Summarize this article"
Advanced Usage
gemini --system="You are a helpful assistant" "Your prompt"
Set a system prompt to guide the model's behavior.
Example: gemini --system="You are a Python expert" "Help me with this code"
gemini --save=mychat "Start a conversation"
Save a conversation to continue later.
Example: gemini --save=project-planning "Let's plan a new web app"
gemini --load=mychat "Continue our discussion"
Continue a previously saved conversation.
Example: gemini --load=project-planning "What were the key features we discussed?"
System & Web Tools
gemini 'List the files in the current directory as a table'
Executes the `ls` command and understands its output. You can ask for specific formats or analysis.
Example: gemini 'Show me the contents of the src folder, recursively, and identify any .css files'
gemini 'Find all instances of `useState` in the `components` directory'
Performs a `grep` search for content within files. Useful for code analysis and discovery.
Example: gemini 'Search for the text `TODO:` in all `.ts` files.'
gemini 'Find all markdown files in the `src/blog` folder'
Uses glob patterns to find files by path. The agent will then typically read or analyze these files.
Example: gemini 'Read all the `.md` files from the blog and give me a summary of each.'
gemini 'Search the web for the latest news on AI'
Performs a web search using Google Search to answer questions about current events or up-to-date information.
Example: gemini 'What were the main announcements from the last Google I/O event?'
gemini 'Remember that I prefer to use pnpm for package management.'
Allows the agent to remember specific facts or preferences for future interactions.
Example: gemini 'From now on, when you suggest installing a package, use pnpm.' 'Okay, I will remember to use pnpm.'
gemini 'Run the command `npm run test` and tell me if it succeeds.'
Executes an arbitrary shell command and analyzes its output. This is a very powerful but potentially dangerous tool.
Example: gemini 'Install the `is-odd` package using npm and then write a node script to use it.'
Pro Tips
export GOOGLE_API_KEY="YOUR_KEY"
Set your API key as an environment variable so you don't have to provide it with every command.
Example: Add this to your .bashrc or .zshrc file for persistence.
gemini -f code.js "Refactor this code. Only output the raw, updated code."
Use prompting to control the output format. Asking for 'raw code' helps when you want to pipe the output directly into a new file.
Example: gemini -f old.py "..." > new.py