You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/cli/commands.md
+88-1Lines changed: 88 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,8 @@ Gemini CLI supports several built-in commands to help you manage your session, c
6
6
7
7
Slash commands provide meta-level control over the CLI itself.
8
8
9
+
### Built-in Commands
10
+
9
11
-**`/bug`**
10
12
-**Description:** File an issue about Gemini CLI. By default, the issue is filed within the GitHub repository for Gemini CLI. The string you enter after `/bug` will become the headline for the bug being filed. The default `/bug` behavior can be modified using the `bugCommand` setting in your `.gemini/settings.json` files.
11
13
@@ -38,7 +40,7 @@ Slash commands provide meta-level control over the CLI itself.
38
40
-**Description:** Lists all active extensions in the current Gemini CLI session. See [Gemini CLI Extensions](../extension.md).
39
41
40
42
-**`/help`** (or **`/?`**)
41
-
-**Description:** Display help information about the Gemini CLI, including available commands and their usage.
43
+
-**Description:** Display help information about Gemini CLI, including available commands and their usage.
42
44
43
45
-**`/mcp`**
44
46
-**Description:** List configured Model Context Protocol (MCP) servers, their connection status, server details, and available tools.
@@ -93,6 +95,91 @@ Slash commands provide meta-level control over the CLI itself.
93
95
-**`/quit`** (or **`/exit`**)
94
96
-**Description:** Exit Gemini CLI.
95
97
98
+
### Custom Commands
99
+
100
+
For a quick start, see the [example](#example-a-pure-function-refactoring-command) below.
101
+
102
+
Custom commands allow you to save and reuse your favorite or most frequently used prompts as personal shortcuts within Gemini CLI. You can create commands that are specific to a single project or commands that are available globally across all your projects, streamlining your workflow and ensuring consistency.
103
+
104
+
#### File Locations & Precedence
105
+
106
+
Gemini CLI discovers commands from two locations, loaded in a specific order:
107
+
108
+
1.**User Commands (Global):** Located in `~/.gemini/commands/`. These commands are available in any project you are working on.
109
+
2.**Project Commands (Local):** Located in `<your-project-root>/.gemini/commands/`. These commands are specific to the current project and can be checked into version control to be shared with your team.
110
+
111
+
If a command in the project directory has the same name as a command in the user directory, the **project command will always be used.** This allows projects to override global commands with project-specific versions.
112
+
113
+
#### Naming and Namespacing
114
+
115
+
The name of a command is determined by its file path relative to its `commands` directory. Subdirectories are used to create namespaced commands, with the path separator (`/` or `\`) being converted to a colon (`:`).
116
+
117
+
- A file at `~/.gemini/commands/test.toml` becomes the command `/test`.
118
+
- A file at `<project>/.gemini/commands/git/commit.toml` becomes the namespaced command `/git:commit`.
119
+
120
+
#### TOML File Format (v1)
121
+
122
+
Your command definition files must be written in the TOML format and use the `.toml` file extension.
123
+
124
+
##### Required Fields
125
+
126
+
-`prompt` (String): The prompt that will be sent to the Gemini model when the command is executed. This can be a single-line or multi-line string.
127
+
128
+
##### Optional Fields
129
+
130
+
-`description` (String): A brief, one-line description of what the command does. This text will be displayed next to your command in the `/help` menu. **If you omit this field, a generic description will be generated from the filename.**
131
+
132
+
---
133
+
134
+
#### Example: A "Pure Function" Refactoring Command
135
+
136
+
Let's create a global command that asks the model to refactor a piece of code.
137
+
138
+
**1. Create the file and directories:**
139
+
140
+
First, ensure the user commands directory exists, then create a `refactor` subdirectory for organization and the final TOML file.
141
+
142
+
```bash
143
+
mkdir -p ~/.gemini/commands/refactor
144
+
touch ~/.gemini/commands/refactor/pure.toml
145
+
```
146
+
147
+
**2. Add the content to the file:**
148
+
149
+
Open `~/.gemini/commands/refactor/pure.toml` in your editor and add the following content. We are including the optional `description` for best practice.
150
+
151
+
```toml
152
+
# In: ~/.gemini/commands/refactor/pure.toml
153
+
# This command will be invoked via: /refactor:pure
154
+
155
+
description = "Asks the model to refactor the current context into a pure function."
156
+
157
+
prompt = """
158
+
Please analyze the code I've provided in the current context.
159
+
Refactor it into a pure function.
160
+
161
+
Your response should include:
162
+
1. The refactored, pure function code block.
163
+
2. A brief explanation of the key changes you made and why they contribute to purity.
164
+
"""
165
+
```
166
+
167
+
**3. Run the Command:**
168
+
169
+
That's it! You can now run your command in the CLI. First, you might add a file to the context, and then invoke your command:
170
+
171
+
```
172
+
> @my-messy-function.js
173
+
> /refactor:pure
174
+
```
175
+
176
+
Gemini CLI will then execute the multi-line prompt defined in your TOML file.
177
+
178
+
This initial version of custom commands is focused on static prompts. Future updates are planned to introduce more dynamic capabilities, including:
179
+
180
+
-**Argument Support:** Passing arguments from the command line directly into your `prompt` template.
181
+
-**Shell Execution:** Creating commands that can run local shell scripts to gather context before running the prompt.
182
+
96
183
## At commands (`@`)
97
184
98
185
At commands are used to include the content of files or directories as part of your prompt to Gemini. These commands include git-aware filtering.
0 commit comments