Workflow Refactoring

Simplify Conditionals

Workflow for refactoring complex conditional logic

refactoringconditionalsreadability
CLAUDE.md

When simplifying complex conditional logic:

  1. Read the entire conditional block and understand every branch — document what each path does.
  2. Check for dead branches: conditions that can never be true. Remove them.
  3. Invert negative conditions to reduce nesting: if (!valid) return; // rest of logic instead of if (valid) { // deeply nested }.
  4. Extract complex conditions into named boolean variables: const isEligible = age >= 18 && hasConsent.
  5. If a switch/if-else has many branches, consider replacing it with a lookup table or strategy pattern.
  6. Run the tests after each simplification step to verify behavior is preserved.

Copy this workflow into your CLAUDE.md or agent config file so your agent follows this process automatically.

get crystl