con un clic
code-review
// Systematic code review and refactoring of a TypeScript/JavaScript codebase. Use when asked to audit, review, refactor, or improve code quality.
// Systematic code review and refactoring of a TypeScript/JavaScript codebase. Use when asked to audit, review, refactor, or improve code quality.
| name | code-review |
| description | Systematic code review and refactoring of a TypeScript/JavaScript codebase. Use when asked to audit, review, refactor, or improve code quality. |
A structured, collaborative process for discovering, prioritizing, and fixing code quality issues.
Goal: Understand the codebase, the user's priorities, and constraints before scanning anything.
Before running a single grep, ask the user:
any casts", "mcp.ts is a mess", "error handling is inconsistent")Let the user answer in shorthand. The goal is to avoid wasting time on findings they don't care about.
[!TIP] If the user dumps context freely ("just review everything"), that's fine — use it to guide the scan. If they're specific ("fix the type safety issues"), skip straight to the relevant scan category.
Exit condition: You know the scope, can name their top concern, and understand what tools/standards exist.
Goal: Build a complete picture before changing anything.
Run relevant scans in parallel. Skip categories the user excluded in Phase 1.
grep -rn "pattern" src/ --include="*.ts" | head -30
Common duplications:
shared.tserror instanceof Error ? error.message : error → extract to utilitygrep -rn "as any\|as unknown\|: any\|@ts-ignore\|@ts-expect-error" src/ --include="*.ts"
Categorize each hit:
any is correct (document with a comment why)catch blocks that swallow errors silentlyerrorCount always 0)wc -l src/**/*.ts | sort -rn | head -10
Files over 300 lines are decomposition candidates. Look for:
grep -rn "hardcoded\|TODO\|FIXME\|'0.1.0'\|localhost" src/ --include="*.ts"
Magic strings, hardcoded versions, region IDs, URLs that should be configurable.
Exit condition: You can list every finding with a category label. No more scans needed.
Goal: Present findings to the user and let them decide what to fix vs defer.
[!IMPORTANT] Never start fixing before the user approves the plan. Present, don't prescribe.
Group findings by category and suggest a priority order based on impact × effort:
| Priority | Category | Rationale |
|---|---|---|
| 1 | Code Duplication | Shared utilities benefit every subsequent fix |
| 2 | Type Safety | Catches bugs, makes refactoring safer |
| 3 | Monolith Decomposition | Largest structural win, enables parallel work |
| 4 | Dead Code / Bugs | Reduces noise, fixes real defects |
| 5 | Hardcoded Values | Quick wins, reduces config drift |
| 6+ | Abstractions / Tests / Docs | Often separate efforts |
Present the full list and ask the user to curate:
Accept shorthand: "1-4: keep, 5: defer, 6: skip" or "looks good, go ahead."
Create a task checklist (task.md) with [ ] items reflecting the user's approved plan.
Exit condition: User has approved a concrete, ordered list of what to fix.
Goal: Work through the approved fixes in order, verifying each one.
npm run build (or equivalent) — must pass before moving onnpm test — no regressionsnpm run lint — no new errorsnpm run format:check → fix with --write if needed[!CAUTION] If incremental edits compound errors in a file (cascading fixes that each break something new), stop and rewrite the file cleanly. Don't keep patching a broken state.
One logical commit per priority group:
git add -A && git commit -m "refactor: <category>
- bullet point per change
- mention files affected"
After most fixes have landed, pause and do a holistic pass:
If issues surface, fix them before continuing to the remaining items.
// Before: duplicated in 7 files
const client = new FooClient({ ...getConfig() });
// After: src/commands/shared.ts
export function createClient(): FooClient {
return new FooClient({ ...getConfig() });
}
Split into registrar functions — pure functions (server, deps) → void:
// src/handlers/auth.ts
export function registerAuthHandlers(server: Server, client: Client): void {
server.register('login', ...);
}
// src/main.ts (thin orchestrator)
registerAuthHandlers(server, client);
registerUserHandlers(server, client);
Key rules: zero coupling between modules, barrel export via index.ts.
// Before: hand-casting
if (e instanceof Error && 'response' in e) {
const axiosErr = e as { response?: { status?: number } };
}
// After: proper typing
import { AxiosError } from 'axios';
if (e instanceof AxiosError && e.response) {
// e.response is fully typed
}
Goal: Confirm everything works, do a fresh-eyes review, and document what was done.
npm run build && npm test && npm run lint && npm run format:check
Re-read the final codebase without thinking about the diffs. Pretend you're seeing it for the first time:
This catches issues that only made sense in the context of the changes but look wrong in the final state.
Create a walkthrough summarizing:
| Don't | Do Instead |
|---|---|
| Fix everything in one giant commit | One commit per priority group |
| Create abstractions speculatively | Extract only when 3+ concrete duplicates exist |
| Add base classes for 2 subclasses | Wait until the pattern is clear across 4+ |
| Rewrite working code for style alone | Focus on correctness, safety, and structure |
| Cascade incremental fixes on a broken file | Rewrite the file cleanly |
| Skip the build step after an edit | Always build immediately |
| Dictate priorities without asking | Present findings and let the user curate |
Tone: Be direct and procedural. Explain rationale briefly when it affects decisions, but don't over-justify. Show don't tell — code diffs over paragraphs.
Handling deviations:
Context management:
unknown[]?"), ask immediatelyQuality over speed: