/useful-skills:pr-inline-comment <PR/MR URL>(其餘細節用對話描述:哪個檔案哪一行、要發什麼)from useful-skills
在 GitHub PR 或 GitLab MR 的指定程式碼行上發、改、刪 inline review comment。處理 commit SHA 取得、行號錨定(新增/刪除/未變動行各有規則)、以及「行號必須以整數送出」這個會讓留言被靜默降級成一般留言的踩雷點。
Ships in useful-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
把 review 出來的問題掛到對應的程式碼行上。通常接在 code-review 之後使用。
支援 GitHub(gh)與 GitLab(glab)。兩邊的概念一樣、欄位名不同,下面分開寫;共通的踩雷點集中在最後一節,動手前務必看。
留言內文格式見 review-finding-format skill 的「精簡格式」:問題 / 🗣️ 白話情境 / 解法三段。因為留言已錨定在程式碼行上,內文不需要再重述檔案與行號脈絡。
gh 已安裝並登入(gh auth status 可確認)。在 repo 目錄內執行時不必指定 repo;否則帶 --repo <owner>/<name>。
inline comment 要錨定在某個 commit 上:
gh pr view <n> --json headRefOid,baseRefName,files
取 headRefOid 當 commit_id。
backend/src/...,不是你的 workspace 相對路徑)line 指該行在檔案中的行號(不是 diff 的位移),搭配 side:
side: "RIGHT"side: "LEFT"start_line 與 start_side務必先驗證行號(從 diff hunk 推算容易差一):
gh api "repos/<owner>/<repo>/contents/<path>?ref=<head_sha>" \
--jq '.content' | base64 -d | sed -n '<起>,<迄>p' | cat -n
python3 - <<'PY'
import json
body = open('/tmp/comment.md', encoding='utf-8').read()
json.dump({
"body": body,
"commit_id": "<head_sha>",
"path": "<diff 檔案路徑>",
"line": 93, # 整數
"side": "RIGHT",
}, open('/tmp/payload.json','w',encoding='utf-8'), ensure_ascii=False)
PY
gh api --method POST \
-H "Accept: application/vnd.github+json" \
--input /tmp/payload.json \
"repos/<owner>/<repo>/pulls/<n>/comments"
若改用
-f/-F而非--input:-f一律送字串、-F才會解析成數字。line用-f送會是字串(見最後一節)。
comment id 從 gh api "repos/<owner>/<repo>/pulls/<n>/comments" --jq '.[].id' 取得。
# 改內文(不動位置)
gh api --method PATCH --input /tmp/update.json \
"repos/<owner>/<repo>/pulls/comments/<comment_id>"
# 刪除(成功回 204)
gh api --method DELETE "repos/<owner>/<repo>/pulls/comments/<comment_id>"
glab 已安裝並登入。所有指令都要以 GITLAB_HOST=<host> 前綴執行——git remote 的 ssh port 與 API port 常常不同,不帶會 404 / None of the git remotes...。
從 MR URL 拆出:
scheme:// 後到第一個 / 前,含 port/-/merge_requests/ 前/-/merge_requests/ 後的數字/ → %2F)GitLab 的 position 需要三個 SHA:
GITLAB_HOST=<host> glab api "projects/<encoded-id>/merge_requests/<iid>/versions"
取陣列**第一筆(最新版本)**的 base_commit_sha、start_commit_sha、head_commit_sha。
+):只給 new_line-):只給 old_lineold_line 與 new_line 都要給(缺一會被拒)務必先驗證行號:
GITLAB_HOST=<host> glab api \
"projects/<encoded-id>/repository/files/<url-encoded-path>/raw?ref=<head_sha>" \
| sed -n '<起>,<迄>p' | cat -n
檔案路徑也要 URL-encode(
/→%2F)。
python3 - <<'PY'
import json
body = open('/tmp/comment.md', encoding='utf-8').read()
json.dump({
"body": body,
"position": {
"position_type": "text",
"base_sha": "<base_commit_sha>",
"start_sha": "<start_commit_sha>",
"head_sha": "<head_commit_sha>",
"new_path": "<diff 檔案路徑>",
"old_path": "<diff 檔案路徑>",
"new_line": 93, # 整數;context 行再加 "old_line": <int>
},
}, open('/tmp/payload.json','w',encoding='utf-8'), ensure_ascii=False)
PY
GITLAB_HOST=<host> glab api --method POST \
-H "Content-Type: application/json" \
--input /tmp/payload.json \
"projects/<encoded-id>/merge_requests/<iid>/discussions"
# 改內文(不動位置)
GITLAB_HOST=<host> glab api --method PUT \
-H "Content-Type: application/json" --input /tmp/update.json \
"projects/<encoded-id>/merge_requests/<iid>/notes/<note_id>"
# 刪除(需 discussion id,成功回 204)
GITLAB_HOST=<host> glab api --method DELETE \
"projects/<encoded-id>/merge_requests/<iid>/discussions/<discussion_id>/notes/<note_id>"
這是最容易踩、也最難發現的一個。 兩邊的 CLI 都有「raw string field」旗標(-f),用它送行號會變成字串:
position 會被靜默丟棄,留言變成不掛在任何行上的一般 MR comment一律用 JSON body(--input + Content-Type: application/json),讓行號保持整數型別。
順帶:先把留言內文寫到檔案再用程式組 JSON,可以避免 backtick、換行、引號被 shell 吃掉。
POST 回應裡的位置欄位應非 null(GitHub 看 line/path,GitLab 看 notes[0].position)。保險起見再列一次確認:
# GitHub
gh api "repos/<owner>/<repo>/pulls/<n>/comments" \
--jq '.[] | "\(.id) \(.path) \(.line)"'
# GitLab
GITLAB_HOST=<host> glab api "projects/<encoded-id>/merge_requests/<iid>/discussions" \
| python3 -c "import sys,json; [print(n['id'], (n.get('position') or {}).get('new_path'), (n.get('position') or {}).get('new_line')) for d in json.load(sys.stdin) for n in d['notes']]"
位置是 null → 它是一般留言,刪掉重發(多半是行號被當字串送了)。
從 diff hunk 標頭算出來的行號很容易差一。發之前用 head SHA 的實際檔案內容對一次(上面兩邊都有指令)。
--- 分隔並標 📋,與開發者要動手的部分區隔開。What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub lystyp/useful-skill --plugin useful-skills19 skills in this plugin
/ai-family-backend-styleai_family_backend / backend-v2 專案的 coding style 與實作 tips — 分層架構(Controller → Service → Repository)、Zod validator 慣例、Import 分群、Prisma + Exception 處理、Pagination、Swagger/Router/Service/Repository 的新增流程、SRP 檢查四問、Commit 規範。當在 /Users/daniel.shi/hephai/ai_family_backend 這個 repo 內寫或改 code(特別是 controllers/services/repository/validators/routes/swagger)時觸發。/backend-repo-onboarding讓後端工程師在最短時間內從「看得懂字」變成「敢改」一個陌生的後端 repo。做法是先實地求證產出一份上手文件(目錄職責與依賴方向、對應到他原本熟的分層、可執行的架構驗證指令、一條讀路徑與一條寫路徑、交易邊界與錯誤轉換、改動迴路、語法與慣例路障),再照那份文件一步步導覽,隨時接「貼一行 code 問這是什麼」。當使用者說「我要怎麼讀這個專案」「幫我熟悉這個 repo」「我接手了一個專案」「這個後端是怎麼設計的」「每個資料夾是做什麼用的」「新人怎麼上手」「帶我看一下這個後端」「這專案怎麼分層」「我第一次碰這個語言的後端」時務必觸發。即使他只丟一個局部問題(例如「api path 寫在哪」「這個資料夾幹嘛的」),也先照常回答,然後用一句話提議把剩下的補齊成一份上手文件——因為他要的通常不只是那一題。不要觸發:已經熟這個 repo 的人問某支功能在哪、純 bug 排查、跟任何 repo 無關的語言教學、或只是要做 code review。/Other plugins' skills for the same job