Skip to content
Development
Command

/simplify-fn

Refactor a complex function to reduce cyclomatic complexity.

From plugin
claude-code-toolkit
2.8k199 skills138 agents199 commands
$ npx -y skills add rohitg00/awesome-claude-code-toolkit --agent claude-code

Command definition

simplify-fn.md

/simplify-fn - Simplify Complex Function

Refactor a complex function to reduce cyclomatic complexity.

Steps

1. Read the target function and calculate its current complexity score 2. Identify the primary complexity drivers: nested ifs, loops, switch statements 3. Map the function's control flow to understand all execution paths 4. Apply Extract Method refactoring: pull out logical blocks into named functions 5. Replace nested conditionals with guard clauses (early returns) 6. Convert switch statements to lookup tables or strategy pattern where appropriate 7. Replace complex boolean expressions with named boolean variables 8. Decompose loops with multiple responsibilities into separate loops or higher-order functions 9. Apply polymorphism to replace type-checking conditionals when applicable 10. Verify the refactored code preserves all original behavior by running tests 11. Calculate the new complexity score and report the improvement 12. Ensure the refactored code is readable and properly named

Rules

  • Preserve all existing behavior; this is refactoring, not feature change
  • Run tests after each refactoring step to catch regressions immediately
  • Target a complexity score of 5 or below for the main function
  • Keep extracted functions small (under 15 lines) and single-purpose
  • Use descriptive names for extracted functions that explain the "why"
  • Do not introduce new dependencies or external libraries
  • If tests do not exist, write them before refactoring
Read more
@rohitg00
Ships withclaude-code-toolkit

The most comprehensive toolkit for Claude Code -- 135 agents, 35 curated skills (+400,000 via SkillKit), 42 commands, 176+ plugins, 20 hooks, 15 rules, 7 templates, 15 MCP configs, 26 companion apps, 53 ecosystem entries, and more.

2.8k40 skills138 agents
Get the whole plugin

Stars on GitHub

Momentum

stars in total
2.8k
Star history of rohitg00/awesome-claude-code-toolkit on GitHub, a chart by star-history.com

Other commands on claude-code-toolkit.

More commands from other plugins.

build
Auto-invoked

build

Command

Implement tasks incrementally — build, test, verify, commit. Add "auto" to run the whole plan in one approved pass.

@addyosmani@addyosmaniInstall Command