simplify — Code Simplification
- Trigger:
/simplifyor keywords "simplify", "clean up", "duplicate code" - Best for: Post-review cleanup, refactoring cleanup, eliminating duplication
- Not for: Performance optimization, architectural refactoring, feature changes
Overview
simplify reviews changed code for reuse, quality, and efficiency issues, then fixes them. It focuses on micro-level code improvements: eliminating duplication, extracting shared logic, improving readability.
Trigger Conditions
simplify auto-triggers when you:
- Want to clean up after code changes
- Spot duplicate code
- Use the
/simplifycommand
Examples
Example 1: Eliminate Duplication
/simplify Review changes under src/components/ and remove duplicate codeBefore:
javascript
// UserList.tsx
const sorted = users.sort((a, b) => a.name.localeCompare(b.name));
// AdminList.tsx
const sorted = admins.sort((a, b) => a.name.localeCompare(b.name));After:
javascript
// utils/sortByName.ts
export const sortByName = <T extends { name: string }>(items: T[]) =>
[...items].sort((a, b) => a.name.localeCompare(b.name));Example 2: Simplify Conditionals
/simplify Simplify the permission checks in src/utils/permission.tsExample 3: Extract Shared Hook
/simplify UserProfile and AdminProfile have duplicate data fetching — extract a shared hookExample 4: Clean Up Redundant State
/simplify Review the Dashboard component, state management seems overly complexExample 5: Flatten Nested Callbacks
/simplify Convert callback chains in src/services/order.ts to async/awaitSimplification Principles
- DRY, not over-DRY — Abstract at three repetitions, tolerate two
- Names over comments — Replace explanatory comments with clear names
- Early returns — Guard clauses instead of deep if-else nesting
- Single responsibility — One function, one job
- Immutable data —
map/filter/reduceover mutating for-loops
Notes
- Focuses on micro-simplification, not large-scale architecture refactors
- Doesn't change external behavior — only optimizes internal implementation
- Simplified code may have more lines (e.g., extracted type definitions) but better readability
- Don't sacrifice readability for "clever" conciseness — that's a red line
- Three similar code blocks > one premature abstraction
Related Skills
- review — Review first, then simplify
- improve-codebase-architecture — Macro-level architecture improvement
- tdd — Use tests to ensure behavior is unchanged after simplification