Skip to content

Instantly share code, notes, and snippets.

@changtimwu
Created June 21, 2026 04:54
Show Gist options
  • Select an option

  • Save changtimwu/a294ba21cd60e76d4fc40cc4e424891c to your computer and use it in GitHub Desktop.

Select an option

Save changtimwu/a294ba21cd60e76d4fc40cc4e424891c to your computer and use it in GitHub Desktop.
Code Review Tutorial (中文)

在單人 GitHub 工作流程中使用 /code-review

一份簡單的教學,教你用 Claude Code 的 /code-review 指令抓出程式錯誤——即使整個專案只有你一個人開發。核心概念:永遠不要直接合併到 main。一律先開分支、發 pull request,並讓 /code-review 在合併前當你的第二雙眼睛。

它能做什麼

/code-review 會在任何 Claude Code 工作階段中執行,直接在終端機裡審查你的 diff。它會找出正確性的錯誤,也會提出重用、簡化與效能上的清理建議。不需要安裝 GitHub App,也不需要付費方案——在單人 repo 上開箱即用。

預設情況下,它會審查你目前分支領先 upstream 的所有 commit,加上工作目錄中尚未 commit 的變更。

開始之前

  • 已安裝並能正常運作的 Claude Code
  • 你身處一個已連結到 GitHub 的 git 儲存庫中
  • 若想從終端機直接開 PR,需安裝 GitHub CLI(gh

工作流程

1. 建立功能分支

絕對不要直接在 main 上工作。

git checkout -b add-login-form

2. 寫程式並 commit

git add .
git commit -m "Add login form"

3. 推送前先在本地審查

在 repo 中開啟 Claude Code,執行:

/code-review

Claude 會審查你這條分支改動的所有內容,並依嚴重程度回報問題。讀完後,自行決定哪些值得修。

如果想讓 Claude 直接把建議套用到你的工作目錄,而不只是列出來:

/code-review --fix

接著檢查它所做的變更,把你想保留的部分 commit 起來。

4. 推送並開 pull request

git push -u origin add-login-form
gh pr create --fill

5.(選用)把審查結果貼到 PR 上

如果你想把這些發現以行內留言的形式記錄在 PR 上——當作存查紀錄或日後參考都很方便——執行:

/code-review --comment

6. 合併

當你滿意、且所有檢查都通過後,合併 PR 並刪除分支。

gh pr merge --squash --delete-branch

這就是完整的循環:開分支 → commit → /code-review → 推送 → PR → 合併。

實用變化

你可以傳入一個目標,讓審查對象不再是預設的 diff:

/code-review src/auth.js        # 單一檔案
/code-review 42                 # 編號 42 的 PR
/code-review main...add-login   # 這條分支對 main 發 PR 時會包含的 diff

你也可以調整投入程度(effort):

  • 較低的 effort 會回傳較少、但信心較高的發現。
  • highmax 則涵蓋更廣,可能也會提出較不確定的問題。
/code-review high

若想進行更深入、在雲端執行並把結果套回工作目錄的審查:

/code-review ultra --fix

速查表

指令 用途
/code-review 審查目前分支的 diff 加上未 commit 的變更
/code-review --fix 審查後,把建議套用到你的檔案
/code-review --comment 把發現以行內留言貼到 PR 上
/code-review <檔案> 審查指定檔案
/code-review <PR編號> 審查指定的 pull request
/code-review main...分支 審查 PR 會包含的 diff
/code-review ultra --fix 更深入的雲端審查,並套用修正

單人開發為什麼還要這樣做?

當沒有人會來審查時,PR 這個步驟看起來像是多餘的——但它讓你擁有一份乾淨的 diff 可以檢視、一個讓 /code-review 留言的地方,以及一份記錄「每個變更為何進來」的歷史。在每條分支合併前都跑一次 /code-review,能讓你在邏輯錯誤與回歸問題還很便宜好修的時候就抓到它們。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment