home / skills / bejranonda / llm-autonomous-agent-plugin-for-claude / code-analysis

code-analysis skill

/skills/code-analysis

This skill analyzes code structure, metrics, and smells to guide refactoring and improve quality across languages.

npx playbooks add skill bejranonda/llm-autonomous-agent-plugin-for-claude --skill code-analysis

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
1.4 KB
---
name: code-analysis
description: Provides methodologies, metrics, and best practices for analyzing code structure, complexity, and quality
version: 1.0.0
---

## Overview

This skill provides comprehensive knowledge for code analysis including complexity metrics, anti-pattern detection, refactoring strategies, and code quality assessment across multiple programming languages.

## Complexity Metrics

### Cyclomatic Complexity
- **Low**: 1-10 (simple, easy to test)
- **Medium**: 11-20 (moderate complexity, acceptable)
- **High**: 21-50 (complex, needs refactoring)
- **Very High**: 51+ (critical, must refactor)

### Cognitive Complexity
Measures how difficult code is to understand based on nesting, control flow breaks, and recursion.

## Code Smells to Detect

- **Long Methods**: >50 lines
- **Large Classes**: >300 lines
- **Duplicate Code**: Repeated blocks
- **Long Parameter Lists**: >5 parameters
- **Deep Nesting**: >4 levels
- **God Objects**: Classes doing too much
- **Dead Code**: Unused functions/variables

## Refactoring Strategies

- **Extract Method**: Break long methods into smaller ones
- **Extract Class**: Split large classes by responsibility
- **Replace Conditional with Polymorphism**
- **Simplify Conditional Expressions**
- **Remove Duplicate Code**

## When to Apply

Use when analyzing codebase structure, identifying refactoring opportunities, or assessing code quality.

Overview

This skill provides practical methodologies, metrics, and best practices for analyzing code structure, complexity, and quality across multiple languages. It helps identify complexity hotspots, common code smells, and actionable refactoring strategies to improve maintainability and testability.

How this skill works

The skill inspects code metrics such as cyclomatic and cognitive complexity, file and function sizes, parameter counts, nesting depth, and duplication patterns. It highlights anti-patterns (long methods, god objects, dead code) and maps each finding to concrete refactor suggestions and priority levels. Reports can be used to guide code reviews, automated gating, and continuous improvement efforts.

When to use it

  • During code reviews to prioritize risky changes
  • When onboarding to a new codebase to learn structure and hotspots
  • Before major refactors or releases to reduce technical debt
  • As part of CI pipelines to enforce quality gates
  • When tracking longitudinal code quality and team progress

Best practices

  • Set concrete thresholds for metrics (e.g., cyclomatic complexity bands) and apply them consistently
  • Combine automated detection with human review — tools find candidates, developers validate intent
  • Prioritize refactors by impact and risk; fix high-complexity, frequently changed code first
  • Prefer small, reversible refactors (extract method/class) and add tests before changes
  • Track trends over time and integrate findings into team retrospectives

Example use cases

  • Run a baseline analysis to find files with cyclomatic complexity >20 and schedule refactors
  • Detect duplicated code blocks across the project and plan extraction to shared utilities
  • Identify long parameter lists and apply parameter object or builder refactors
  • Locate deep nesting and replace conditionals with guard clauses or polymorphism
  • Scan for dead code and remove unused functions after ensuring test coverage

FAQ

What complexity thresholds should I use?

Use bands like Low (1–10), Medium (11–20), High (21–50), Very High (51+) and adapt to your team’s tolerance and domain risk.

How do I balance metric-driven changes with delivery deadlines?

Prioritize fixes by frequency of change and risk; schedule low-risk refactors during maintenance windows and address critical hotspots first.