complexity-reducer

Generate behavior-preserving refactoring plans with quantified complexity metrics.

3|2|Updated Jan 23, 2026
One-click install
npx skills add https://github.com/robotijn/ctoc --skill complexity-reducer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: complexity-reducer
Source: https://github.com/robotijn/ctoc/tree/main/skills/quality/complexity-reducer
Command: npx skills add https://github.com/robotijn/ctoc --skill complexity-reducer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill eliminates the guesswork and regression risk of refactoring complex, hard-to-maintain code by providing step-by-step, behaviour-preserving refactoring plans with measurable complexity reduction targets.

Core Features & Use Cases

  • Quantified Refactoring Plans: Calculates exact cyclomatic and cognitive complexity before and after each refactoring step, with clear effort estimates and risk ratings.
  • Multi-Language Pattern Catalog: Includes before/after examples and AST-based codemod recipes for 7 languages (C#, Java, Python, C, C++, TypeScript, SQL) aligned with Fowler's refactoring best practices.
  • Safety Guardrails: Enforces an 80% test coverage prerequisite before recommending refactors, and grades finding severity based on impact to current development workflows.
  • Use Case: For a 95-LOC payment processing function with a cyclomatic complexity of 18 and 4 levels of nested conditionals, use this skill to get a plan that reduces complexity by 75%, includes guard clause extractions, and provides a libCST codemod for repeated conditional patterns across the codebase.

Quick Start

Use the complexity-reducer skill to generate a refactoring plan for the complex validate_order function in src/orders/validator.py, including quantified complexity metrics and codemod recipes for repeated type-checking conditionals.

Frequently Asked Questions about complexity-reducer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor complex code while preserving original behavior?

Behaviour-preserving refactoring requires step-by-step plans that quantify cyclomatic and cognitive complexity reduction before and after each step. This approach eliminates regression risk by calculating exact metrics for complex, hard-to-maintain code.

What is the best way to reduce cyclomatic complexity in legacy Python code?

To reduce cyclomatic complexity in legacy Python code, apply AST-based codemod recipes and guard clause extractions. This provides measurable complexity reduction targets while following Fowler's refactoring best practices for maintainable code.

Does behaviour-preserving refactoring require a specific test coverage threshold?

Yes, behaviour-preserving refactoring enforces an 80% test coverage prerequisite before recommending any code changes. This safety guardrail validates refactoring steps and grades finding severity based on impact to current development workflows.

Can I generate codemod recipes for cross-file changes in Java and C#?

Yes, you can generate AST-based codemod recipes for cross-file changes in Java and C#. The multi-language pattern catalog provides before/after examples and codemod recipes for 7 supported languages including C#, Java, Python, C, C++, TypeScript, and SQL.

How do I quantify technical debt reduction for nested conditional functions?

You can quantify technical debt reduction by calculating exact cyclomatic and cognitive complexity before and after refactoring nested conditional functions. This yields measurable complexity reduction percentages, effort estimates, and risk ratings for each step.