About this codelab
1. What is it?
Gemini CLI is an open-source AI agent that brings the power of Gemini directly into the terminal. It provides lightweight access to Gemini, giving you the most direct path from the prompt to our model.
Key features of the Gemini CLI include:
- Agentic Capabilities: It can perform complex tasks by chaining together multiple commands and services.
- Local Execution: It runs locally on your machine, harnessing the most powerful Cloud-based models, providing fast and responsive interactions.
- Extensibility: It can be extended with custom tools and commands to meet specific needs.
- Integration: It can be integrated with other Google tools and services.
2. Installation & Usage
To get started with the Gemini CLI, you'll need to install it on your machine. You'll need Node 18+ installed on your machine.
Installation:
With npm
:
npm install -g @google/gemini-cli
gemini
Or with npx
:
npx https://github.com/google-gemini/gemini-cli
3. Tools Overview
The Gemini CLI's power comes from its modular tools. These tools are essentially functions that can be called by the CLI to perform specific actions. They are designed to be composable, meaning that Gemini can chain them together to create complex workflows.
Available Tools
- File System Tools: These tools allow you to interact with files and directories on your local system. You can use them to read, write, list, and search files.
Example prompt:Show me the content of README.md
- Shell Tool: This tool allows you to execute shell commands directly from the Gemini CLI. This is useful for automating tasks that require shell interaction. Example prompt:
Show me the disk space
- Web Fetch Tool: This tool allows you to retrieve content from URLs. You can use it to fetch data from web pages, APIs, and other online resources.
Example prompt:What are the 3 MCP transports again?
- Web Search Tool: This tool allows you to search the web using a given query. You can use it to find information on a variety of topics.
Example prompt:What's the latest version of resilience4j-circuitbreaker on maven central?
- Multi-File Read Tool: This specialized tool allows you to read content from multiple files or directories at once. It's often used in conjunction with the
@
command to process a list of files.
Example prompt:Give me the last line of each log in this folder
- Memory Tool: This tool allows you to save information across different sessions with the Gemini CLI. This is useful for personalizing the agent.
Example prompt:Remember that I like to use Conventional Commits.
Tools API Overview
The Gemini CLI utilizes a powerful Tools API to manage and execute its various tools. This API defines how tools are structured, how they receive input, and how they return output.
See the Tools API documentation for more details.
Composability: Gemini CLI combines tools to create complex workflows.
Tools are designed to be composable, allowing the Gemini CLI to chain them together to automate complex tasks by combining simpler tools. This flexibility is a key feature of the Gemini CLI.
See the Tools API documentation for examples of how to combine tools.
4. Setting up a Model Context Protocol (MCP) server [optional]
If you want to add an MCP server to Gemini, this is as simple as adding an entry to your ~/.gemini/settings.json
– or the project's gemini/settings.json file.
- Configure an MCP server in your
settings.json
file. - Set a personal access token (e.g., for GitHub) as an environment variable.
- Gemini CLI will automatically launch the MCP server when it starts.
- Use natural language prompts to interact with the MCP server.
For more details, see Tutorials.
5. Use Gemini CLI on open source repo (Gemma)
One of the powerful use cases of Gemini CLI is to interact with open source repositories, like Gemma. You can use it to:
- Build features: Generate code that integrates with your existing style and the structure of the Gemma repository.
- Automate tasks: Automate tasks like creating pull requests, or generating documentation.
- Explore the code: Explore the code base, and find specific code snippets.
To do this, you can use the following commands:
git clone https://github.com/google-deepmind/gemma.git
cd gemma
gemini
Once Gemini opens, enter the following prompt: What is the purpose of the image.py file?
6. Cool use cases
Tip: It's best to handle blocking scripts yourself, then tell Gemini CLI where the logs are located and inform it that you'll run the script in the background.
Configure workflow
Include the following line in your GEMINI.md as a starting point in describing your workflow:
## About the app
This app is about [description of your app]
##Testing
It's very important to me there is a test for every python file, and the name is <original_file>_test.py.
For everything else, follow this style guide: https://google.github.io/styleguide/pyguide.html
##App flow
Do not run npm start since its blocking: I will run the app for you.
You check logs under ./logs/app.log, and
curl endpoints in localhost port 8080.
So if I tell you to check endpoint /up you can simply curl http://localhost:8080/up and check logs there.
If port 8080 is closed, also try 8081 and 8082 in sequence.
Git bisect
Now that you're running your app, Gemini can help you locate a commit that broke it automatically using git bisect
.
gemini --prompt="Can you help me find the commit that broke my app using git bisect?"
Automate gcloud commands
As you're working, you might forget the exact syntax of a gcloud
command, like how to get your project number. Gemini CLI can help! Simply describe what you want to achieve, and it will provide you with the correct command.
For example:
gemini --prompt="Provide the gcloud command to get my project number given a project id"
7. Contributing guide
We welcome contributions to the Gemini CLI! If you're interested in adding new features or fixing bugs, please refer to the CONTRIBUTING.md file in the repository for more detailed instructions:
Join our discussion fourm at https://github.com/google-gemini/gemini-cli/discussions to share your thoughts and feedback!
8. Conclusion
Congratulations on completing this Codelab! You have learned how to use the Gemini CLI to interact with your code, and how to contribute to the project.
Feel free to review these other documents and materials for further reading: