Simplify Conditionals
Workflow for refactoring complex conditional logic
CLAUDE.md
When simplifying complex conditional logic:
- Read the entire conditional block and understand every branch — document what each path does.
- Check for dead branches: conditions that can never be true. Remove them.
- Invert negative conditions to reduce nesting:
if (!valid) return; // rest of logicinstead ofif (valid) { // deeply nested }. - Extract complex conditions into named boolean variables:
const isEligible = age >= 18 && hasConsent. - If a switch/if-else has many branches, consider replacing it with a lookup table or strategy pattern.
- 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.