home / skills / a5c-ai / babysitter / code-complexity-analyzer

This skill analyzes code complexity and debt to guide refactoring and performance improvements across projects.

npx playbooks add skill a5c-ai/babysitter --skill code-complexity-analyzer

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

Files (2)
SKILL.md
2.8 KB
---
name: code-complexity-analyzer
description: Analyze code complexity metrics including cyclomatic complexity, code smells, and technical debt
allowed-tools:
  - Bash
  - Read
  - Write
  - Glob
  - Grep
---

# Code Complexity Analyzer Skill

## Overview

Analyzes code complexity metrics including cyclomatic complexity, cognitive complexity, code smells, duplicate code detection, and technical debt scoring.

## Capabilities

- Calculate cyclomatic complexity
- Calculate cognitive complexity
- Identify code smells
- Dependency analysis
- Duplicate code detection
- Technical debt scoring
- Maintainability index calculation
- Lines of code metrics

## Target Processes

- refactoring-plan
- performance-optimization
- system-design-review

## Input Schema

```json
{
  "type": "object",
  "required": ["paths"],
  "properties": {
    "paths": {
      "type": "array",
      "items": { "type": "string" },
      "description": "Paths to analyze (supports glob patterns)"
    },
    "metrics": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": ["cyclomatic", "cognitive", "loc", "dependencies", "duplicates", "maintainability"]
      },
      "default": ["cyclomatic", "cognitive", "loc"]
    },
    "thresholds": {
      "type": "object",
      "properties": {
        "cyclomatic": { "type": "number", "default": 10 },
        "cognitive": { "type": "number", "default": 15 },
        "duplicateLines": { "type": "number", "default": 6 }
      }
    },
    "languages": {
      "type": "array",
      "items": { "type": "string" },
      "description": "Languages to analyze"
    }
  }
}
```

## Output Schema

```json
{
  "type": "object",
  "properties": {
    "files": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "path": { "type": "string" },
          "metrics": {
            "type": "object",
            "properties": {
              "cyclomatic": { "type": "number" },
              "cognitive": { "type": "number" },
              "loc": { "type": "number" },
              "maintainability": { "type": "number" }
            }
          },
          "violations": { "type": "array" }
        }
      }
    },
    "summary": {
      "type": "object",
      "properties": {
        "totalFiles": { "type": "number" },
        "averageComplexity": { "type": "number" },
        "technicalDebtScore": { "type": "number" },
        "hotspots": { "type": "array" }
      }
    },
    "duplicates": {
      "type": "array"
    }
  }
}
```

## Usage Example

```javascript
{
  kind: 'skill',
  skill: {
    name: 'code-complexity-analyzer',
    context: {
      paths: ['src/**/*.ts'],
      metrics: ['cyclomatic', 'cognitive', 'loc', 'dependencies'],
      thresholds: { cyclomatic: 10, cognitive: 15 }
    }
  }
}
```

Overview

This skill analyzes code complexity metrics across a codebase to surface risk, maintainability issues, and refactoring targets. It computes cyclomatic and cognitive complexity, counts lines of code, detects duplicates and code smells, and produces a technical debt score and hotspots. The output highlights files and functions that exceed configured thresholds so teams can prioritize work.

How this skill works

Provide file paths (supports glob patterns) and select which metrics to run. The analyzer parses source files, computes per-file and per-function metrics (cyclomatic, cognitive, LOC, maintainability), detects duplicated code blocks, and reports dependency metrics and code smells. Results are returned as a structured summary with file-level metrics, violation lists, duplicate groups, overall technical debt score, and prioritized hotspots.

When to use it

  • Before or during a refactor to identify high-risk regions and plan work
  • As part of CI to prevent complexity regressions and enforce thresholds
  • During architecture or design reviews to quantify maintainability
  • To audit third-party or legacy code for modernization efforts
  • When preparing performance or technical debt reduction roadmaps

Best practices

  • Run analyses incrementally (changed files) for fast feedback in CI
  • Tune thresholds per project—start conservative, then tighten over time
  • Combine metrics (cyclomatic + cognitive + duplicates) to prioritize hotspots
  • Review flagged items in code review rather than auto-fixing critical logic
  • Track historical scores to measure the effect of refactoring work

Example use cases

  • Scan a TypeScript monorepo to list functions with cyclomatic > 10 and generate a refactor backlog
  • Integrate into CI to fail builds when average complexity increases beyond a threshold
  • Create a maintainability report for an acquisition audit showing technical debt and hotspot files
  • Detect duplicate code blocks to drive consolidation and reduce maintenance cost
  • Produce a prioritized remediation plan combining complexity, LOC, and dependency risk

FAQ

Which languages are supported?

You can specify languages to analyze; the skill focuses on common languages and parsers available in the environment (JavaScript/TypeScript support is included).

Can I customize thresholds?

Yes. Cyclomatic, cognitive, and duplicate line thresholds are configurable per run or via the thresholds object.

What does the technical debt score represent?

It aggregates complexity, duplication, and maintainability indicators into a single score to help prioritize remediation, not a precise monetary estimate.