Code Review
Description
Code review inspects a concrete code change (diff, PR, or file set) and reports evidence-backed findings: what is wrong or risky, why, where (file/line), and how severe it is. It is not a vague opinion and not a rewrite of the code unless the task explicitly asks for fixes.
Activate this skill when the user asks to review, critique, assess, or find issues in source code. Prefer this skill over web search or RAG when the subject is the code itself.
When to Use
- A pull request, diff, or set of source files must be reviewed for correctness, security, or maintainability.
- The task names acceptance criteria, coding standards, or test expectations to check against.
- The user wants a structured findings list before merge or ship.
Do not use when:
- The user only wants an explanation of how code review works, with no code to inspect (answer conceptually; do not pretend to review).
- The task is pure code generation with no review request (use Code Generation).
- The need is open-web research (use Web Search) or private-corpus Q&A (use RAG).
Inputs / Outputs
| Field |
Type |
Description |
diff_or_files |
str / list[File] |
Unified diff, PR patch, or file contents under review |
acceptance_criteria |
list[str] |
Optional explicit requirements or standards |
security_policy |
object |
Optional constraints (no secrets, no privilege escalation, etc.) |
→ findings |
list[Finding] |
Ordered by severity |
→ findings[i].severity |
critical|high|medium|low|info |
Impact if unfixed |
→ findings[i].location |
str |
path:line or range |
→ findings[i].evidence |
str |
Quote or concrete observation from the code |
→ findings[i].recommendation |
str |
Actionable fix direction |
→ summary |
str |
Short overall assessment |
→ block_merge |
bool |
True if any critical/high unresolved finding |
Review Procedure
- Establish scope: which files/hunks are in the change; ignore unrelated code.
- Check correctness against stated requirements or obvious invariants.
- Check security: injection, authz, secrets, unsafe deserialization, path traversal.
- Check tests: new behavior covered; existing tests not deleted without cause.
- Check maintainability: naming, complexity, dead code, API contracts.
- Check repository conventions and existing gates (lint, types, CI).
- Emit findings with severity + location + evidence; do not invent issues not grounded in the diff.
- Set
block_merge only for critical/high issues or policy violations.
Runnable Example
from __future__ import annotations
from dataclasses import dataclass
@dataclass
class Finding:
severity: str
location: str
evidence: str
recommendation: str
def review_diff(diff_text: str, acceptance: list[str] | None = None) -> dict:
"""Minimal checklist-style review over a unified diff string."""
findings: list[Finding] = []
lines = diff_text.splitlines()
for i, line in enumerate(lines):
if line.startswith("+") and not line.startswith("+++"):
body = line[1:]
lowered = body.lower()
if "hardcoded_token" in lowered or ("password" + " = ") in lowered:
findings.append(Finding(
severity="critical",
location=f"diff:{i+1}",
evidence=body.strip()[:120],
recommendation="Remove hardcoded credentials; use env or a secret manager.",
))
if "todo: fix later" in lowered and acceptance:
findings.append(Finding(
severity="medium",
location=f"diff:{i+1}",
evidence=body.strip()[:120],
recommendation="Resolve or ticket TODOs that affect acceptance criteria before merge.",
))
if acceptance and not any("test" in l.lower() for l in lines if l.startswith("+")):
findings.append(Finding(
severity="high",
location="diff:global",
evidence="No test-related additions detected in diff",
recommendation="Add or update tests for the new behavior.",
))
severity_rank = {"critical": 0, "high": 1, "medium": 2, "low": 3, "info": 4}
findings.sort(key=lambda f: severity_rank.get(f.severity, 9))
block = any(f.severity in ("critical", "high") for f in findings)
return {
"findings": findings,
"summary": f"{len(findings)} finding(s); block_merge={block}",
"block_merge": block,
}
if __name__ == "__main__":
sample = (
"+++ b/app.py\n+"
+ "hardcoded_" + "token" + " = " + '"placeholder-not-a-real-secret"'
+ "\n+def refund(amount): return True\n"
)
out = review_diff(sample, acceptance=["refunds must be tested"])
print(out["summary"])
for f in out["findings"]:
print(f.severity, f.location, f.recommendation)
Failure Modes
| Failure |
Cause |
Mitigation |
| Invented bugs |
Model guesses without reading the diff |
Require every finding to quote evidence from the change |
| Scope creep |
Reviewing files not in the PR |
Limit to changed hunks unless asked for full-file review |
| Nitpick flood |
Style noise hides real issues |
Cap low/info; lead with critical/high |
| Missed secrets |
Pattern not recognized |
Run secret scanning; deny merge on credential literals |
| Rubber-stamp approve |
No criteria, shallow pass |
Walk correctness → security → tests → conventions explicitly |
| False "review" with no code |
User asked how review works, not to review |
Do not activate full review procedure; answer conceptually |
| Claiming merge-ready without tests |
Tests absent or deleted |
High severity finding; block_merge=true |
Security Boundary
- Never recommend disabling security gates to make CI green.
- Flag secrets, unsafe
eval, unrestricted deserialization, and authz bypasses as critical/high.
- Do not exfiltrate proprietary code beyond the review response channel.
Related Skills
- Security Scanning — specialized secret/pattern detection in the code category
- Secret Scanning — security-category secret detection contract
- Git Diff Reading — parse and scope the change set
- Unit Test Generation — add tests for reviewed behavior
- Debugging — investigate failures found in review
- Code Generation — implement fixes after review
Evidence
Repository-backed guidance aligned with validation and security workflows. No external benchmark score is claimed for this skill version.
Changelog
| Date |
Version |
Change |
| 2026-09 |
v1 |
Initial stub-level skill |
| 2026-10 |
v2 |
Activation-oriented rewrite: when/not-to-use, typed findings, procedure, runnable checklist, failure modes for selection reliability |
1---2name: code-review3description: Review a code change for correctness, security, maintainability, tests, and repository conventions; return evidence-backed findings with severity and file/line anchors. Activate when the task is to review, critique, or assess source code quality—not when the task is only to explain review theory without inspecting code.4metadata:5 source: https://skillmd.com/skills/samotech/code-review6 upstream: skills/05-code/code-review.md7 category: 05-code8 version: "v2"9---1011# Code Review1213## Description1415Code review inspects a concrete code change (diff, PR, or file set) and reports **evidence-backed findings**: what is wrong or risky, why, where (file/line), and how severe it is. It is not a vague opinion and not a rewrite of the code unless the task explicitly asks for fixes.1617Activate this skill when the user asks to **review**, **critique**, **assess**, or **find issues in** source code. Prefer this skill over web search or RAG when the subject is the code itself.1819## When to Use2021- A pull request, diff, or set of source files must be reviewed for correctness, security, or maintainability.22- The task names acceptance criteria, coding standards, or test expectations to check against.23- The user wants a structured findings list before merge or ship.2425**Do not use** when:26- The user only wants an explanation of *how* code review works, with **no code to inspect** (answer conceptually; do not pretend to review).27- The task is pure code generation with no review request (use [Code Generation](code-generation.md)).28- The need is open-web research (use [Web Search](../11-web/web-search.md)) or private-corpus Q&A (use [RAG](../03-memory/rag.md)).2930## Inputs / Outputs3132| Field | Type | Description |33|---|---|---|34| `diff_or_files` | `str` / `list[File]` | Unified diff, PR patch, or file contents under review |35| `acceptance_criteria` | `list[str]` | Optional explicit requirements or standards |36| `security_policy` | `object` | Optional constraints (no secrets, no privilege escalation, etc.) |37| → `findings` | `list[Finding]` | Ordered by severity |38| → `findings[i].severity` | `critical\|high\|medium\|low\|info` | Impact if unfixed |39| → `findings[i].location` | `str` | `path:line` or range |40| → `findings[i].evidence` | `str` | Quote or concrete observation from the code |41| → `findings[i].recommendation` | `str` | Actionable fix direction |42| → `summary` | `str` | Short overall assessment |43| → `block_merge` | `bool` | True if any critical/high unresolved finding |4445## Review Procedure46471. Establish scope: which files/hunks are in the change; ignore unrelated code.482. Check **correctness** against stated requirements or obvious invariants.493. Check **security**: injection, authz, secrets, unsafe deserialization, path traversal.504. Check **tests**: new behavior covered; existing tests not deleted without cause.515. Check **maintainability**: naming, complexity, dead code, API contracts.526. Check **repository conventions** and existing gates (lint, types, CI).537. Emit findings with severity + location + evidence; do not invent issues not grounded in the diff.548. Set `block_merge` only for critical/high issues or policy violations.5556## Runnable Example5758```python59from __future__ import annotations60from dataclasses import dataclass6162@dataclass63class Finding:64 severity: str65 location: str66 evidence: str67 recommendation: str6869def review_diff(diff_text: str, acceptance: list[str] | None = None) -> dict:70 """Minimal checklist-style review over a unified diff string."""71 findings: list[Finding] = []72 lines = diff_text.splitlines()7374 for i, line in enumerate(lines):75 if line.startswith("+") and not line.startswith("+++"):76 body = line[1:]77 lowered = body.lower()78 if "hardcoded_token" in lowered or ("password" + " = ") in lowered:79 findings.append(Finding(80 severity="critical",81 location=f"diff:{i+1}",82 evidence=body.strip()[:120],83 recommendation="Remove hardcoded credentials; use env or a secret manager.",84 ))85 if "todo: fix later" in lowered and acceptance:86 findings.append(Finding(87 severity="medium",88 location=f"diff:{i+1}",89 evidence=body.strip()[:120],90 recommendation="Resolve or ticket TODOs that affect acceptance criteria before merge.",91 ))9293 if acceptance and not any("test" in l.lower() for l in lines if l.startswith("+")):94 findings.append(Finding(95 severity="high",96 location="diff:global",97 evidence="No test-related additions detected in diff",98 recommendation="Add or update tests for the new behavior.",99 ))100101 severity_rank = {"critical": 0, "high": 1, "medium": 2, "low": 3, "info": 4}102 findings.sort(key=lambda f: severity_rank.get(f.severity, 9))103 block = any(f.severity in ("critical", "high") for f in findings)104 return {105 "findings": findings,106 "summary": f"{len(findings)} finding(s); block_merge={block}",107 "block_merge": block,108 }109110if __name__ == "__main__":111 sample = (112 "+++ b/app.py\n+"113 + "hardcoded_" + "token" + " = " + '"placeholder-not-a-real-secret"'114 + "\n+def refund(amount): return True\n"115 )116 out = review_diff(sample, acceptance=["refunds must be tested"])117 print(out["summary"])118 for f in out["findings"]:119 print(f.severity, f.location, f.recommendation)120```121122## Failure Modes123124| Failure | Cause | Mitigation |125|---|---|---|126| Invented bugs | Model guesses without reading the diff | Require every finding to quote evidence from the change |127| Scope creep | Reviewing files not in the PR | Limit to changed hunks unless asked for full-file review |128| Nitpick flood | Style noise hides real issues | Cap low/info; lead with critical/high |129| Missed secrets | Pattern not recognized | Run secret scanning; deny merge on credential literals |130| Rubber-stamp approve | No criteria, shallow pass | Walk correctness → security → tests → conventions explicitly |131| False "review" with no code | User asked how review works, not to review | Do not activate full review procedure; answer conceptually |132| Claiming merge-ready without tests | Tests absent or deleted | High severity finding; `block_merge=true` |133134## Security Boundary135136- Never recommend disabling security gates to make CI green.137- Flag secrets, unsafe `eval`, unrestricted deserialization, and authz bypasses as critical/high.138- Do not exfiltrate proprietary code beyond the review response channel.139140## Related Skills141142- [Security Scanning](security-scanning.md) — specialized secret/pattern detection in the code category143- [Secret Scanning](../14-security/secret-scanning.md) — security-category secret detection contract144- [Git Diff Reading](../01-perception/git-diff-reading.md) — parse and scope the change set145- [Unit Test Generation](unit-test-generation.md) — add tests for reviewed behavior146- [Debugging](debugging.md) — investigate failures found in review147- [Code Generation](code-generation.md) — implement fixes after review148149## Evidence150151Repository-backed guidance aligned with validation and security workflows. No external benchmark score is claimed for this skill version.152153## Changelog154155| Date | Version | Change |156|---|---|---|157| 2026-09 | v1 | Initial stub-level skill |158| 2026-10 | v2 | Activation-oriented rewrite: when/not-to-use, typed findings, procedure, runnable checklist, failure modes for selection reliability |