Development

Bikin Global Custom Slash Commands (Claude & Gemini)

Asep Alazhari

Panduan praktis membuat global custom slash commands di Claude Code (Markdown) dan Gemini CLI (TOML) untuk streamline workflow development lo sehari-hari.

Bikin Global Custom Slash Commands (Claude & Gemini)

Cerita Latar Belakang

Setelah menguasai Claude Code dengan tools productivity essential, gue menghadapi tantangan baru nih: kecemasan berulang karena harus bikin prompt yang sama terus-menerus. Setiap kali butuh git commit message, gue nemuin diri gue ngetik variasi “analyze my git changes and create a professional commit message” , buang-buang waktu dan energi mental untuk sesuatu yang harusnya bisa diotomatis.

Sebenernya sih, gue bisa aja pake AI commit message generation bawaan VS Code, tapi hasilnya mengecewakan banget , message generic kayak “Update files” atau “Fix issues” yang ga ngasih tau apa-apa tentang perubahan yang sebenernya terjadi. Tool-nya kurang context awareness dan ga bisa ngikutin format commit message yang gue suka dengan module prefix dan semantic type.

Frustasi ini yang akhirnya bikin gue nemuin kekuatan custom slash commands. Beberapa minggu lalu gue sempet bingung konsepnya waktu building AI tooling gue. Gue pengen otomatis bikin commit message dan bersihin file, tapi gue terus bilang “yuk bikin hook aja,” padahal yang gue mau sebenernya adalah custom slash command yang bisa gue panggil kapan aja, kayak /gcm untuk git commit message. Pergeseran kejelasan kecil itu bikin perbedaan besar deh. Slash commands itu intentional: lo trigger mereka ketika lo butuh, menghilangkan kecemasan harus nulis ulang prompt yang sama berulang-ulang.

Sekarang gue udah setup custom slashes di dua tools yang gue pake setiap hari:

  • Claude Code → custom slashes disimpen sebagai file Markdown.
  • Gemini CLI → custom slashes disimpen sebagai file TOML.

Kedua pendekatan ini ngasih gue cara yang konsisten untuk manggil workflow yang bisa diulang dari mana aja. Dan karena disimpen di lokasi global, command gue ngikutin gue lintas project, ga perlu copy-paste snippet atau ngetik ulang prompt yang sama.


Yang Bakal Lo Pelajari: Poin-Poin Penting

  • Command global /gcm yang baca Git diff lo dan draft commit message yang bersih
  • Template yang bisa dipakai ulang untuk semua slash command: input → context gathering → output format
  • Panduan implementasi side-by-side untuk Claude Code (Markdown) dan Gemini CLI (TOML)
  • Contoh real-world termasuk environment auditing dan best practices

Bagian I , Claude Code: Global Slash Commands dengan Markdown

Claude Code nemuin slash dari file Markdown. Nama file jadi nama command, dan frontmatter ngontrol description, model options, dan shell calls mana aja yang diizinkan.

1) Bikin folder command global

mkdir -p ~/.claude/commands

2) Bikin ~/.claude/commands/gcm.md

---
description: Generate a formatted git commit message from current changes
allowed-tools: Bash(git status:*), Bash(git diff:*), Bash(git log:*)
argument-hint: "[module] [type] optional context"
---

# Git Commit Message Generator

Current git status:
!`git status --porcelain`

Current staged changes:
!`git diff --cached`

Current unstaged changes:
!`git diff`

Recent commits:
!`git log --oneline -5`

Analyze the changes and create a commit message using this format:

- \[Module] \[Type]: description

Guidelines:

- Be specific and concise.
- Prefer imperative mood.
- If multiple logical changes exist, output multiple bullet lines.
- If no changes are staged, suggest commands to stage or split.

3) Pake deh

Ketik /gcm di mana aja di Claude Code. Lo bisa kasih hint kayak /gcm UI Feature dan bakal dipertimbangkan dalam prompt body.

Tips: Taro slash lainnya juga di sini: ~/.claude/commands/review.md, ~/.claude/commands/test.md, dll. Bikin mereka kecil, composable, dan bisa ditemuin dengan /help.


Bagian II , Gemini CLI: Global Slash Commands dengan TOML

Untuk Gemini CLI, kita bisa define slash dalam TOML, yang perfect untuk configuration-style prompts dengan parameter. Di bawah ini layout praktis dan minimal yang mirror versi Claude.

1) Bikin folder command global

mkdir -p ~/.gemini/commands

2) Bikin ~/.gemini/commands/gcm.toml

# Name becomes the slash name: /gcm
name = "gcm"
description = "Generate a formatted git commit message from current changes"

# Optional: choose a default model or temperature per command
# model = "gemini-2.5-pro"
# temperature = 0.2

[permissions]
# Whitelist external commands Gemini CLI may execute and insert into context
allow = [
  "git status --porcelain",
  "git diff --cached",
  "git diff",
  "git log --oneline -5"
]

