Google’s Gemini CLI is transforming the developer experience by bringing the power of AI directly into the terminal. This open-source tool allows for natural language interaction to perform a variety of tasks, from generating and explaining code to managing files and fixing bugs. Now, with the introduction of custom slash commands, Gemini CLI is becoming an even more powerful and personalised tool for developers looking to boost their productivity.
An AI Assistant in Your Terminal
At its core, Gemini CLI is an AI-powered assistant that lives in your command line interface. It leverages the capabilities of Google’s Gemini models to understand your codebase and help you with complex tasks without needing to switch between different applications.
e.g.…
Google’s Gemini CLI is transforming the developer experience by bringing the power of AI directly into the terminal. This open-source tool allows for natural language interaction to perform a variety of tasks, from generating and explaining code to managing files and fixing bugs. Now, with the introduction of custom slash commands, Gemini CLI is becoming an even more powerful and personalised tool for developers looking to boost their productivity.
An AI Assistant in Your Terminal
At its core, Gemini CLI is an AI-powered assistant that lives in your command line interface. It leverages the capabilities of Google’s Gemini models to understand your codebase and help you with complex tasks without needing to switch between different applications.
e.g. You can install dependencies via npm or npx and, after a simple authentication process with your Google account, you’re ready to go. Gemini CLI offers a generous free tier, making it accessible to a wide range of developers.
The CLI comes with a set of built-in tools that allow it to interact with your local environment. These tools include functionalities for searching files, editing code, running shell commands, and even fetching content from the web. This combination of powerful AI and practical tools makes Gemini CLI a versatile assistant for both coding and a wide range of other tasks.
Supercharging Your Workflow with Custom Commands
The latest and most exciting feature of Gemini CLI is the ability to create custom slash commands.
This highly requested feature allows you to define reusable, parameterizable prompts to streamline repetitive tasks and create shortcuts for your specific workflows. These commands are defined in simple .toml files, making them easy to create and share.
You can create two types of custom commands:
- User-scoped commands: Stored in the
~/.gemini/commands/directory, these commands are available globally across all your projects. - Project-scoped commands: Located in a
.gemini/commands/directory within your project, these commands are specific to that project and can be checked into version control for team collaboration.
Easy Steps To Create Your Command
Let’s walk through creating a custom command called /plan. This command will instruct Gemini to create a strategic, step-by-step plan for a given task without immediately jumping into implementation. This allows you to review and iterate on the proposed plan before any code is written.
First, you need to create a plan.toml file in your user-scoped commands directory:
mkdir -p ~/.gemini/commands
touch ~/.gemini/commands/plan.toml
The name of the .toml file determines the name of your slash command. In this case, plan.toml becomes /plan.
Define The Command
Next, open plan.toml and add the following content:
description="Investigates and creates a strategic plan to accomplish a task."
prompt = """
Your primary role is that of a strategist, not an implementer.
Your task is to stop, think deeply, and devise a comprehensive strategic plan to accomplish the following goal: {{args}}
You MUST NOT write, modify, or execute any code. Your sole function is to investigate the current state and formulate a plan.
Present your strategic plan in markdown. It should be the direct result of your investigation and thinking process.
Structure your response with the following sections:
1. **Understanding the Goal:** Re-state the objective to confirm your understanding.
2. **Investigation & Analysis:** Describe the investigative steps you would take.
3. **Proposed Strategic Approach:** Outline the high-level strategy.
4. **Verification Strategy:** Explain how the success of this plan would be measured.
5. **Anticipated Challenges & Considerations:** Based on your analysis, what potential risks do you foresee?
Your final output should be ONLY this strategic plan.
"""
This .toml file has two key parts: a description that explains what the command does, and a prompt that contains the detailed instructions for Gemini. The {{args}} placeholder will be replaced by any text you provide after the /plan command.
Use Your New Command
Now you can use your custom command directly in the Gemini CLI:
/plan How can I improve the performance of my web application?
Gemini will then follow the instructions in your plan.toml file and provide a detailed, strategic plan to address your query.
Custom slash commands in Gemini CLI are a game-changer for developers. They offer a simple yet powerful way to automate repetitive tasks, enforce best practices, and create a more efficient and personalized development workflow. By abstracting away complex prompts into easy-to-use commands, Gemini CLI empowers you to focus on what matters most: building great software.
You can follow me on GitHub, where I’m creating cool projects.
I hope you enjoyed this article, don’t forget to give ❤️. Until next time 👋