Custom commands in Gemini CLI

Official Link:https://geminicli.com/docs/cli/custom-commands/

Introduction

Custom commands in Gemini CLI let you save and reuse your favorite prompts as shortcut-style commands. Instead of typing the same long instruction again and again, you can store it in a .toml file and run it with a short slash command such as /review, /git:commit, or /refactor:pure.

This makes your workflow faster, more consistent, and easier to manage across projects.

What are Custom Commands?

A custom command is a reusable prompt stored in a TOML file. Gemini CLI reads these files and turns them into slash commands.

For example:

Custom commands are useful when you:

Why Custom Commands are Useful

Custom commands help you:

In simple words, custom commands turn Gemini CLI into a more personalized and automated tool.

File Locations and Precedence

Gemini CLI loads commands from two main locations.

  1. User commands (global): These commands are available in every project.
    • Location:~/.gemini/commands/
  2. Project commands (local): These commands are available only inside the current project.
    • Location:<your-project-root>/.gemini/commands/

Precedence Rule

If a project command and a user command have the same name, the project command wins. That means local project commands can override your global commands.

Example:

If both of these exist:

Then Gemini CLI will use the project version when you are inside that project.

Naming and Namespacing

Command names come from the file path relative to the commands directory.

Examples:

Key idea

This helps keep commands organized.

Reloading Commands

After creating or editing a command file, run:

Bash

/commands reload    

This refreshes the available commands without restarting Gemini CLI.

TOML File Format (v1)

Custom commands must be written in:

Each command file usually contains:

Running Your Custom Command in Gemini CLI

After creating or modifying a command file, you must restart your Gemini CLI session for the changes to take effect.

  1. Type /quit to exit.
  2. Run gemini to start a new session.
  3. Type / and you should see your custom command in the list.

Basic Example

Suppose you create a summarize.toml file with the following content:

summarize.toml file

description = "Asks the model to summarize the given file."
prompt = "Please summarize the given file {{args}} in simple terms."

If this file is saved as:

Folder Structure

📁 ~/.gemini/
└── 📁 commands/
    └── 📄 summarize.toml

You can run it as:

Bash

/summarize

Using Arguments with {{args}}

The {{args}} placeholder is used to capture any text the user types after the command.

For example, if you run:

Bash

/summarize filename.txt

The text filename.txt will be injected into the prompt where {{args}} is placed.