Claude-Code-Review-Skill: code-review prüft den Diff vor dem Merge

Dmitriy Solodukha, Caprock-Entwickler · Veröffentlicht am

Am mit Claude Code und Codex getestet

Ein Claude-Code-Review-Skill für jeden Agenten: zuerst Bugs, dann Tests, Sicherheit und Umfang, jeweils mit Datei:Zeile und Lösung, vor dem Bericht überprüft.

Der code-review-Skill ist ein Claude-Code-Review-Skill, der auch in Codex, OpenCode und Cursor funktioniert: Er prüft den nicht committeten Diff oder den Branch gegen seine Basis und meldet zuerst Korrektheitsfehler, dann fehlende Tests, Sicherheitsprobleme und Ausweitungen des Umfangs. Jeder Befund enthält Datei und Zeile, die Fehlerursache und eine konkrete Lösung und wird anhand des Codes belegt (nachverfolgter Aufrufer, Reproduktion, Testlauf), bevor er im Bericht erscheint. Keine Stilkritik, sofern du nicht darum bittest.

Installiere den code-review-Skill

Ein Befehl pro Agent. Der Skill ist eine einzelne SKILL.md; bei der Installation wird nichts ausgeführt.

Alle neun Skills als Plugin. Gib dies in Claude Code ein:

Oder nur diesen Skill, im Projektordner in einem Terminal:

Füge -g hinzu, um ihn für jedes Projekt zu installieren.

Prompts für den code-review-Skill

Der Agent wählt den Skill, wenn deine Worte zu dessen Beschreibung passen; mit dem Namen stellst du es sicher. Klicke auf einen Prompt, um ihn zu kopieren.

Was der code-review-Skill prüft

  1. Wählt den Diff: die nicht committete Arbeit, sonst den Branch gegen seine Basis (aus origin/HEAD, sonst main oder master), und nennt die Auswahl in einer Zeile.
  2. Ermittelt die Absicht aus deiner Anfrage, den Commit-Nachrichten und den Agentenanweisungen des Projekts; eine verletzte Projektregel ist ein Befund.
  3. Liest den Code, nicht nur den Diff: die umgebende Funktion, ihre Aufrufer, jede Verwendung eines geänderten Namens.
  4. Prüft der Reihe nach: Korrektheit, Tests, Sicherheit, Ausweitung des Umfangs.
  5. Überprüft jeden Befund, oder markiert ihn als ungeprüft und nennt, was ihn bestätigen würde. Wenige echte Befunde sind besser als viele mögliche.
  6. Ergänzt CI: Caprocks ci_status, sonst gh pr checks, sonst „CI: not available“.

Was wir ausgeführt haben und was die Agenten taten

Jeder Skill wurde am 29. November 2026 in einem eigens dafür angelegten Wegwerf-Repository ausgeführt und als Projekt-Skill installiert. Ein Branch feat/discount gegen master in einem kleinen Python-Repository: ein Rabattcode, dessen letzte zwei Zeichen geparst und an os.system übergeben werden (Shell-Injection), ein ungültiger Code, der einen Absturz auslöst, eine unabhängige average(), die bei einer leeren Liste durch null teilt, und keinerlei Tests dafür.

Claude Code (claude -p --model sonnet)

Review the changes on this branch before I merge them.

Rief den code-review-Skill auf (der Projekt-Skill wurde statt Claude Codes gleichnamigem eingebautem Skill verwendet) und meldete sieben Befunde: Shell-Injection, ungeprüfter Code, Parsing ein- und dreistelliger Werte, eine Logzeile bei jedem Aufruf, der average([])-Absturz, fehlende Tests und average() als Ausweitung des Umfangs. Jeder wurde überprüft: fünf durch Reproduktion (die Injection erzeugte eine Datei in einem temporären Ordner), fehlende Tests und die Ausweitung des Umfangs durch Lesen des Codes und seiner Historie. Urteil: vor dem Merge beheben, mit den Zeilen CI und Not checked.

Codex (0.163.0, codex exec)

Review the changes on this branch before I merge them.

Las den Skill und folgte seinem Format mit drei überprüften Befunden (Injection, Parsing, Tests). Übersah average() und ließ die CI-Zeile weg; nach diesem Lauf wurde die CI-Zeile im Skill verpflichtend, und Codex wurde nicht erneut ausgeführt. Der Anfang seines Berichts (Links als Klartext):

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.

Agenten, mit denen er getestet wurde

  • Claude Code: am 29. November 2026 mit claude -p --model sonnet getestet, der Skill als Projekt-Skill in .claude/skills/ installiert.
  • Codex: am 29. November 2026 mit Codex 0.163.0 (codex exec) getestet, der Skill in .agents/skills/.
  • OpenCode und Cursor: nicht getestet. Der Skill besteht aus reinen Anweisungen im offenen Agent-Skills-Format, wurde aber mit keinem der beiden erprobt.

Grenzen

  • Claude Code hat einen eingebauten /code-review mit demselben Namen. Im Test wurde der Projekt-Skill verwendet; welcher bei einer Plugin-Installation Vorrang hat, wurde nicht getestet.
  • Codex meldete 3 Befunde gegenüber 7 bei Claude Code, in jeweils einem Lauf; der average()-Absturz und der Befund zum Umfang wurden übersehen.
  • Bei einem sehr großen Diff werden die riskantesten Dateien zuerst geprüft; der Rest wird unter Not checked aufgeführt.
  • Die CI-Zeile über Caprocks ci_status wurde nicht erprobt: Das Test-Repository hatte kein Remote.

Mit und ohne Caprock

Wenn der Caprock-MCP-Server verbunden ist, ruft der Skill ci_status für die neuesten Workflow-Läufe und die Checks des offenen Pull Requests auf, samt Namen fehlgeschlagener Jobs. Ohne ihn nutzt er gh pr checks, sofern die GitHub CLI angemeldet ist, oder schreibt „CI: not available“. Caprock ist die kostenlose Open-Source-App, die jede Coding-Agent-Session auf deinem Computer aufzeichnet.

Caprock holen →

Die vollständige SKILL.md

Die Datei aus dspv/skills in Revision dfce799. Zur manuellen Installation speicherst du sie in deinem Projekt als .claude/skills/code-review/SKILL.md für Claude Code oder .agents/skills/code-review/SKILL.md für Codex.

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`.

Fragen zum code-review-Skill

Gibt es einen Claude-Code-Review-Skill, der in anderen Agenten funktioniert?
code-review ist einer: eine einfache SKILL.md, die Claude Code, Codex, OpenCode und Cursor lesen können. Er wurde am 29. November 2026 mit Claude Code und Codex 0.163.0 getestet.
Wie unterscheidet sich dieser Code-Review-Skill vom eingebauten Review in Claude Code?
Er funktioniert in jedem Agenten gleich, berichtet in einem festen Format und belegt jeden Befund anhand des Codes, bevor er ihn meldet. Der eingebaute /code-review-Befehl von Claude Code hat denselben Namen. Im Test wurde dieser als Projekt-Skill installiert und verwendet; über das Plugin rufst du ihn mit `/caprock-skills:code-review` auf (diese Form wurde nicht ausgeführt).
Ändert der code-review-Skill meinen Code?
Nein. Er stoppt nach dem Bericht. Änderungen nimmt er nur auf deine Bitte vor und führt dann die zuvor ausgeführten Tests erneut aus.
Kommentiert er den Stil?
Nur wenn du darum bittest oder eine Projektregel es verlangt. Stil, Benennung und Formatierung werden standardmäßig übersprungen.

Quellen

Die App selbst ist auf Englisch.