Skip to content

simplify — Code Simplification

  • Trigger: /simplify or 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 /simplify command

Examples

Example 1: Eliminate Duplication

/simplify Review changes under src/components/ and remove duplicate code

Before:

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.ts

Example 3: Extract Shared Hook

/simplify UserProfile and AdminProfile have duplicate data fetching — extract a shared hook

Example 4: Clean Up Redundant State

/simplify Review the Dashboard component, state management seems overly complex

Example 5: Flatten Nested Callbacks

/simplify Convert callback chains in src/services/order.ts to async/await

Simplification Principles

  1. DRY, not over-DRY — Abstract at three repetitions, tolerate two
  2. Names over comments — Replace explanatory comments with clear names
  3. Early returns — Guard clauses instead of deep if-else nesting
  4. Single responsibility — One function, one job
  5. Immutable datamap/filter/reduce over 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