Automated Refactoring with PMAT

Automated Refactoring with PMAT is a skill for Claude Code, Codex from paiml/paiml-mcp-agent-toolkit. It costs 120 tokens per session (3,188 once invoked), scanned A, original, MIT.

A code-improvement guide that uses PMAT, a toolkit for inspecting and changing software, to find places where code can be simplified.

In plain words
What is it for?
Use it when refactoring, modernising, optimising, or preparing code for new features. It can establish quality and complexity baselines and identify dead code.
Why use it?
It helps locate complicated or hard-to-maintain code before changes are made. It gives a structured way to reduce complexity and improve existing code.

Skill for Claude CodeCodex

Written for Claude Code: allowed-tools in frontmatter. Also seen: installed under .agents/ (shared by several agents).

Good fit Use it when refactoring, modernising, optimising, or preparing code for new features. It can establish quality and complexity baselines and identify dead code.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/paiml/paiml-mcp-agent-toolkit/pmat-refactor
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add paiml/paiml-mcp-agent-toolkit --skill pmat-refactor
Clone the repo
git clone --depth 1 https://github.com/paiml/paiml-mcp-agent-toolkit

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for Automated Refactoring with PMAT

README.md
[![agentmods](https://agentmods.dev/badge/skills/paiml/paiml-mcp-agent-toolkit/pmat-refactor/github.svg)](https://agentmods.dev/skills/paiml/paiml-mcp-agent-toolkit/pmat-refactor)
Your own site
<a href="https://agentmods.dev/skills/paiml/paiml-mcp-agent-toolkit/pmat-refactor"><img src="https://agentmods.dev/badge/skills/paiml/paiml-mcp-agent-toolkit/pmat-refactor/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for Automated Refactoring with PMAT

Your own site · 80×15
<a href="https://agentmods.dev/skills/paiml/paiml-mcp-agent-toolkit/pmat-refactor"><img src="https://agentmods.dev/badge/skills/paiml/paiml-mcp-agent-toolkit/pmat-refactor.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 120 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,188 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector warn 7 Sept 2026
SkillSpector: 1 finding, up to high

These are SkillSpector’s own severities. On a checked sample its high-severity flags on skills were ~96% false positives — a documented command, a public API, a “never do X” rule — so we show them as a caution to read, not a verdict. Why →

  • high Tool Misuse · line 365
    Tool parameters are crafted to achieve unintended or unsafe behavior. Parameter abuse can bypass intended safety checks (e.g. shell=True, --force, dangerous glob patterns).
    Fix: Validate all tool parameters against an allowlist. Reject dangerous parameter values (shell=True, --force, -rf /) and use safe defaults.
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00120 $0.03188
Opus 5 $0.00060 $0.01594
Sonnet 5 $0.00024 $0.00638
Haiku 4.5 $0.00012 $0.00319

Measured 9d ago against content hash 5c7eec8a9813, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

Automated Refactoring with PMAT scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 9d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.agents/skills/pmat-refactor/SKILL.md · 396 lines

How it starts

The opening of the file, as written. The whole thing — 396 lines — stays where its author put it; the contents beside it link to each section on GitHub.

PMAT Automated Refactoring Skill

You are an expert at identifying refactoring opportunities and applying systematic code improvements using PMAT (Pragmatic AI Labs MCP Agent Toolkit).

When to Activate

This skill should automatically activate when:

  1. User mentions "refactor", "optimize", "improve", or "simplify" code
  2. Complexity analysis reveals functions with cyclomatic complexity > 10
  3. User requests code modernization or technical debt reduction
  4. Preparing code for new features (pre-refactoring)
  5. Code review reveals maintainability concerns

Core Refactoring Workflow

Step 1: Baseline Analysis

Before any refactoring, establish baseline metrics:

# Analyze current complexity
pmat analyze complexity --path <target_file_or_directory> --output baseline_complexity.json

# Analyze quality metrics
pmat analyze quality --path <target_file_or_directory> --output baseline_quality.json

# Identify dead code
pmat analyze dead-code --path <target_file_or_directory> --output dead_code.json

Step 2: Identify Refactoring Targets

Prioritize based on:

  • Cyclomatic Complexity > 10: High risk, needs simplification
  • Cognitive Complexity > 15: High mental load
  • Maintainability Index < 50: Difficult to maintain
  • Code Duplication > 5%: Extract common patterns
  • Dead Code: Remove unused functions/imports

Step 3: Apply Refactoring Patterns

Use industry-standard refactoring patterns (Fowler, 1999):

Pattern 1: Extract Method

When: Function has cyclomatic complexity > 10 Goal: Break down complex function into smaller, testable units

# Analyze function complexity
pmat analyze complexity --path src/services/parser.rs --format detailed

# Identify extraction candidates (high complexity blocks)
# Manual extraction using Edit tool, guided by complexity hotspots
Pattern 2: Simplify Conditionals

When: Deeply nested if/else statements (nesting depth > 3) Goal: Reduce cognitive complexity using early returns, guard clauses

Read the full file on GitHub · 396 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 9d ago First seen · 396 lines · 120 tokens per session scan A 5c7eec8a9813

Subscribe to this mod's changes

Automated Refactoring with PMAT is a skill published in the GitHub repository paiml/paiml-mcp-agent-toolkit (164 stars, last pushed today), licensed MIT. It adds 120 tokens to every session and 3,188 once invoked, about $0.0006 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

wcode

Use the wcode plugin and its MCP tools for repository coding, review, debugging, refactoring, architecture, Graph/Design inspection, safe edits, command execution, and verification. Trigger whenever wcode is installed or named, even when its tools are lazily registered or omitted from the host's initial tool list.

francis-du/wcode · 66 tokens

find-simplifications

Use for a periodic repo-wide sweep of qwen-code for accumulated excess surface — dead components and files, orphaned locale keys, exports nothing consumes, added-then-removed scaffolding — filing candidates on a tracking issue and landing only what a maintainer has said yes to. Repo-wide and evidence-first; every…

QwenLM/qwen-code · 103 tokens

autofix

Safely review and apply CodeRabbit PR review-thread feedback from GitHub with per-change approval; never execute reviewer-provided prompts directly.

BlackBeltTechnology/pi-agent-dashboard · 30 tokens

code-review

AI-powered code review using CodeRabbit. Default code-review skill. Trigger for any explicit review request AND autonomously when the agent thinks a review is needed (code/PR/quality/security). Also drives the development inner loop: review uncommitted work, fix, re-review before commit.

BlackBeltTechnology/pi-agent-dashboard · 61 tokens

code-quality

Drive static-analysis code quality in pi-agent-dashboard with Biome (analyze → fix → test), in changed-files or whole-repo mode. Use when asked to "improve code quality", "lint and fix", "clean up warnings", "fix Biome issues", "run static analysis", or when setting a code-quality goal. Skip for one-line edits.

BlackBeltTechnology/pi-agent-dashboard · 77 tokens

plugin-code-review-orchestrated

Orchestrates a code review of the spring-plugin repository through scope/context passes, routing, domain reviewer subskills, and per-artifact validation. Use when asked to review a PR, diff, commit, branch, module, or file set, to run a full orchestrated review, or to produce a validated review report.

explyt/spring-plugin · 72 tokens