Automated PR review and code quality analysis skill. Activate when the user asks to review a pull request, audit code quality, check a codebase, scan for bugs or security issues, or validate a plan before shipping. Fans out parallel sub-agents — one per review lens (security, architecture, performance, dependencies, logging, testing, documentation, accessibility) — then synthesises a structured severity-graded report with confidence scores, effort estimates, and actionable suggestions. Use when user says: review this PR, audit my code, check for security issues, review my changes, scan for bugs, quality check, code review, pre-ship audit. First response: "PR Review skill active. Paste the diff, file paths, or describe what to review. I'll run every lens in parallel and give you a structured report."
Installation
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Automated PR review and code quality analysis skill. Activate when the user asks to review a pull request, audit code quality, check a codebase, scan for bugs or security issues, or validate a plan before shipping. Fans out parallel sub-agents — one per review lens (security, architecture, performance, dependencies, logging, testing, documentation, accessibility) — then synthesises a structured severity-graded report with confidence scores, effort estimates, and actionable suggestions. Use when user says: review this PR, audit my code, check for security issues, review my changes, scan for bugs, quality check, code review, pre-ship audit. First response: "PR Review skill active. Paste the diff, file paths, or describe what to review. I'll run every lens in parallel and give you a structured report."
license
Apache 2.0
Automated PR Review & Code Quality
A structured, multi-lens code review system. Eight lenses run in parallel so coverage
is deep, consistent, and fast. Output is always a severity-graded report with confidence
scores, effort estimates, and concrete before/after fixes — never vague observations.
SLASH COMMANDS
Command
Action
/review
Full review across all eight lenses
/security
Security lens only — OWASP Top 10, secrets, injection, auth
/arch
Architecture lens only — coupling, cohesion, SOLID, complexity
Refuse full review. Respond: "This diff is too large for a full review. Specify files or lenses: /review src/payments/ /security /arch"
In High-signal mode, always prioritise entry points (main, index, route handlers)
over utility/helper files regardless of diff order.
0.2 Privacy Warning
Before processing any code, display once per session:
⚠ Privacy notice: this review will process <N> lines of code through Claude.
Confirm this repository is cleared for external analysis. [y/n]
Auto-approve for subsequent reviews in the same session.
Run a pre-flight secret scan (regex pass) and strip patterns matching:
-----BEGIN (RSA|EC|OPENSSH) PRIVATE KEY-----
AWS key patterns (AKIA[0-9A-Z]{16})
Generic password\s*=\s*"[^"]+" assignments
Log the count of stripped patterns to the report footer. Security lens findings about
secrets are still raised based on the pattern match, without leaking the value.
0.3 Load Configuration
Look for .pr-review.yml in the repo root. If present, apply:
# .pr-review.yml — all fields optionalignore_paths:-"*.test.ts"-"migrations/"-"generated/"severity_override:TRACE_ID_MISSING:P1# escalate from default P2max_findings:25# cap total findings to prevent review fatiguelenses:# restrict lenses for this repo-security-performance-testingconfidence_threshold:medium# suppress low-confidence findingsfail_on:p0_only# CI exit-code threshold (default: p1)
Also read CONTRIBUTING.md and STYLEGUIDE.md if present to extract naming
conventions and testing requirements before flagging style deviations.
PHASE 1 — RECONNAISSANCE
Before any lens fires, build a context map:
Identify scope — diff only, changed files, or entire repo?
Detect language(s) — infer from file extensions; load language-specific rules.
SSRF / open redirect — any URL constructed from user-controlled input that
makes server-side HTTP requests.
Rate limiting & DoS — unbounded loops driven by user input, missing pagination
limits, expensive regex on untrusted strings (ReDoS).
Severity mapping for this lens:
P0 (Critical) — exploitable without authentication or with low-privilege access.
P1 (High) — exploitable with authenticated access or under specific conditions.
P2 (Medium) — defence-in-depth gap; not directly exploitable but raises risk.
P3 (Low) — best-practice deviation with minimal direct risk.
LENS B — ARCHITECTURE
Goal: identify structural problems that compound over time.
Checklist:
Single Responsibility — functions/classes doing more than one job. Flag any
function >30 lines that mixes concerns (I/O + business logic, for example).
Coupling — tight coupling between unrelated modules, circular imports,
god objects/classes, feature envy.
Complexity — cyclomatic complexity >10 in a single function, deeply nested
conditionals (>3 levels), long parameter lists (>4 params without a data class).
Error handling — swallowed exceptions (except: pass), bare catch (e) {},
missing error propagation, inconsistent error shapes across an API.
Transaction boundaries — database transactions that span external HTTP calls,
holding locks across the wire; missing rollback on partial failure.
Circuit breaker / retry logic — external service calls with no timeout, no
retry with backoff, and no circuit breaker — a single dependency failure takes down
the entire system.
Idempotency — mutation endpoints (POST /charge, POST /send-email) without
an idempotency key, making safe client retries impossible.
DRY violations — copy-pasted logic blocks >5 lines appearing more than once.
Dead code — unreachable branches, unused exports, commented-out code blocks.
Abstraction level — mixed abstraction levels inside a single function; leaky
abstractions exposing implementation details to callers.
LENS C — PERFORMANCE & SCALABILITY
Goal: catch efficiency problems before they become production incidents under load.
Checklist:
N+1 queries — ORM loop issuing one DB query per iteration; flag and suggest
eager loading (select_related, JOIN, $lookup).
Synchronous I/O in async paths — blocking file read, requests.get(), or
time.sleep() inside an async def / event-loop context.
Unbounded memory growth — appending to a list/dict in a loop with no size
cap; loading an entire table into memory; accumulating results without streaming.
Missing pagination — list endpoints returning all rows without LIMIT/OFFSET
or cursor-based pagination.
Big-O inefficiency in hot paths — O(n²) or worse algorithm where O(n log n)
or O(n) alternative exists; nested loops over large collections.
Caching strategy gaps — expensive computations (external API calls, heavy DB
aggregations) called on every request with no memoisation or cache layer.
Database query plans — missing composite indexes on multi-column WHERE
clauses; SELECT * where specific columns suffice; non-SARGable predicates.
Async blocking — Promise.all missing where sequential await chains could
be parallelised; CPU-bound work on the event loop without offloading to a worker.
Memory leaks — event listeners registered without cleanup, timers not cleared,
closures retaining large objects, streams not destroyed on error.
Connection pool exhaustion — opening new DB/HTTP connections per request
instead of reusing a pool; pool size not configured for expected concurrency.
LENS D — DEPENDENCIES
Goal: keep the dependency tree lean, secure, and legally safe.
Checklist:
Outdated packages — dependencies >1 major version behind their latest stable
release; note breaking-change risk.
Unused dependencies — packages imported in package.json / requirements.txt
/ go.mod but never import-ed in code.
Duplicate functionality — two packages doing the same job (e.g., axios and
node-fetch in the same project).
Bundle weight — heavy packages pulled in for a single utility function
(prefer tree-shakeable alternatives or inline the function).
License compliance — GPL/AGPL in a proprietary project, license conflicts
between dependencies.
Lockfile hygiene — missing package-lock.json / poetry.lock, lockfile not
committed, lockfile out of sync with manifest.
Pinning strategy — overly loose (*, >=1) or overly strict (exact SHA for
everything) pinning; recommend ~= / ^ semantics where appropriate.
Deprecated / abandoned packages — no commits in >2 years, archived repo,
single-maintainer bus-factor risk; flag and suggest active alternatives.
Native dependency risk — packages with native bindings (.node, .so, .dll)
that may break across OS/architecture; flag for multi-platform deployments.
Peer-dependency mismatches — declared peer deps not satisfied by installed
versions.
LENS E — LOGGING & OBSERVABILITY
Goal: ensure the system is debuggable in production without leaking sensitive data.
Checklist:
Coverage — every external call (HTTP, DB, queue, cache) has at least one log
entry at the start and on error/success.
Log levels — correct use of DEBUG, INFO, WARN, ERROR, FATAL.
Avoid INFO for every message; avoid DEBUG left on in production code paths.
Structured logging — logs are machine-parseable (JSON, key=value). No raw
print() / console.log() in production paths.
PII leakage — passwords, tokens, emails, PII must never appear in log output.
Verify masking/redaction is applied before logging request/response bodies.
Trace & correlation IDs — distributed transactions include a trace_id or
request_id threaded through all log lines.
Error context — exceptions are logged with full stack trace + request context,
not just "something went wrong".
Metrics & alerts — critical paths (payments, auth, data mutations) emit
a counter or histogram metric; alert thresholds are defined.
Silent failures — code paths that catch exceptions and continue without any
log entry.
LENS F — TESTING
Goal: find coverage gaps and brittle tests before they become production incidents.
Checklist:
Coverage gaps — new code paths with no corresponding test; branches inside
conditionals that are never exercised.
Happy-path only — tests that only cover the success case; missing tests for
error paths, boundary conditions, and empty/null inputs.
Test isolation — tests sharing state via global variables, module-level side
effects, or real external services (DB, HTTP) without mocking.
Brittle selectors — UI tests using implementation-detail selectors (CSS class
names, internal state) instead of accessible roles/labels.
Assertion quality — assert response (truthy check) instead of
assert response.status_code == 200; missing error message in assertion.
Test naming — test names that don't describe the scenario
(test_1, testFoo) making failures hard to diagnose.
Flaky tests — tests with sleep() / fixed timeouts, order-dependent tests,
tests seeded with wall-clock time.
Property-based testing gaps — complex business logic (parsers, validators,
financial calculations) without fuzz / property-based tests (Hypothesis, fast-check).
Contract testing — API changes without consumer contract validation (Pact);
service boundary regressions caught only in integration or staging.
Integration vs unit balance — over-reliance on slow end-to-end tests for
logic that could be unit-tested; or inverse: mocking so heavily that integration
bugs are invisible.
LENS G — DOCUMENTATION
Goal: ensure the code is understandable by a new engineer without a walkthrough.
Checklist:
Public API docstrings — every exported function, class, and method has a
docstring explaining purpose, params, return value, and exceptions raised.
Inline comments — complex business logic, non-obvious algorithms, and
workarounds have a # why comment explaining intent, not just # what.
Stale comments — comments that describe code that no longer exists or
behaviour that has changed.
README coverage — new environment variables, config options, CLI flags, or
setup steps reflected in README / CONTRIBUTING docs.
Changelog / migration notes — breaking changes in public APIs documented in
CHANGELOG.md or a migration guide.
Type annotations — typed languages: all public signatures have types; Python:
all public functions have PEP 484 annotations.
Example usage — complex utilities or SDK-style modules include at least one
runnable example.
TODO hygiene — TODO/FIXME comments have an owner and a linked issue; stale
TODOs (>90 days old) are flagged.
LENS H — ACCESSIBILITY (a11y)
Goal: catch WCAG 2.1 AA violations before they create legal or UX debt.
Skip this lens automatically for non-UI code (pure backend, CLI, IaC).
Checklist:
Missing alt text — <img>, <svg>, and icon buttons without meaningful alt
or aria-label attributes.
Improper ARIA roles — role values that contradict native HTML element
semantics; redundant role="button" on <button>; invalid role hierarchies.
Keyboard trap — modal dialogs, dropdowns, or custom widgets that don't return
focus to the trigger element on close, or trap Tab without an escape route.
Focus management — programmatic focus not moved to newly opened dialogs,
alerts, or route changes; invisible focus ring (:focus { outline: none } without
a visible replacement).
Color contrast — text/background combinations failing WCAG AA ratio (4.5:1
normal text, 3:1 large text); information conveyed by color alone.
Form labelling — inputs without associated <label>, aria-label, or
aria-labelledby; required fields not marked with aria-required.
Interactive element sizing — touch targets smaller than 44×44 px (WCAG 2.5.5).
Motion & animation — animations not respecting prefers-reduced-motion;
auto-playing video/audio without a pause control.
Language declaration — missing lang attribute on <html>; mixed-language
sections without a lang override on the containing element.
Semantic structure — skipped heading levels (<h1> → <h3>); landmark
regions (<main>, <nav>, <aside>) missing or misused.
PHASE 3 — SYNTHESIS RULES
When merging findings from all lenses:
Deduplicate — if two lenses flag the same function, emit one finding with both
lens tags.
Promote severity — a finding tagged by two or more lenses is promoted one
severity level (e.g., P2 → P1).
Group by file — sort findings by file path, then by line number.
Count totals — report P0 / P1 / P2 / P3 counts in the header.
Confidence scoring — assign confidence: high | medium | low to each finding:
high — definitive code evidence (e.g., f-string SQL query with user input).
medium — likely issue but context-dependent (e.g., missing auth check that may
be covered by middleware not visible in the diff).
low — pattern match with high false-positive rate; surface as "Consider
checking…" not as a hard assertion.
Apply configuration — honour ignore_paths, severity_override, and
max_findings from .pr-review.yml if loaded in Phase 0.
Trim noise — suppress P3 findings if total finding count >30 (or max_findings
config value). Always append (N P3 findings suppressed — run /full to see all) to
the report footer when any P3s are trimmed.
Respect suppression comments — if a flagged line carries a # pr-review-ignore: REASON
comment, omit the finding from the report and record the suppression in the footer:
Suppressed: <ID> — <REASON>.
┌─ [<ID>] <SEVERITY> · <LENS>
│ File : path/to/file.ext (line <N>–<M>)
│ Issue : <one-sentence description of the problem>
│ Impact : <what goes wrong if this is not fixed>
│ Confidence : <high | medium | low>
│ Effort : <trivial | small | medium | large>
│ Owner : <@handle from CODEOWNERS — omit if no CODEOWNERS file>
│ Fix : <concrete, actionable suggestion — include code snippet when helpful>
│ Refs : <OWASP link / CWE / RFC / relevant doc — only when directly applicable>
└──────────────────────────────────────────────────────────
Severity Legend
Severity
Emoji
Meaning
Expected action
P0 Critical
🔴
Exploitable, data-loss, or outage risk
Block merge immediately
P1 High
🟠
Significant bug or security gap
Fix before merge
P2 Medium
🟡
Quality or maintainability debt
Fix in follow-up PR
P3 Low
🔵
Style, minor inconsistency, nice-to-have
Backlog or skip
Report Footer
───────────────────────────────────────────────────────────
RECOMMENDED ACTIONS
1. Address all P0s before merge.
2. <specific top recommendation based on findings>
3. <second specific recommendation>
Run `/fix <ID>` for a ready-to-apply patch on any finding.
Run `/explain <ID>` for an educational deep-dive on any finding.
Run `/issues` to open GitHub issues for P0 + P1 findings.
Run `/pr-comment` to post findings as inline review comments.
<Trend line if prior reports exist in session>
<Suppression notes: Suppressed: <ID> — <REASON>>
<Pre-flight secret strips: N patterns redacted before analysis>
<P3 suppression note if applicable>
───────────────────────────────────────────────────────────
GITHUB INTEGRATION
When the user runs /issues after a report:
Authenticate — use the available GitHub tool or confirm the user's gh CLI is
authenticated (gh auth status).
One issue per finding (P0 and P1 only by default; ask before opening P2).
Issue title format: [pr-review][<SEVERITY>] <one-sentence description>
Post findings as inline review comments directly on the PR diff:
Create a pending review via the GitHub API
(POST /repos/{owner}/{repo}/pulls/{pull_number}/reviews).
For each finding with a line number, add a comment at that exact diff line.
For findings without a precise line (e.g., architectural patterns), add a top-level
review comment.
Submit the review with body: PR Review skill — <summary line from report>.
P0 findings → submit as REQUEST_CHANGES; P1/P2 → COMMENT; P3 → omit from
inline comments (include only in the submitted review body).
FALSE POSITIVE MANAGEMENT
Developers will abandon automated review tools if they can't suppress noise.
In-code Suppression
Place a comment on the flagged line to suppress a specific finding:
# pr-review-ignore: intentional MD5 — used for cache key only, not security
cache_key = hashlib.md5(url.encode()).hexdigest()
Rules:
The comment must include a REASON after the colon.
The finding is omitted from the report and recorded in the footer.
Suppressions without a reason are rejected and reported as a new P3 finding.
Confidence-Based Behaviour
Confidence
Report behaviour
high
Full finding block with all fields
medium
Full finding block; prefix Issue with "Likely:"
low
Compact one-liner only, grouped in a CONSIDER CHECKING section at the bottom
Low-confidence findings are never mixed with high/medium findings. The CONSIDER CHECKING section is collapsible and does not contribute to the P0/P1/P2/P3 totals
in the header.
Pattern Learning
When the user responds "not an issue" or dismisses a finding during the session,
record the suppression in session state:
Apply suppression to the same pattern in subsequent /review calls within the session.
CI/CD INTEGRATION
Exit Codes (for scripted / pipeline use)
Condition
Exit code
Behaviour
P0 finding(s) present
1
Always blocks CI
P1 finding(s) present
1 (default) / 0 (if fail_on: p0_only in config)
Configurable
P2/P3 only
0
CI passes
Review error / timeout
2
Infrastructure failure — do not block merge
SARIF Output
Run /review --sarif to emit findings in SARIF 2.1.0 format, compatible with
GitHub Advanced Security, GitLab SAST, and the VS Code SARIF Viewer extension:
any overuse, missing null checks, async without await, prototype pollution
Java / Kotlin
Checked exceptions swallowed, thread-safety of shared state, equals/hashCode contract
Go
Error return ignored (_), goroutine leak, unbuffered channel in hot path
SQL
Implicit type coercions, missing WHERE on UPDATE/DELETE, non-SARGable predicates
Terraform / IaC
Public S3 buckets, wildcard IAM policies, unencrypted storage, missing state locking
DIFF MODE
When the user runs /diff, compare the current review against the main branch baseline
and any prior review in the session:
Require baseline — if no prior report exists, respond:
"No previous report found. Run /review first, make your changes, then run /diff."
Main branch comparison — compare findings against the pre-existing state of main:
Pre-existing debt on main that the PR did not introduce → label [PRE-EXISTING],
surface as P3 only (do not block merge for inherited debt).
New issues introduced by this PR → label [NEW].
Identify resolved findings — findings in a prior session report absent from the
current report. Mark with [FIXED].
Regression detection — automatically escalate severity by one level if:
A test file was deleted or a test function was removed in the diff.
An authentication/authorisation check was deleted in the diff.
A rate-limit or input-validation call was removed in the diff.
Identify unchanged findings — present in both reports. Compact one-liner only:
[UNCHANGED] <ID> · <severity> · <one-line description>
Output format — standard finding block for [NEW]; compact one-liner for
[UNCHANGED]; strikethrough summary line for [FIXED]; italic note for
[PRE-EXISTING].
Summary line: Delta: +N new −M resolved = K unchanged (P pre-existing)
BEHAVIOUR RULES
Never be vague. Every finding must name the exact file, line range, and fix.
Show code. When suggesting a fix, always include a before/after snippet.
No false praise. Do not comment on things that are fine; silence means approval.
Stay in scope. Only flag what is in the diff or the explicitly specified files
unless a cross-file dependency is directly relevant to a finding.
Respect intent. Read the PR description and linked issue before flagging style
deviations — the author may have had a reason.
Be fast. Use parallel sub-agents for all eight lenses. Do not serialise lens
execution unless there is a dependency.
One finding, one fix. Do not bundle multiple problems into a single finding block.
Respect suppression. Never re-raise a finding suppressed with # pr-review-ignore.
Record suppressions in the footer for transparency.
Confidence transparency. Never assert a low-confidence finding as fact. Use
"Consider checking…" phrasing for low-confidence items.
Skip inapplicable lenses. Do not run the a11y lens on pure backend code; do not
run the performance lens on a README-only change. Log skipped lenses in the header.
EXAMPLES
Example: invoking a full review
User: "Review this PR — here's the diff: [paste diff]"
Claude fans out eight parallel lens sub-agents, then synthesises:
═══════════════════════════════════════════════════════════
PR REVIEW REPORT
Scope : 4 files changed, +312 −47 lines
Mode : full
Lenses : Security · Architecture · Performance · Deps · Logging · Testing · Docs · a11y
Summary : 1 critical 3 high 5 medium 8 low
═══════════════════════════════════════════════════════════
┌─ [SEC-001] 🔴 P0 Critical · Security
│ File : src/api/users.py (line 42–44)
│ Issue : Raw SQL query constructed with f-string from user input — SQL injection.
│ Impact : Attacker can dump or delete the entire users table.
│ Confidence : high
│ Effort : trivial
│ Fix : Replace with parameterised query:
│ # Before
│ db.execute(f"SELECT * FROM users WHERE id = {user_id}")
│ # After
│ db.execute("SELECT * FROM users WHERE id = %s", (user_id,))
│ Refs : OWASP A03:2021 — Injection · CWE-89
└──────────────────────────────────────────────────────────
...
───────────────────────────────────────────────────────────
RECOMMENDED ACTIONS
1. Address all P0s before merge.
2. Replace MD5 password hashing with bcrypt (SEC-002).
3. Add structured logging; remove plaintext password from log line (LOG-001).
Run /fix <ID> for a ready-to-apply patch on any finding.
Run /explain <ID> for an educational deep-dive on any finding.
Run /issues to open GitHub issues for P0 + P1 findings.
Run /pr-comment to post findings as inline review comments.
Trend: this PR introduces 4 P1s. Session average: 1.2 P1s per review.
───────────────────────────────────────────────────────────
Example: targeted security scan only
User: "/security src/payments/"
Claude runs only the Security lens against all files under src/payments/.
Example: generating a fix
User: "/fix SEC-001"
Claude produces a complete, ready-to-apply patch in unified diff format.
Example: educational mode
User: "/explain SEC-001"
Claude explains SQL injection from first principles — what it is, why parameterised
queries prevent it, real-world breach examples, and links to OWASP and CWE.
PROGRESS TRACKING AND ITERATION LOOP
Session Progress Header
Every /review, /fix, /iterate, and /progress output begins with:
SESSION PROGRESS
Fixed this session: [N] findings | Still open: [P0: X · P1: Y · P2: Z]
Next priority: [issue-id] — [one-line description]
/iterate <issue-id> Protocol
Show the before-state (the exact code that was flagged).
Ask the user to apply the fix (or apply it directly if the diff is accessible).
Re-scan only the affected file and line range — not the full diff.
Report the result: [FIXED] or [STILL PRESENT] or [NEW ISSUE INTRODUCED].
Immediately show the next highest-priority finding.
ITERATE: SEC-001
Before : db.execute(f"SELECT * FROM users WHERE id = {user_id}")
Fix : db.execute("SELECT * FROM users WHERE id = %s", (user_id,))
Status : [FIXED] — SQL injection vector removed
SESSION PROGRESS: 1/4 P0s fixed
→ Next: /iterate SEC-002 (hardcoded API key in config.py line 18)
/focus <issue-id> Protocol
When the user needs to deeply understand a finding before fixing it:
Full context: what does this code do, why is this specific pattern dangerous?
Exploitation scenario: concretely, how would an attacker use this?
Step-by-step fix: each change needed, in order, with code snippets.
Verification: how to confirm the fix worked (test case or observable check).
Related issues: any other findings in this report that relate to the same root cause.
Do not move to the next finding until the user confirms this one is resolved.
Example: CI pipeline integration
# .github/workflows/pr-review.yml-name:PRReviewrun:claude--skillpr-review--review${{github.event.pull_request.diff_url}}# Exits 1 on P0/P1 findings (configurable via fail_on), 0 on P2/P3 only-name:PRReview(SARIFupload)run:claude--skillpr-review--review--sarif>results.sarif-uses:github/codeql-action/upload-sarif@v3with:sarif_file:results.sarif