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
+61-5Lines changed: 61 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -129,6 +129,67 @@ Your command definition files must be written in the TOML format and use the `.t
129
129
130
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
131
132
+
#### Handling Arguments
133
+
134
+
Custom commands support two powerful, low-friction methods for handling arguments. The CLI automatically chooses the correct method based on the content of your command's `prompt`.
135
+
136
+
##### 1. Shorthand Injection with `{{args}}`
137
+
138
+
If your `prompt` contains the special placeholder `{{args}}`, the CLI will replace that exact placeholder with all the text the user typed after the command name. This is perfect for simple, deterministic commands where you need to inject user input into a specific place in a larger prompt template.
139
+
140
+
**Example (`git/fix.toml`):**
141
+
142
+
```toml
143
+
# In: ~/.gemini/commands/git/fix.toml
144
+
# Invoked via: /git:fix "Button is misaligned on mobile"
145
+
146
+
description = "Generates a fix for a given GitHub issue."
147
+
prompt = "Please analyze the staged git changes and provide a code fix for the issue described here: {{args}}."
148
+
```
149
+
150
+
The model will receive the final prompt: `Please analyze the staged git changes and provide a code fix for the issue described here: "Button is misaligned on mobile".`
151
+
152
+
##### 2. Default Argument Handling
153
+
154
+
If your `prompt` does **not** contain the special placeholder `{{args}}`, the CLI uses a default behavior for handling arguments.
155
+
156
+
If you provide arguments to the command (e.g., `/mycommand arg1`), the CLI will append the full command you typed to the end of the prompt, separated by two newlines. This allows the model to see both the original instructions and the specific arguments you just provided.
157
+
158
+
If you do **not** provide any arguments (e.g., `/mycommand`), the prompt is sent to the model exactly as it is, with nothing appended.
159
+
160
+
**Example (`changelog.toml`):**
161
+
162
+
This example shows how to create a robust command by defining a role for the model, explaining where to find the user's input, and specifying the expected format and behavior.
description = "Adds a new entry to the project's CHANGELOG.md file."
169
+
prompt = """
170
+
# Task: Update Changelog
171
+
172
+
You are an expert maintainer of this software project. A user has invoked a command to add a new entry to the changelog.
173
+
174
+
**The user's raw command is appended below your instructions.**
175
+
176
+
Your task is to parse the `<version>`, `<change_type>`, and `<message>` from their input and use the `write_file` tool to correctly update the `CHANGELOG.md` file.
177
+
178
+
## Expected Format
179
+
The command follows this format: `/changelog <version> <type> <message>`
180
+
- `<type>` must be one of: "added", "changed", "fixed", "removed".
181
+
182
+
## Behavior
183
+
1. Read the `CHANGELOG.md` file.
184
+
2. Find the section for the specified `<version>`.
185
+
3. Add the `<message>` under the correct `<type>` heading.
186
+
4. If the version or type section doesn't exist, create it.
187
+
5. Adhere strictly to the "Keep a Changelog" format.
188
+
"""
189
+
```
190
+
191
+
When you run `/changelog 1.2.0 added "New feature"`, the final text sent to the model will be the original prompt followed by two newlines and the command you typed.
192
+
132
193
---
133
194
134
195
#### Example: A "Pure Function" Refactoring Command
@@ -175,11 +236,6 @@ That's it! You can now run your command in the CLI. First, you might add a file
175
236
176
237
Gemini CLI will then execute the multi-line prompt defined in your TOML file.
177
238
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
-
183
239
## At commands (`@`)
184
240
185
241
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.
Copy file name to clipboardExpand all lines: docs/cli/configuration.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -429,7 +429,7 @@ This example demonstrates how you can provide general project context, specific
429
429
- Location: The CLI searches for the configured context file in the current working directory and then in each parent directory up to either the project root (identified by a `.git` folder) or your home directory.
430
430
- Scope: Provides context relevant to the entire project or a significant portion of it.
- Location: The CLI also scans for the configured context file in subdirectories _below_ the current working directory (respecting common ignore patterns like `node_modules`, `.git`, etc.).
432
+
- Location: The CLI also scans for the configured context file in subdirectories _below_ the current working directory (respecting common ignore patterns like `node_modules`, `.git`, etc.). The breadth of this search is limited to 200 directories by default, but can be configured with a `memoryDiscoveryMaxDirs` field in your `settings.json` file.
433
433
- Scope: Allows for highly specific instructions relevant to a particular component, module, or subsection of your project.
434
434
-**Concatenation & UI Indication:** The contents of all found context files are concatenated (with separators indicating their origin and path) and provided as part of the system prompt to the Gemini model. The CLI footer displays the count of loaded context files, giving you a quick visual cue about the active instructional context.
0 commit comments