Automated Refactoring with PMAT

Automate refactoring of multi-language codebases with PMAT and impact metrics.

161|27|Updated May 25, 2025
One-click install
npx skills add https://github.com/paiml/paiml-mcp-agent-toolkit --skill automated-refactoring-with-pmat
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Automated Refactoring with PMAT
Source: https://github.com/paiml/paiml-mcp-agent-toolkit/tree/main/.claude/skills/pmat-refactor
Command: npx skills add https://github.com/paiml/paiml-mcp-agent-toolkit --skill automated-refactoring-with-pmat

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides automated refactoring recommendations and patterns to reduce complexity and improve maintainability using PMAT.

Core Features & Use Cases

  • Baseline Analysis: Gather current complexity, quality, and dead code metrics.
  • Target Identification: Prioritize refactoring targets based on cyclomatic complexity (>10), cognitive complexity (>15), maintainability (<50), duplication, and dead code.
  • Pattern Library: Apply common refactoring patterns (Extract Method, Simplify Conditionals, Remove Dead Code, Extract Class/Module, Reduce Duplication).
  • Impact Verification: Re-measure metrics to confirm improvements.

Quick Start

  1. Baseline complexity and quality: pmat analyze complexity --path <target> --output baseline_complexity.json
  2. Detect dead code: pmat analyze dead-code --path <target> --output dead_code.json
  3. Apply refactor patterns (one pattern at a time) and verify:
    • pmat analyze complexity --path <refactored_files> --output after_complexity.json
    • pmat compare --baseline baseline_complexity.json --current after_complexity.json
    • pmat analyze quality --path <refactored_files> --output after_quality.json

Frequently Asked Questions about Automated Refactoring with PMAT

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

FAQPage Schema
How do I reduce cyclomatic complexity in my codebase?

Cyclomatic complexity measures code branching; reducing it improves maintainability. PMAT automates detection of high-complexity functions (>10) and applies refactoring patterns like Extract Method and Simplify Conditionals to break them into simpler, testable units across 25+ languages.

Can I automatically detect dead code in large projects?

Yes. PMAT analyzes entire codebases to identify unused code and dead code paths, then prioritizes removal based on impact. It works across multi-language projects and outputs metrics showing code reduction and quality gains.

What refactoring patterns does automated analysis support?

PMAT applies Extract Method, Simplify Conditionals, Remove Dead Code, Extract Class/Module, and Reduce Duplication. Each pattern targets specific complexity drivers and includes before/after metrics to verify that refactoring actually improves maintainability.

How do I prioritize which code to refactor first?

PMAT baseline analysis ranks refactoring targets by cyclomatic complexity (>10), cognitive complexity (>15), maintainability score (<50), duplication, and dead code volume. This focuses effort on high-risk constructs with the greatest impact.

Does refactoring preserve code behavior and quality?

PMAT compares complexity and quality metrics before and after refactoring to verify improvements. It outputs transformed code snippets and impact metrics, letting you confirm that behavior is preserved and maintainability gains are real.

Can I use this for projects in multiple programming languages?

Yes. PMAT supports 25+ languages, so baseline analysis, pattern detection, and complexity reduction work across polyglot codebases without language-specific setup.