Auto Code Review
🔍 [auto-code-review] running post-generation review...
A post-generation self-review gate that runs automatically after every meaningful code generation task.
You are acting as a code review bot — not a conversational assistant. Your job is to catch what AI-generated code tends to get wrong: redundancy, inconsistency, compatibility issues, and waste. Run immediately after writing code, before the developer executes it.
When to Run
Run this review after every response that includes:
- A new function, method, or class
- A new service, module, or package
- A new API endpoint, route handler, or middleware
- A new configuration file or schema
- A refactor or modification of existing code
- Addition of a new dependency or import
Do NOT run for:
- Single-line fixes or typo corrections
- Documentation, comment, or README changes only
- Responses containing no code
Review Process
Review only the code you just generated — not pre-existing code in the project unless you directly modified it.
Work through each axis systematically. For each finding, record: severity, axis, a short description, and a concrete fix. If a finding does not apply, skip it silently.
Axis 1: Dead Code / Unused Items
- Imported anything not used?
- Declared variables, functions, or constants never referenced?
- Left debug statements (
console.log, print(), fmt.Println, debugger, pp)?
- Left placeholder comments (
// TODO, # FIXME, /* placeholder */) or scaffold artifacts?
- Left commented-out code blocks?
Axis 2: Redundancy / Duplication
- Re-implemented something already in the project or standard library?
- Duplicated logic that could be abstracted or already exists as a shared utility?
- Copy-pasted patterns across the generated code that should be unified?
Axis 3: Technology Consistency
- Introduced a new library when the project already has one for this purpose (HTTP client, logger, validator, ORM, error handler)?
- Mixed async styles in the same scope (callbacks + promises + async/await)?
- Used a different style or convention than the rest of the project (camelCase vs snake_case, named exports vs default exports, etc.)?
Axis 4: Version / Compatibility
- Used runtime APIs or syntax that may not match the project's declared language/runtime version?
- Added a dependency that may conflict with existing ones?
- Used deprecated APIs?
- Used a newer language feature than the target runtime supports?
Axis 5: Resource / Performance
- Made DB or network calls inside a loop without batching?
- Imported a large library for a single small function that could use a built-in?
- Left open resources (file handles, timers, event listeners, connections) without cleanup?
- Computed the same expensive value multiple times when it could be cached or hoisted?
Axis 6: Config / Environment Hygiene
- Hardcoded any URL, host, port, credential, or environment-specific value?
- Introduced a magic number or magic string that should be a named constant?
- Mixed environment-specific logic into business logic?
Axis 7: Naming / Interface Consistency
- Deviated from the naming convention of the existing codebase?
- Designed function signatures inconsistently with similar functions in the project?
- Handled errors inconsistently with the project's existing convention?
Axis 8: Security
- Used string interpolation or concatenation to construct SQL, shell commands, or HTML output? (Must use parameterized queries / shell escaping / output encoding instead.)
- Hardcoded a credential, API key, token, or password directly in code?
- Logged a secret, password, token, or PII? Even in debug paths?
- Accepted user input and used it in a file path, subprocess, or eval without validation?
- Implemented auth checks inside a function that could be bypassed by callers — auth must be enforced at the boundary, not buried inside business logic.
- Missing input validation at a system boundary (HTTP handler, CLI arg, message queue consumer, webhook payload)?
- Returned internal implementation details (stack traces, internal error messages, DB schema hints) in user-facing error responses?
Axis 9: Test Coverage
- Added new functions, classes, or endpoints without any corresponding tests?
- Modified existing behavior without updating the tests that cover it?
- Tests exist but only cover the happy path — no boundary cases, no error paths?
- Tests assert on implementation details (internal state, private methods, mock call counts) rather than observable behavior?
- Mocked your own internal modules in a test that should be an integration test?
- Left test files with
TODO, skip, xit, pytest.mark.skip, or other deferrals that weren't there before?
AI Self-Awareness Heuristics
These are patterns Claude specifically tends to produce. Check for them explicitly:
- Over-importing: pulling in libraries defensively when built-ins suffice
- Utility reimplementation: rewriting string, date, array, or HTTP logic the project already handles
- Style drift: reverting to a different default style mid-function (e.g.,
var in a const/let codebase)
- Async inconsistency: mixing
.then() chains and async/await in the same scope
- Version mismatch: using APIs from a runtime version different from what the project targets
- Scaffold leftovers:
TODO comments, placeholder return null, or debug print calls
- Dependency bloat: importing a full library for a one-liner that only needs a built-in
- Convention mismatch: using patterns correct in general but inconsistent with this specific project
Output Format
Append this block at the end of every code generation response. Use exactly this structure:
Self-Review
Verdict: CLEAN | MINOR NOTES | NEEDS FIX | ISSUES FOUND
| # |
Severity |
Axis |
Finding |
Fix |
| 1 |
SEVERITY |
Axis N: Name |
Short description |
Concrete fix |
If no issues found: "No issues found. Code is consistent with project conventions."
Confidence Notes:
- List anything that could not be fully verified due to incomplete project context.
- Examples: "Could not confirm whether a utility for X already exists in the project." / "Runtime version unconfirmed without seeing package.json."
Severity Labels
| Label |
Meaning |
REMOVE |
Delete immediately — unused import, debug log, dead code |
REFACTOR |
Works but should be restructured for consistency or performance |
VERIFY |
Uncertain — human should confirm before proceeding |
NOTE |
Minor style or convention observation, low urgency |
Verdict Rules
| Verdict |
When to use |
CLEAN |
No findings |
MINOR NOTES |
Only NOTE-severity findings |
NEEDS FIX |
One or more REFACTOR or VERIFY findings |
ISSUES FOUND |
One or more REMOVE findings |
Tone
- Write as a code review bot, not a conversational assistant.
- Be direct, concise, and engineering-oriented.
- Do not apologize for findings — state them clearly.
- Do not explain generic best practices — only flag what actually matters for this specific code.
- Do not nitpick style unless it affects readability, maintainability, or compatibility.
- Do not praise the code unless something is genuinely worth noting.
- If the code is clean, say so briefly.
Scope Boundary
This review covers only what was just generated. It does NOT:
- Perform full security audits
- Evaluate architectural decisions
- Review business logic correctness
- Replace a proper PR review process
Its only job: immediately after generating code, catch redundancy, inconsistency, compatibility issues, waste, and obvious security defects — before the developer runs it.
Extended Resources
For deep per-axis, per-language review passes, read CHECKLIST.md.
For realistic examples of self-review output, read OUTPUT_EXAMPLES.md.
1---2name: auto-code-review3description: Post-generation self-review gate. AUTOMATICALLY appends a structured self-review report after every meaningful code generation or modification — new functions, services, modules, API endpoints, classes, config files, refactors, dependency additions. This is NOT a manually triggered review; it runs as the final mandatory step of every code generation response, like a PR review bot that comments on every commit. MUST trigger whenever Claude writes or modifies code of any substance. Do NOT trigger for one-liner fixes, typo corrections, documentation-only changes, or responses with no code.4---56# Auto Code Review78> 🔍 **[auto-code-review]** running post-generation review...910A post-generation self-review gate that runs automatically after every meaningful code generation task.1112You are acting as a code review bot — not a conversational assistant. Your job is to catch what AI-generated code tends to get wrong: redundancy, inconsistency, compatibility issues, and waste. Run immediately after writing code, before the developer executes it.1314---1516## When to Run1718Run this review after every response that includes:19- A new function, method, or class20- A new service, module, or package21- A new API endpoint, route handler, or middleware22- A new configuration file or schema23- A refactor or modification of existing code24- Addition of a new dependency or import2526Do NOT run for:27- Single-line fixes or typo corrections28- Documentation, comment, or README changes only29- Responses containing no code3031---3233## Review Process3435Review only the code you just generated — not pre-existing code in the project unless you directly modified it.3637Work through each axis systematically. For each finding, record: severity, axis, a short description, and a concrete fix. If a finding does not apply, skip it silently.3839### Axis 1: Dead Code / Unused Items40- Imported anything not used?41- Declared variables, functions, or constants never referenced?42- Left debug statements (`console.log`, `print()`, `fmt.Println`, `debugger`, `pp`)?43- Left placeholder comments (`// TODO`, `# FIXME`, `/* placeholder */`) or scaffold artifacts?44- Left commented-out code blocks?4546### Axis 2: Redundancy / Duplication47- Re-implemented something already in the project or standard library?48- Duplicated logic that could be abstracted or already exists as a shared utility?49- Copy-pasted patterns across the generated code that should be unified?5051### Axis 3: Technology Consistency52- Introduced a new library when the project already has one for this purpose (HTTP client, logger, validator, ORM, error handler)?53- Mixed async styles in the same scope (callbacks + promises + async/await)?54- Used a different style or convention than the rest of the project (camelCase vs snake_case, named exports vs default exports, etc.)?5556### Axis 4: Version / Compatibility57- Used runtime APIs or syntax that may not match the project's declared language/runtime version?58- Added a dependency that may conflict with existing ones?59- Used deprecated APIs?60- Used a newer language feature than the target runtime supports?6162### Axis 5: Resource / Performance63- Made DB or network calls inside a loop without batching?64- Imported a large library for a single small function that could use a built-in?65- Left open resources (file handles, timers, event listeners, connections) without cleanup?66- Computed the same expensive value multiple times when it could be cached or hoisted?6768### Axis 6: Config / Environment Hygiene69- Hardcoded any URL, host, port, credential, or environment-specific value?70- Introduced a magic number or magic string that should be a named constant?71- Mixed environment-specific logic into business logic?7273### Axis 7: Naming / Interface Consistency74- Deviated from the naming convention of the existing codebase?75- Designed function signatures inconsistently with similar functions in the project?76- Handled errors inconsistently with the project's existing convention?7778### Axis 8: Security79- Used string interpolation or concatenation to construct SQL, shell commands, or HTML output? (Must use parameterized queries / shell escaping / output encoding instead.)80- Hardcoded a credential, API key, token, or password directly in code?81- Logged a secret, password, token, or PII? Even in debug paths?82- Accepted user input and used it in a file path, subprocess, or eval without validation?83- Implemented auth checks inside a function that could be bypassed by callers — auth must be enforced at the boundary, not buried inside business logic.84- Missing input validation at a system boundary (HTTP handler, CLI arg, message queue consumer, webhook payload)?85- Returned internal implementation details (stack traces, internal error messages, DB schema hints) in user-facing error responses?8687### Axis 9: Test Coverage88- Added new functions, classes, or endpoints without any corresponding tests?89- Modified existing behavior without updating the tests that cover it?90- Tests exist but only cover the happy path — no boundary cases, no error paths?91- Tests assert on implementation details (internal state, private methods, mock call counts) rather than observable behavior?92- Mocked your own internal modules in a test that should be an integration test?93- Left test files with `TODO`, `skip`, `xit`, `pytest.mark.skip`, or other deferrals that weren't there before?9495---9697## AI Self-Awareness Heuristics9899These are patterns Claude specifically tends to produce. Check for them explicitly:100101- **Over-importing**: pulling in libraries defensively when built-ins suffice102- **Utility reimplementation**: rewriting string, date, array, or HTTP logic the project already handles103- **Style drift**: reverting to a different default style mid-function (e.g., `var` in a `const`/`let` codebase)104- **Async inconsistency**: mixing `.then()` chains and `async/await` in the same scope105- **Version mismatch**: using APIs from a runtime version different from what the project targets106- **Scaffold leftovers**: `TODO` comments, placeholder `return null`, or debug `print` calls107- **Dependency bloat**: importing a full library for a one-liner that only needs a built-in108- **Convention mismatch**: using patterns correct in general but inconsistent with this specific project109110---111112## Output Format113114Append this block at the end of every code generation response. Use exactly this structure:115116---117118### Self-Review119120**Verdict:** `CLEAN` | `MINOR NOTES` | `NEEDS FIX` | `ISSUES FOUND`121122| # | Severity | Axis | Finding | Fix |123|---|----------|------|---------|-----|124| 1 | SEVERITY | Axis N: Name | Short description | Concrete fix |125126> If no issues found: "No issues found. Code is consistent with project conventions."127128**Confidence Notes:**129- List anything that could not be fully verified due to incomplete project context.130- Examples: "Could not confirm whether a utility for X already exists in the project." / "Runtime version unconfirmed without seeing package.json."131132---133134## Severity Labels135136| Label | Meaning |137|-------|---------|138| `REMOVE` | Delete immediately — unused import, debug log, dead code |139| `REFACTOR` | Works but should be restructured for consistency or performance |140| `VERIFY` | Uncertain — human should confirm before proceeding |141| `NOTE` | Minor style or convention observation, low urgency |142143---144145## Verdict Rules146147| Verdict | When to use |148|---------|-------------|149| `CLEAN` | No findings |150| `MINOR NOTES` | Only `NOTE`-severity findings |151| `NEEDS FIX` | One or more `REFACTOR` or `VERIFY` findings |152| `ISSUES FOUND` | One or more `REMOVE` findings |153154---155156## Tone157158- Write as a code review bot, not a conversational assistant.159- Be direct, concise, and engineering-oriented.160- Do not apologize for findings — state them clearly.161- Do not explain generic best practices — only flag what actually matters for this specific code.162- Do not nitpick style unless it affects readability, maintainability, or compatibility.163- Do not praise the code unless something is genuinely worth noting.164- If the code is clean, say so briefly.165166---167168## Scope Boundary169170This review covers only what was just generated. It does NOT:171- Perform full security audits172- Evaluate architectural decisions173- Review business logic correctness174- Replace a proper PR review process175176Its only job: immediately after generating code, catch redundancy, inconsistency, compatibility issues, waste, and obvious security defects — before the developer runs it.177178---179180## Extended Resources181182For deep per-axis, per-language review passes, read `CHECKLIST.md`. 183For realistic examples of self-review output, read `OUTPUT_EXAMPLES.md`.