Claude Codeのレビュースキル:マージ前に差分を調べるcode-review
Dmitriy Solodukha、Caprock開発者 · 公開日
にClaude CodeとCodexでテスト済み
各エージェントで使えるClaude Code向けレビュースキル。バグ、テスト、セキュリティ、スコープを順に確認し、file:lineと修正案を検証して報告します。
code-reviewはClaude Code用で、Codex・OpenCode・Cursorでも使えます。未コミット差分かベースに対するブランチの差分を調べ、正確性のバグ、足りないテスト、セキュリティ、スコープ逸脱の順に報告します。各指摘にファイル・行・理由・具体的修正案を添え、呼び出し追跡、再現、テストなどで検証します。依頼がなければスタイルの細かな指摘は行いません。
code-reviewスキルをインストールする
エージェントごとに1コマンド。スキルはSKILL.md 1ファイルで、インストール時に何も実行しません。
9スキルをプラグインとして導入します。Claude Code内で次を入力してください:
このスキルだけを導入する場合は、プロジェクトのフォルダーで次を実行します:
全プロジェクトに導入するには -g を追加します。
プロジェクトのフォルダーでターミナルから実行:
全プロジェクトに導入するには -g を追加します。
プロジェクトのフォルダーでターミナルから実行:
全プロジェクトに導入するには -g を追加します。 OpenCodeでは未検証です。オープンな形式の通常の指示ですが、OpenCodeでの実行確認はしていません。
プロジェクトのフォルダーでターミナルから実行:
全プロジェクトに導入するには -g を追加します。 Cursorでは未検証です。オープンな形式の通常の指示ですが、Cursorでの実行確認はしていません。
code-reviewスキルを使うプロンプト
依頼の内容が説明と合うと、エージェントがスキルを選びます。名前を指定すると確実です。プロンプトをクリックしてコピーできます。
code-reviewスキルの確認項目
- 差分を選ぶ:未コミットの作業があればそれを、なければベースブランチに対するブランチの差分を選び、どちらかを1行で明記します。ベースは
origin/HEAD、なければmainまたはmasterです。 - 意図を把握ために、依頼、コミットメッセージ、プロジェクトのエージェント向け指示を読みます。プロジェクトのルール違反も指摘対象です。
- 差分だけでなくコードも読む:周辺の関数、呼び出し元、変更した名前のすべての使用箇所を調べます。
- 順に確認:正しさ、テスト、セキュリティ、スコープの広がりの順に確認します。
- 全指摘を検証。確認できなければ未検証とし、確認方法も示します。あいまいな指摘を多く出すより、確実な指摘を少数出します。
- CIを追加:Caprockの
ci_status、なければgh pr checks、それもなければ「CI: not available」と記します。
実行したテストとエージェントの動作
各スキルは2026年11月29日に、専用の使い捨てリポジトリへプロジェクトスキルとしてインストールして実行しました。小さなPythonリポジトリのmasterに対するfeat/discountブランチです。割引コードの末尾2文字を解析してos.systemに渡す処理(シェルインジェクション)、不正コードでのクラッシュ、無関係なaverage()が空リストでゼロ除算する処理があり、どれにもテストがありません。
Claude Code (claude -p --model sonnet)
Review the changes on this branch before I merge them.
code-reviewスキルを呼び(Claude Codeの同名の組み込みスキルよりプロジェクトスキルが優先)、7件を報告しました。シェルインジェクション、未検証のコード、1桁・3桁の解析、呼び出しごとのログ行、average([])のクラッシュ、テスト不足、スコープ外のaverage()です。5件は再現で検証し(インジェクションでは一時フォルダーにファイルを作成)、テスト不足とスコープの指摘はコードと履歴を読んで確認しました。判定はマージ前に修正で、CI行とNot checked行もありました。
Codex (0.163.0, codex exec)
Review the changes on this branch before I merge them.
スキルを読み、書式に沿って検証済みの3件(インジェクション、解析、テスト)を報告しました。average()は見落とし、CI行も抜けていました。その後、スキルはCI行を必須に変更しましたが、Codexでは再実行していません。報告の冒頭(リンクは通常のテキストで表示):
Reviewed: `feat/discount` vs `master`, 1 commit, 1 changed file. Verdict: **fix before merge** 1. [security] cart.py:9: Discount codes can execute arbitrary shell commands. Why: `SAVE10; echo injected > marker; #10` passes percentage parsing and executes the injected command. Fix: Replace `os.system` with Python file I/O or logging. Verified: Reproduced in a temporary directory; the injected command created a marker file.
検証したエージェント
- Claude Code:2026年11月29日に、
.claude/skills/にプロジェクトスキルとしてインストールし、claude -p --model sonnetで検証しました。 - Codex:2026年11月29日にCodex 0.163.0(
codex exec)、.agents/skills/内のスキルで検証しました。 - OpenCodeとCursor:未検証です。オープンなAgent Skills形式の通常の指示ですが、どちらでも実行して確認していません。
制限
- Claude Codeには同名の組み込み
/code-reviewがあります。テストではプロジェクトスキルが使われました。プラグインとしてインストールした場合、どちらが優先されるかは未検証です。 - 各1回の実行で、Claude Codeの7件に対してCodexは3件を報告しました。Codexは
average()のクラッシュとスコープの指摘を見落としました。 - 差分が非常に大きい場合は、リスクの高いファイルからレビューし、残りをNot checkedに列挙します。
- Caprockの
ci_statusによるCI行は未検証です。テストリポジトリにリモートがありませんでした。
Caprockがある場合とない場合
Caprock MCPサーバーに接続している場合、スキルはci_statusを呼び、最新のワークフロー実行とオープンなプルリクエストのチェックを調べ、失敗したジョブ名を挙げます。接続がなければ、GitHub CLIにサインインしている場合はgh pr checksを使い、それ以外は「CI: not available」と書きます。Caprockはコンピューター上の全コーディングエージェントのセッションを記録する無料のオープンソースアプリです。
SKILL.md全文
dspv/skillsのリビジョンdfce799にあるファイルそのものです。手動で導入する場合、プロジェクト内の、Claude Codeは.claude/skills/code-review/SKILL.md、Codexは.agents/skills/code-review/SKILL.mdに保存してください。
--- name: code-review description: > Review the changes a coding agent made before they are committed or merged: the uncommitted diff, or the branch's diff against its base branch. Finds correctness bugs first, then missing or broken tests, security problems and scope creep. Every finding has file:line, why it is wrong and a concrete fix, and is checked against the code before it is reported. No style nitpicks unless asked. Use when the user says "review my changes", "review this diff", "review the branch before I merge", "code review", "check what the agent changed", or is looking for a claude code review skill that works in any agent. license: Apache-2.0 --- # Code review Review a diff the way a careful senior engineer would before approving it: find what will break, prove it from the code, say how to fix it. Do not edit files unless the user asks for fixes. ## 1. Pick the diff Use what the user named (a branch, a commit range, a file). Otherwise, in this order: 1. Uncommitted work: `git status --short`. If anything is staged, unstaged or untracked, review `git diff HEAD` plus the untracked files (read them whole; they are new code). 2. Otherwise the branch against its base. Find the base: the user's word, else `git symbolic-ref refs/remotes/origin/HEAD` (strip `refs/remotes/`), else `main` or `master`, whichever exists. Then review `git diff $(git merge-base <base> HEAD)...HEAD` and read `git log --oneline <base>..HEAD` for the stated intent. 3. If both are empty, say there is nothing to review and stop. State the diff you reviewed in one line (for example `uncommitted, 4 files` or `feat/x vs master, 3 commits, 6 files`). ## 2. Learn the intent Before judging, know what the change is meant to do: the user's request, commit messages, a PR description, a linked issue, the project's agent instructions (`CLAUDE.md`, `AGENTS.md` or the like). Those instructions are rules too: a change that breaks one is a finding. ## 3. Read the code, not only the diff For each changed hunk, open the surrounding function and its callers. A diff hides the line that makes it wrong: the caller that passes `None`, the other branch of the `if`, the second place that writes the same field. Use the project's search (`git grep`, `rg`) to find every use of a changed name, signature, return value or config key. ## 4. Look for problems, in this order 1. **Correctness.** Logic errors, wrong conditions, off-by-one, unhandled `null`/empty/error cases, wrong types or units, race conditions, resource leaks, broken callers of a changed signature, behavior that no longer matches the intent, data loss or migrations that cannot be undone. 2. **Tests.** New behavior with no test, a test that cannot fail (asserts nothing, mocks the thing under test), a test changed to pass instead of the code being fixed, deleted or skipped tests. If the project has a fast test command, run it and report the result. 3. **Security.** Injection (SQL, shell, path, HTML), secrets or tokens in code or logs, missing authorization checks, unsafe deserialization, user input reaching the file system or a network call unchecked. 4. **Scope creep.** Changes the task did not ask for: unrelated refactors, renamed files, reformatting, new dependencies, debug prints, commented-out code, edits to generated or lock files. Name them so the user can drop them; they are findings only when they risk something or hide the real change. Skip style, naming and formatting unless the user asked for them or a project rule requires it. ## 5. Verify every finding Before a finding goes in the report, prove it: - Re-read the exact lines and the code they depend on. Confirm the input that breaks it can actually reach it (trace the caller, the type, the validation upstream). - Where it is cheap, show it: run the failing test, a one-line script, or the project's check. - If you cannot prove it, either drop it or keep it marked **unverified** with what would confirm it. Never present a guess as a bug. Drop a finding that the code already handles elsewhere. Fewer real findings beat many maybe ones. ## 6. CI results (optional) If the branch has a pull request or CI runs, include the result: - When the Caprock MCP tools are available (server `caprock`), call `ci_status` (optional argument `repo`: a directory inside the repository). It returns the newest run of each workflow on the default branch and the checks of the open pull request, with failing jobs named. Caprock (<https://caprock.dev>, free, open source, runs locally) provides that tool. - Otherwise, if the GitHub CLI is installed and signed in, `gh pr checks` shows the checks of the current branch's pull request. - If neither is available, write `CI: not available` in the report and move on. A failing check related to the diff is a finding; read its log before blaming the diff. ## 7. Report Use this format, most severe first. Nothing else before it except the one-line diff summary. ``` Reviewed: <what diff> Verdict: <ready to merge | fix before merge | needs discussion> 1. [bug] path/to/file.py:42: <what is wrong, one sentence> Why: <the input or path that triggers it, and what happens> Fix: <the concrete change: code or exact steps> Verified: <how: test run, traced caller at file:line, reproduced> | unverified: <what would confirm> 2. [test] ... 3. [security] ... 4. [scope] ... CI: <checks passed | failing: job names | not available> Not checked: <anything you could not read or run> ``` Severity tags: `bug`, `test`, `security`, `scope`, and `rule` for a broken project instruction. If there are no findings, say so in one line and give the verdict; do not invent findings to fill the report. ## Stop conditions - Stop after the report. Apply fixes only if the user asks; then re-run the tests you ran. - If the diff is too large to read whole, say so, review the riskiest files first (logic over config, config over docs), and list the files you did not review under `Not checked`.
code-reviewスキルについての質問
- 他のエージェントでも使えるClaude Codeのレビュースキルはありますか?
- code-reviewは、Claude Code・Codex・OpenCode・Cursorが読める通常のSKILL.mdです。Claude CodeとCodex 0.163.0で2026年11月29日に検証しました。
- Claude Codeの組み込みレビューとの違いは?
- 各エージェントで同じ固定形式を使い、指摘をコードで検証してから報告します。Claude Codeの組み込み /code-reviewと同名です。テストではプロジェクトスキルとしてこちらが使われました。プラグインでは`/caprock-skills:code-review`で呼べますが、この形式は未実行です。
- code-reviewスキルはコードを変更しますか?
- 変更しません。報告で停止し、依頼された場合だけ修正して、先に実行したテストを再実行します。
- スタイルも指摘しますか?
- 依頼やプロジェクト規則がない限り行いません。スタイル、命名、整形は既定では対象外です。