This loop iteratively analyzes and reduces code complexity by generating complexity reports, identifying high-complexity areas, and applying refactoring techniques until the specified threshold is met.
Lower code complexity to meet specified thresholds through automated analysis and refactoring
Run this loop in your coding agent to automatically reduce code complexity through iterative analysis and refactoring
Set Target Threshold
Define the acceptable complexity threshold (e.g., average cyclomatic complexity < 10)
Select Target File(s)
Specify the file(s) or directory to analyze for complexity reduction
Execute Loop
Run the loop in your coding agent - it will automatically analyze, report, and refactor until the exit condition is met
Review Changes
After loop completion, review the complexity reductions and ensure functionality remains intact
Analyze code structure and generate initial complexity report
Use static analysis tools to measure cyclomatic complexity, cognitive complexity, and other metrics across the codebase
Quality
Automatically identifies and removes unused code to improve codebase quality and maintainability. This loop performs iterative scans for dead code, removes it gradually, and ensures no regressions are introduced.
Quality
Automatically iterates through lint error detection and resolution until the codebase passes linting with zero issues. This loop ensures code quality and consistency by having the agent fix problems as they are identified.
Quality
This loop systematically refactors your codebase to improve structure while maintaining test coverage. The agent identifies opportunities for cleaner code without breaking existing functionality.
Identify high-complexity functions and modules
Flag functions with cyclomatic complexity > 10, nesting levels > 4, or excessive conditional branches
Generate detailed complexity breakdown
Create per-function complexity scores and highlight areas contributing most to overall complexity
Apply targeted refactoring strategies
Break down large functions, extract methods, simplify conditionals, reduce nesting, and eliminate duplicate logic
Re-analyze refactored code
Run complexity report again to measure improvement and identify remaining hotspots
Check exit condition
If thresholds are met or max iterations reached, stop. Otherwise, continue to next iteration
Start the "Complexity Reducer" loop. Goal: Lower code complexity to meet specified thresholds through automated analysis and refactoring Max iterations: 10 Between iterations run: complexity report Exit when: Average cyclomatic complexity below target threshold (e.g., 10) OR all functions under individual complexity threshold (e.g., 20) Please analyze the complexity of my code and iteratively reduce it. Start by running a comprehensive complexity report on the target codebase. Once you have the baseline metrics, identify the highest-complexity functions and apply appropriate refactoring techniques. Continue this analyze-refactor cycle until the average cyclomatic complexity is below 10 or no further meaningful reductions are possible. Focus on breaking down large functions, simplifying conditional logic, and improving overall maintainability without changing the program's behavior. Self-pace this loop. After each iteration, run `complexity report` and evaluate the output, and only continue if the exit condition is not met (Average cyclomatic complexity below target threshold (e.g., 10) OR all functions under individual complexity threshold (e.g., 20)). Stop when the exit condition passes or 10 iterations are reached. Give a short status update each pass.