
Claude Code slash commands:內建 10 個 + 點整你自己嘅 /command
你 Claude Code 每日貼同樣指示 5 次。Slash command 一招搞掂:定 1 次「/commit」,往後打個指令就啟動。介紹內建 10 個必備 + 教你 15 分鐘整自己嘅 /command。
情境
你 Claude Code 用咗 1 個月。每日流程:
- 「請睇吓我啲改動」(5 次 / 日)
- 「請寫 commit message」(3 次 / 日)
- 「請跑個 tests」(2 次 / 日)
- 「請解釋呢段 code」(4 次 / 日)
- 「請更新 CHANGELOG」(1 次 / 日)
15 個每日 prompt,每個你打一遍。計過:每日 5-10 分鐘打同樣嘢。每月 2.5-5 個鐘。
Slash command 一個字搞掂:
- 打
/commit→ Claude 即時覆檢 + 寫 commit message - 打
/explain→ 簡短解釋揀咗嘅 code - 打
/test→ 跑 tests
呢類預定指令慳你每日打字時間,更重要係 —— 跨 session、跨 team 統一你個 workflow。
呢篇拆內建 10 個必備指令 + 教你 15 分鐘整自己嘅 /command。
跟住做
1. 內建 slash commands
開咗 Claude Code 之後打 /,就會列出當前有得用嘅指令:
🛠 設定 + 資訊:
/help—— 顯示指令列表 + 簡介/model—— 即場切換模型(Opus / Sonnet / Haiku)/config—— 打開設定檔/permissions—— 管理工具權限/cost—— 顯示當前 session 嘅開支
📁 處理檔案:
/init—— 將當前 directory 初始化做 Claude Code project(建立.claude/)/clear—— 清除對話 context(重新開始)/compact—— 壓縮舊對話慳 context
🔍 理解程式碼:
/review—— 睇當前 diff,揾 bug / 改進位/explain—— 解釋揀咗嘅檔案 / function/test—— 跑 project tests/commit—— 由 diff 出 commit message
🤖 Agent 管理:
/agents—— 列出 + 管理 subagents/loop—— 設定定期任務/schedule—— 排程遙距任務
⚠️ 有得用嘅指令會隨版本變。/help 永遠顯示當前完整列表。
2. 每日 workflow 例子
朝早重設:
/clear
# Fresh conversation start
Session 中段 compact(對話感覺慢):
/compact
# Old messages summarized, context 保留核心
做完一個 feature commit:
/review
# Claude reviews diff, flags issues
# If OK:
/commit
# Generates message, you confirm
解釋 code(喺 IDE 揀起一個 function):
/explain
# 揀選嘅 code 會被 explain
3. 點整自訂 slash command
每個用家都可以加自訂 /command。位置:
- User-level(你所有 project 共用):
~/.claude/commands/ - Project-level(淨係呢個 project):
./.claude/commands/
例:整個 /release-notes command。
建立 file ~/.claude/commands/release-notes.md:
---
description: Generate release notes from recent commits
---
請 review 過去 7 日嘅 git commits + generate user-facing release notes:
1. Run `git log --since="7 days ago" --oneline` 拎 commits
2. Group commits by type (feat / fix / refactor)
3. Translate technical commit message → user-readable feature description
4. Format as markdown 「## What's new」 section
5. 排序: new feature first, bug fix second
6. 唔包含 internal refactor (除非 user-facing impact)
Output structure:
## ✨ New features
- ...
## 🐛 Bug fixes
- ...
## 🔧 Improvements
- ...
語氣:concise, user-focused, 唔好 technical jargon.
存好個 file。返 Claude Code,打 /release-notes。
Claude 即刻讀你嘅指示 file 再執行。每次 release 準備好 → 一個字指令 → notes 出嚟。
4. 進階:command 加 arguments
自訂 command 可以收 argument:
~/.claude/commands/refactor-function.md:
---
description: Refactor a specific function with clear input
---
請 refactor 我指 function:
Function name (from 我 first message): $ARGUMENTS
Step:
1. Locate function 喺 codebase
2. Identify: complexity / readability issue
3. 提 2-3 refactor option
4. Implement after my approval
叫起:
/refactor-function calculateTotal
Claude 讀完指示,$ARGUMENTS 就等於 calculateTotal,知道要重構邊個 function。
5. 進階:限制 command 用嘅工具
有啲 command 想限定淨係用某幾樣工具:
~/.claude/commands/read-only-review.md:
---
description: Read-only architecture review (no edits)
allowed-tools: Read, Grep, Bash(git diff:*)
---
請讀過 codebase + 出 architecture overview:
1. 用 Read tool 識 main entry point
2. Grep 揾 critical module
3. 不要 edit 任何 file
4. Output:
- Architecture diagram (mermaid)
- 3 個 strength
- 3 個 weakness / refactor opportunity
呢類唯讀 command 夠安全,唔會一個唔小心搞爛嘢。
6. 同 team 分享 commands
如果成隊開發 team 都用 Claude Code,將共用嘅 ./.claude/commands/ commit 入 git repo:
# In project root
mkdir -p .claude/commands
git add .claude/commands/
Team commit 共用 commands。新同事 pull 個 repo,打 /your-command 即刻用得。成隊人個 workflow 就統一晒。
變化
變化 1:將常見規律整理成 commands
用 Claude Code 一個禮拜之後,自己盤點吓:
「邊個 prompt 我打過 5 次以上?」
頭 5 名 —— 每個變一個自訂 slash command:
/morning-standup—— 睇最近啲 commit + 起今日 standup/deploy-check—— 部署前 checklist(tests 過咗 / 冇 debug code / 等)/changelog-update—— 由新 commit 更新 CHANGELOG.md/explain-error—— 貼個 error → Claude 解釋 + 提解法/onboard-newhire—— 為新 dev 出 onboarding 文檔
每個 15 分鐘整起,之後每日每個慳 5-10 分鐘。
變化 2:Project-level 同 user-level 嘅分別
User-level(~/.claude/commands/):跨 project 都有用嘅通用
- /commit、/explain、/test(universal)
Project-level(./.claude/commands/):呢個 codebase 獨有
- /deploy-to-vercel(Next.js project)
- /generate-migration(Supabase project)
- /publish-to-pypi(Python lib project)
Project-level command 跟住 codebase 走 —— 成隊人入同一個 repo,用同一批 commands。
變化 3:Slash commands + skills + hooks 三者組合
3 層自訂工具疊埋一齊:
- Skills(按第 79 篇):重複 workflow 加規則(例如 email-polish-hk skill)
- Slash commands(呢篇):你主動叫起嘅命名程序
- Hooks(第 87 篇):系統事件自動啟動嘅自動化(例如存檔時自動排版)
用途有時會重疊 —— 你揀邊一層:
- 「我想自己主動叫起」→ slash command
- 「我想 Claude 自己決定叫起」→ skill
- 「我想系統事件自動啟動」→ hook
例:
/format-codeslash command(自己主動、按需要)- email-polish skill(自動認得我貼 email)
- 存檔 hook(自動跑 linter)
拆解:點解 work,同邊度會仆街
跟到上面就已經用得。下面呢段係畀**想由「整咗個 command 跑得」做到「半年後重組個 repo 都唔會無聲無息壞咗」**嘅人——初學者可以跳過,唔影響你跟住做。
自訂 command 最呃人嘅地方係:佢只係一份 prompt template,唔係 program。你打 /commit,Claude 唔係執行一段保證行為一致嘅 code,而係再讀一次你份指示、即場重新詮釋。所以「今次出嚟啱」唔代表「下次同隊友嗰邊都一樣」。呢幾個位你要預咗:
1. $ARGUMENTS 唔會幫你 validate
你 /refactor-function calculateTotal,份 template 直接將 calculateTotal 塞落 prompt。如果你打錯名、打咗個唔存在嘅 function、或者乜都唔打,command 唔會即刻停低話你知。
- 會出事:Claude 自己揾一個「最似」嘅 function 嚟改,你以為改咗 A 其實改咗 B;或者空 argument 之下佢自由發揮。
- 點救:喺 template 入面明寫「若果搵唔到完全脗合嘅 function name,列出候選畀我揀,唔好估住改」。寧願多問一句,唔好靜雞雞改錯。
2. User-level command 假設咗你部機嘅環境
~/.claude/commands/ 嘅 command 跨所有 project 共用。但你 /test 入面如果寫死咗 pnpm test,去到一個用 npm 或者 pytest 嘅 project 就唔 work。
- 會出事:同一個指令喺 A project 順暢、喺 B project 報錯或者跑錯嘢,你一時間摸唔清點解。
- 點救:通用 command 唔好寫死跑乜,叫 Claude「先睇 package.json / Makefile 揾返正確 test 指令再跑」;project 獨有嘅嘢就放
./.claude/commands/。
3. allowed-tools 收得太緊會靜靜哋失敗
你為咗安全,read-only-review 限死 Read, Grep, Bash(git diff:*)。但如果份指示叫佢做啲超出範圍嘅嘢(例如要跑 git log),佢未必會大大聲報錯,可能只係靜靜哋略過嗰步。
- 會出事:output 似模似樣,但其實漏咗你期望佢做嘅一半,你唔細睇睇唔出。
- 點救:tool 白名單同份指示要對得返——指示叫做嘅嘢,工具權限要畀得齊;改完自己跑一次,confirm 佢真係有做晒每一步。
4. Commit 入 repo 嘅 command,會跟住你嘅習慣一齊散播
你將 /commit 嘅 template commit 入 team repo,係好事——但如果你份 template 寫死咗你個人風格(例如硬性要 emoji prefix、或者假設咗某個 branch 命名),成隊人一打就跟你套習慣走。
- 會出事:team 嘅 commit message / workflow 被你一份 template 默默定型,有人覺得唔啱但又唔知改邊度。
- 點救:team 共用嘅 command 寫之前同隊友對一對 convention;template 入面啲硬規則寫得保守啲,畀彈性。
5. Command 一多就無人記得邊個做乜
變化一叫你儲頭 5 名常打嘅 prompt,但儲到 15-20 個之後,/explain、/explain-error、/review、/read-only-review 開始撞名撞職能。
- 會出事:你(同隊友)唔記得邊個 command 做乜,索性唔用,又退返去成段成段打字。
- 點救:每個 command 嘅
description寫到一睇就明、唔好兩個太似;定期清走半年冇用過嘅;命名留返一套習慣(動詞開頭、職能分組)。
呢幾個位,就係「整咗個 command 跑得」同「成隊人用足半年都信得過」之間嘅距離。
一個心態
Slash command 嘅深層價值唔係「打字快咗」—— 係將你自己嘅 workflow 固定落嚟,變成一個可以重用、又有名有姓嘅程序。
你個腦每日都喺度由頭諗「點 commit」「點寫 release notes」「點解釋個 bug」。每次重新諗都係 5-10 分鐘心理負擔。Slash command = 設計一次,往後重複執行。
長遠嚟講:你嘅 ~/.claude/commands/ 會變成你「工程思維嘅延伸」—— 10-20 個自訂指令,經年累月磨利。新同事一睇你啲 commands,就明你個 workflow 哲學。
最後提醒:
- ✅ 第一個自訂 command 唔使完美。15 分鐘出咗佢,每星期再執。
- ⚠️ 唔好未用就過度設計個 command。確認真係每日都用嘅規律,先固定落嚟。
- 🎯 將 team 層嘅 command commit 入 git repo。佢同時係 onboarding 工具,又統一咗成隊人個 workflow。
下個鐘就整一個自訂 command。一個禮拜之後,你會本能咁打 /your-command。
文中工具 · 連結
- Claude Code CLI· 付費
開發者用 — terminal 入面同 Claude pair coding
睇完想同 Claude 一齊行一次?
撳一撳,就將成段 tutor 指示(連埋成篇文嘅內容)抄入剪貼簿。 貼入 Claude.ai 或 Claude Desktop,佢會用廣東話帶你一步一步行, 每步問你填關鍵位,最後畀返一個專為你情況寫嘅 prompt 帶走。
- 創作者 · 30 分鐘
Claude Code 由零安裝:Mac / Linux 30 分鐘起第一個 project
你睇 Twitter / HN 講 Claude Code,但搜尋「install」出咗 5 個矛盾教學,唔知由邊度開始。呢篇 30 分鐘有系統咁裝好 —— Mac / Linux 設定、API key、第一個 project 跑起、權限設定、常見安裝錯誤拆解。
- 創作者 · 25 分鐘
MCP servers 入門:5 個最有用 + 10 分鐘 install
Claude Code 想連 Notion / Slack / GitHub / database —— Claude 自己唔識用外部服務。MCP 解決:install server 之後 Claude 即時可以 query。介紹 5 個最有用 + install 步驟。
- 創作者 · 25 分鐘
Claude Code Hooks:自動排版 / 自動 test / 自動 block 危險指令
成日唔記得跑 prettier,commit 就 lint fail。或者擔心 Claude 突然跑 `rm -rf /`。Hooks 解決:PreToolUse 阻破壞性指令,PostToolUse 自動排版。教你 setup 5 個必備 hook + 邊個事件對邊類任務。