Skip to main content

Command Palette

Search for a command to run...

Create Custom Commands with Gemini CLI

Updated
3 min read
E

Senior .NET Developer passionate about developer productivity and automation. I specialize in building scalable backend systems with C#, Azure, and modern DevOps practices. Always exploring tools that help developers ship faster and write better code. Sharing practical tips at ArabDevSimplified.

Custom commands help you streamline your development workflow by automating common tasks like code reviews, documentation generation, and testing. Start with these examples and customize them to fit your needs

Before vs After Gemini CLI

Before:

  • Checkout to feature branch

  • Stash my changes in case I have any

  • Check git history and new changes added

  • Look at specific patterns from technical perspective

  • Validate the business logic

After:

  • Type review command with feature branch name

  • It checks everything for me automatically

  • I only validate the business logic to avoid any surprises

Understanding Command Structure

Each Command should have 2 sections

  • description: This is what you see on gemini cli when you type your command

  • prompt: Normal instructions in plain prompt:, you can add shell commands using this format ! { }

\> 💡 Important: Shell commands must be wrapped in !{ } - this tells Gemini CLI to execute them and include the output in the prompt.

description = "..."

prompt = """
This is plain text the model reads.


These are just sentences that tell the model what to do.

!{
# THIS PART is different:
# add your shell commands
}

Back to plain text again.
"""

Setting Up Your First Command: Review Command (Mac Users)

#1 Create the global Gemini commands folder
mkdir -p ~/.gemini/commands

#2 Create/open the command file in VS Code
code ~/.gemini/commands/review.toml


#3 add your command inside review.toml

description = "Reviews changes from a specific feature branch against 
origin/main"

prompt = """
You are a senior .NET expert.
Review the code changes for the branch '{{args}}'.

Git Changes:
!{
set -euo pipefail
branch="{{args}}"

git check-ref-format --branch "$branch" >/dev/null

git fetch origin
git diff "origin/main...origin/$branch" -- . ':!**/bin/' ':!**/obj/' ':!*.lock' ':!**/.env*' ':!**/secrets*' ':!**/appsettings.*'
}

Instructions:
1. Identify code smells, security issues, or performance bottlenecks.
2. Focus on C# best practices (Async/Await, LINQ, Memory allocations).
3. If you see API changes, verify if versioning is handled correctly.
4. Provide a bulleted summary of the changes.
5. If the code is solid, end with the phrase: "Ship it 🚀".
"""

Setting Up Your First Command: Review Command (Windows Users - CMD)

# Create the global Gemini commands folder
mkdir "%USERPROFILE%\.gemini\commands"

# Create/open the command file in VS Code
code "%USERPROFILE%\.gemini\commands\review.toml"

# add your command inside review.toml

description = "Reviews changes from a specific feature branch against origin/main"

prompt = """
You are a senior .NET expert.
Review the code changes for the branch '{{args}}'.

### Git Changes:
!{
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest

$branch = "{{args}}"

# Validate branch name format (fails fast if sketchy/invalid)
git check-ref-format --branch $branch | Out-Null

git fetch origin | Out-Null

git diff ("origin/main...origin/$branch") -- . `
  ':!**/bin/' `
  ':!**/obj/' `
  ':!*.lock' `
  ':!**/.env*' `
  ':!**/secrets*' `
  ':!**/appsettings.*'
}

### Instructions:
1. Identify code smells, security issues, or performance bottlenecks.
2. Focus on C# best practices (Async/Await, LINQ, Memory allocations).
3. If you see API changes, verify if versioning is handled correctly.
4. Provide a bulleted summary of the changes.
5. If the code is solid, end with the phrase: "Ship it 🚀".
"""

Now that you’ve set up your first custom command, here are more ideas to supercharge your workflow:

  1. Documentation Generator - Create a docs command that reads your code and generates markdown documentation with usage examples

  2. Test Creator - Build a test command that analyzes your functions and generates unit tests following your team’s conventions

  3. Commit Message Writer - Make a commit-msg command that examines your staged changes and crafts clear, conventional commit messages

The possibilities are endless! Each command you create saves time and ensures consistency across your projects.

What Will You Create?

What custom command will YOU create? Share your ideas and creations in the comments below! I’d love to see how you’re using Gemini CLI to streamline your development workflow. 🚀