最近工作幾乎都使用 Claude Code 在輔助開發,平常下 prompt 都用中文,偶爾會發生 Claude 誤會我意思的狀況。
某天突然想到可以在 Claude.md 中要它在執行指令前,如果我的 prompt 是中文就先翻譯成英文後再執行,如果是英文則建議我更好的 prompt。
這樣有兩個好處,一是我可以練英文(用英文來思考+即時糾正),二是我可以在他執行指令前再次確認他是否正確理解我想表達的內容。
主委加碼
這篇文如果只寫上面那段好像有點太水了XD 來分享兩個我前陣子自己加的 slash commands。(還是現在應該要改叫 skill?)
gc
首先是 /gc,這個指令會要 Claude Code 分析我的 git diff,並適當地拆分多個 commit。不過比較可惜的是它的粒度似乎只能到檔案,沒辦法一行一行地新增到 stage 中。(更不用妄想讓每個 commit 都能 work)
有時候會連續地要 Claude 執行許多更改,/gc 這個指令就很實用。
gc stands for git commit,我自己的 alias 中也有這個指令。(參看: github)順帶一提,git checkout 則是 gco。
---
name: gc
description: Analyze the current git diff and stage appropriate commits.
user-invocable: true
---
Steps:
1. Run `git diff` and `git diff --cached` to see all unstaged and staged changes
2. Run `git status` to get a full picture of modified, new, and deleted files
3. Group related changes into logical, atomic commits
4. For each commit group:
a. Stage only the relevant files using `git add <files>`
b. Commit with a clear message using `git commit -m "<message>"`
Commit message rules:
- Use Conventional Commits format: `<type>(<scope>): <subject>`
- Types: feat, fix, refactor, chore, docs, style, test, perf
- Subject: imperative mood, no period, under 72 chars
- No Co-authored-by, no "Generated by", no AI attribution of any kind
- Multi-line body only if the change genuinely needs explanation
Splitting rules:
- Each commit should represent one logical change
- Do not mix refactoring with feature changes
- Do not mix dependency updates with business logic changes
- Prefer more smaller commits over one large commit
pr
再來是 /pr,這個指令主要是開了 branch 想要 merge 回 main/master 時會開 pull request,有時候很懶得想 title & desc 時這個指令就可以很方便快速地彙整這個 branch 的主要變更,並用列點的方式來呈現在 description 中。
---
name: pr
description: Analyze diff between current branch and main/master, output PR title and description
user-invocable: true
---
Steps:
1. Run `git rev-parse --abbrev-ref HEAD` to get current branch name
2. Run `git diff main...HEAD` (or `git diff master...HEAD`) to get the diff
3. Analyze the changes
Output **only** the following in English:
**Title:** A concise PR title (imperative mood, under 72 chars, no period)
**Description:**
- Bullet points summarizing what changed and why
- Group related changes together
- Keep each point short and clear
- Do not include implementation details unless critical
以上兩個檔案都是放在 ~/.claude/skills/{command}/SKILL.md 下,但因為版本更迭的速度真的很快,說不定下週就又換地方了。但使用情境應該不會有太大差異,到時找不到正確的地方再問問 Claude Code 就好XD