[prompt]
# The prompt body: supports template vars and injected command outputs
header = """
# Git Commit Message Generator

Current git status:
{{exec "git status --porcelain"}}

Current staged changes:
{{exec "git diff --cached"}}

Current unstaged changes:
{{exec "git diff"}}

Recent commits:
{{exec "git log --oneline -5"}}

Analyze the changes and create a commit message using this format:

- [Module] [Type]: description

Guidelines:
- Be specific and concise.
- Prefer imperative mood.
- If multiple logical changes exist, output multiple bullet lines.
- If no changes are staged, propose next steps.
"""

# Optional arguments users can pass like: /gcm module=UI type=Feature
[args]
module = { required = false, hint = "e.g., UI, API, Auth" }
type = { required = false, hint = "Feature, Fix, Refactor, Docs" }
context = { required = false, hint = "extra hints to include" }

[render]
# Control how the final output is presented
format = "markdown"

3) Pake nih

Jalanin /gcm di dalam Gemini CLI. Kalo CLI lo support passing argumen, coba:

/gcm module=API type=Fix context="handle null auth token"

Using custom /gcm slash command in Gemini CLI terminal interface Eksekusi custom /gcm slash command di Gemini CLI - liat tuh gimana command otomatis ngumpulin context Git dan prepare untuk generate commit message profesional

TOML bikin command lo mudah dipindah dan jelas, dan lo bisa version-control di dotfiles.

Baca juga: MCP dengan Claude Desktop: Transformasi Workflow Development Lo


Bikin Slash Commands yang Keren (berlaku untuk keduanya)

Jaga skeleton yang stabil

  1. Title , jelasin apa yang dilakukan command dalam satu baris.
  2. Context collectors , git calls di atas adalah contohnya, lo bisa ganti dengan grep, jq, atau ls untuk tugas lain.
  3. Output shape , tentuin format akhir dengan jelas (bullets, table, JSON, checklist).
  4. Guardrails , cuma whitelist command yang aman, hindari yang destructive.

Result of /gcm command showing generated commit message Command /gcm in action - otomatis analisis perubahan Git dan bikin commit message berformat yang ngikutin guideline dan format yang udah dispesifikasi

Bikin mereka bisa dirantai

  • Command /review bisa output checklist yang dikonsumsi /fixit.
  • Command /todo bisa parse TODO: comments dan jadiin rencana berprioritas.

Pake tiny patterns yang compound

  • File pickers: capture diff aja untuk file yang berubah.
  • Branch heuristics: baca nama branch dan propose JIRA ticket tag.
  • Diff size thresholds: kalo diff gede banget, minta untuk diperkecil cakupannya atau dipisah.

Baca juga: GitHub Copilot Limit Abis? Claude Code Solusinya Nih!


Contoh Real-World: /audit-env

Claude (MD) , ~/.claude/commands/audit-env.md

---
description: Audit .env keys referenced in the repo and suggest a cleanup plan
allowed-tools: Bash(rg:*), Bash(jq:*), Bash(ls:*)
---

# Env Audit

List env files:
!`ls -1 .env* 2>/dev/null || true`

Find references in code:
!`rg -n --hidden --glob '!node_modules' '(process\.env\.[A-Z0-9_]+)'`

Summarize missing/unused keys, possible typos, and risks. Output as a checklist with actions.

Gemini (TOML) , ~/.gemini/commands/audit-env.toml

name = "audit-env"
description = "Audit .env keys and produce a cleanup plan"

[permissions]
allow = [
  "ls -1 .env*",
  "rg -n --hidden --glob !node_modules (process\.env\.[A-Z0-9_]+)"
]

[prompt]
header = """
# Env Audit

List env files:
{{exec "ls -1 .env*"}}

Find references in code:
{{exec "rg -n --hidden --glob !node_modules (process\.env\.[A-Z0-9_]+)"}}

Summarize missing/unused keys, possible typos, and risks. Output a checklist with actions.
"""

[render]
format = "markdown"

Tips, Opini, dan Lessons Learned

  • Mulai kecil aja. /gcm pertama gue cuma ada git status dan satu bullet. Udah cukup buat nempel.
  • Nama itu penting. Slash yang pendek dan mudah diucapkan menang. Gue pake /gcm, /review, /audit, /test, /ship.
  • Lebih suka collectors yang read-only. Gue jarang biarkan slash jalanin command yang ngubah-ngubah. Kalo workflow harus ubah file, gue bikin command terpisah untuk itu.
  • Explainers kurangin hallucination. Bentuk output yang jelas (kayak - [Module] [Type]: ...) menghasilkan hasil yang lebih konsisten daripada free-form prose.
  • Version command lo. Simpen ~/.claude/commands dan ~/.gemini/commands di repo dotfiles lo biar mesin baru langsung familiar.

Fresh bonus: Gue ukur efeknya di repo Next.js medium-sized selama seminggu. Pake /gcm dan /review, rata-rata waktu persiapan commit turun dari ~95 detik jadi ~28 detik, dan commit lint-only berkurang karena intention lebih jelas sebelum staging.


Back to Blog

Related Posts

View All Posts »