Topic 2 of 4 · 5 min read
Writing a reusable command with arguments
Goal: Write a command that takes arguments, limits its tools and produces the same structured result every time it runs.
A good command is a prompt with a fixed shape: placeholders for what changes, front matter for what it may use, and a required output format for what comes back. Write it once, and every run gets the same careful request.
Check yourself · 1 of 3
What is the purpose of an argument placeholder such as $ARGUMENTS or {{args}} in a command file?
Why it matters
A pasted prompt drifts. One person leaves out the output format, another forgets the test command. A command file keeps the wording stable, so differences in results come from the code, not from the prompt.
The parts
- Location. A file in the repository, such as
.claude/commands/,.gemini/commands/or.github/prompts/, is shared with the team through git. A file in your home folder is private. Codex reads prompts from its own prompts folder in your home directory. - Front matter. A short header with a description (shown in the command list) and, in tools that support it, the tools the command may use and the model to run it on. Claude Code uses
allowed-toolsandmodel. VS Code prompt files usetoolsandmodel. Gemini CLI commands are TOML with adescriptionand aprompt. - Arguments. A placeholder that is replaced by what you type after the command name:
$ARGUMENTSor$1in Claude Code and Codex,{{args}}in Gemini CLI,${input:name}in VS Code. - Context injection. Some tools can run a shell command or include a file when the command starts, so the agent sees real data: the git diff, a log, a config file. Gemini CLI uses
!{...}and@{...}; Claude Code uses a backtick command after an exclamation mark. - Output contract. Say exactly what to return: headings, order, a verdict word, a limit on length.
Before and after
Weak:
Review my changes and tell me if they are ok.
Stronger, as .claude/commands/review.md:
---
description: Review the current branch against main
argument-hint: [focus area]
allowed-tools: Bash(git diff:*), Bash(git log:*), Read, Grep
---
Review the diff of this branch against main. Focus: $ARGUMENTS
Diff: !`git diff main...HEAD`
Return exactly:
1. Verdict: APPROVE, CHANGES or BLOCK
2. Up to 5 findings, each as file:line, problem, fix
3. Tests missing, if any
Do not edit any file.
It limits the tools to read-only git and file reads, pulls in the real diff, takes a focus area, and fixes the output shape.
What goes wrong
- No output contract. Results change from run to run, and nobody can compare them.
- Missing argument. The user runs the command with nothing and the placeholder stays empty. Write what to do then: "If no focus is given, review everything."
- Too many tools. A review command that can edit files will sometimes edit files.
- Huge injected output. Injecting a 5,000-line diff buries the instructions. Limit it, or name the files to read.
Examples
A read-only review command in Gemini CLI
description = "Review staged changes"
prompt = """
Review these staged changes. Focus: {{args}}
!{git diff --staged}
Return a verdict (APPROVE, CHANGES, BLOCK) and at most 5 findings as file:line, problem, fix.
"""
The shell command runs first and its output is placed in the prompt.
A prompt file in VS Code
---
description: Explain a failing test
agent: ask
---
Explain why the test in ${input:testFile} fails and propose the smallest fix.
Do not change files.
Key points
- Use placeholders for the parts that change and keep the rest of the prompt fixed.
- Front matter sets a description, and in many tools the allowed tools and the model, so a command can be limited to what it needs.
- Injecting a diff, log or file at run time gives the agent real data instead of your memory of it.
- State an output format so results from different runs and different people can be compared.
- Say what to do when an argument is empty, because the placeholder will then be blank.
Common mistakes
- Leaving the output format open, so every run answers in a different shape.
- Granting write or shell tools to a command that only needs to read.
- Forgetting the empty-argument case.
- Injecting a very large diff or log and burying the instructions.
Check yourself · 2 of 3
A review command should never change files. Which setup supports that best?
Check yourself · 3 of 3
Why add 'Return exactly: verdict, up to 5 findings, missing tests' to a command?
Practice items, not counted towards your mastery.
Start here
- Custom commands (Gemini CLI docs) (opens in a new tab)DocsFree
Shows TOML command files, the args placeholder, and shell and file injection with escaping.
- Use prompt files in VS Code (opens in a new tab)DocsFree
Reusable prompt files with front matter for description, agent mode, model and tools.
- Custom prompts (Codex docs) (opens in a new tab)DocsFree
How Codex stores reusable prompts as Markdown files and passes arguments into them.