simplify
Review code for reuse, quality, and efficiency issues, then fix them. Works on recently changed files, specific files/modules, or whatever you point it at. Pass optional text to focus on specific concerns.
Simplify: Code Review and Cleanup
$ARGUMENTS
Phase 1: Identify Scope
Determine what to review:
- If the user specified files, modules, or directories — review those
- If the user described a concern — find the relevant code
- If nothing was specified — fall back to
git diff(orgit diff HEADif staged) to review recent changes - If no git changes either — ask what to review
Phase 2: Review
Perform all three reviews on the target code.
Review 1: Code Reuse
- Search for existing utilities and helpers that could replace code. Use grep/search to find similar patterns elsewhere in the codebase — utility directories, shared modules, and adjacent files.
- Flag any function that duplicates existing functionality. Suggest the existing function instead.
- Flag inline logic that could use an existing utility — hand-rolled string manipulation, manual path handling, custom environment checks, ad-hoc type guards, and similar.
Review 2: Code Quality
- Redundant state: state that duplicates existing state, cached values that could be derived, observers/effects that could be direct calls
- Parameter sprawl: too many parameters instead of generalizing or restructuring
- Copy-paste with slight variation: near-duplicate code blocks that should be unified
- Leaky abstractions: exposing internal details that should be encapsulated, or breaking existing abstraction boundaries
- Stringly-typed code: using raw strings where constants, enums, or branded types already exist in the codebase
- Dead code: unused functions, unreachable branches, commented-out blocks that should be removed
Review 3: Efficiency
- Unnecessary work: redundant computations, repeated file reads, duplicate network/API calls, N+1 patterns
- Missed concurrency: independent operations run sequentially when they could run in parallel
- Hot-path bloat: blocking work on startup or per-request/per-render hot paths
- Unnecessary existence checks: pre-checking file/resource existence before operating (TOCTOU anti-pattern) — operate directly and handle the error
- Memory: unbounded data structures, missing cleanup, event listener leaks
- Overly broad operations: reading entire files when only a portion is needed, loading all items when filtering for one
Phase 3: Fix Issues
Fix each issue directly. If a finding is a false positive or not worth addressing, skip it.
When done, briefly summarize what was fixed (or confirm the code was already clean).