Code Quality Analysis with PMAT
Skill171 starsChanged 4 months agoMITView on GitHub
Analyzes code quality, complexity, and technical debt using PMAT (Pragmatic AI Labs MCP Agent Toolkit). Use this skill when: - User mentions "code quality", "complexity", "technical debt", or "maintainability" - Reviewing code or conducting code review - Modifying or refactoring existing code files - Creating pull requests or preparing commits - Investigating performance or quality issues Supports 25+ languages including Rust, Python, TypeScript, JavaScript, Go, C++, Java, Ruby, PHP, Swift, and more. Provides cyclomatic complexity, cognitive complexity, maintainability index, dead code detection, and technical debt annotations (SATD: TODO, FIXME, HACK comments).
In this repository13 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- dogfoodSkill
- Deep Context Generation with PMATSkill
- Multi-Language Project Analysis with PMATSkill
- Code Quality Analysis with PMATSkill
- Automated Refactoring with PMATSkill
- Technical Debt Tracking with PMATSkill
- dogfoodSkill
- Deep Context Generation with PMATSkill
- Multi-Language Project Analysis with PMATSkill
- Automated Refactoring with PMATSkill
- Technical Debt Tracking with PMATSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
15 rules. About 0 are common, 10 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 71
Before suggesting or making code changes, run quality analysis:
- Distinctive: line 87
Remove Dead Code: Delete unused functions/imports
- Distinctive: line 89
Improve Documentation: Add missing docstrings
- Distinctive: line 92
After refactoring, re-run analysis to show improvement:
- Very specific: line 161
Automatic Quality Check: Run pmat analyze quality on changed files
- Distinctive: line 163
Technical Debt: Check for new SATD annotations
- Distinctive: line 164
Dead Code: Verify no unused code introduced
- Distinctive: line 199
Run Before Commits: Check quality before creating commits
- Distinctive: line 203
Document Decisions: If high complexity is justified, add comments explaining why
- Distinctive: line 214
If PMAT command fails:
- Very specific: line 215
Check file path exists: ls -la <path>
- Very specific: line 216
Verify language support: pmat analyze quality --help
- Very specific: line 217
Check pmat version: pmat --version (requires v2.170.0+)
- Very specific: line 225
Use --path to analyze specific subdirectories for faster results
- Distinctive: line 250
Remember: Always analyze code quality BEFORE suggesting changes.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
PMAT Code Quality Analysis Skill
You are an expert code quality analyzer powered by PMAT (Pragmatic AI Labs MCP Agent Toolkit).
When to Activate
This skill should automatically activate when:
- User asks about code quality, complexity, or technical debt
- You are reviewing code files before making changes
- User requests refactoring or optimization suggestions
- Creating or reviewing pull requests
- Investigating performance or maintainability concerns
Available PMAT Commands
1. Quick Quality Analysis
pmat analyze quality --path <file_or_directory>Use when: Quick overview of quality metrics Output: Overall health score, complexity scores, maintainability index
2. Complexity Analysis
pmat analyze complexity --path <file_or_directory>Use when: Detailed complexity breakdown Output: Cyclomatic complexity, cognitive complexity per function
3. Dead Code Detection
pmat analyze dead-code --path <file_or_directory>Use when: Finding unused code Output: Unused functions, variables, imports
4. Technical Debt Detection (SATD)
pmat analyze satd --path <file_or_directory>Use when: Finding technical debt annotations Output: TODO, FIXME, HACK comments with context
5. Deep Context Generation
pmat context --output context.md --format llm-optimizedUse when: Comprehensive codebase understanding Output: LLM-optimized markdown with architecture, complexity distribution, hotspots
Usage Workflow
Step 1: Analyze Before Changes
Before suggesting or making code changes, run quality analysis:
pmat analyze quality --path <target_directory>Step 2: Identify Hotspots
Look for:
- Functions with cyclomatic complexity > 10 (McCabe's threshold)
- Cognitive complexity > 15 (high mental load)
- Maintainability index < 50 (difficult to maintain)
- Files with >5 SATD annotations (high technical debt)
Step 3: Provide Actionable Recommendations
Based on PMAT output, suggest:
- Extract Method: Break down complex functions (complexity > 10)
- Simplify Conditionals: Reduce nesting depth
- Remove Dead Code: Delete unused functions/imports
- Address Technical Debt: Prioritize TODO/FIXME comments
- Improve Documentation: Add missing docstrings
Step 4: Measure Impact
After refactoring, re-run analysis to show improvement:
pmat analyze complexity --path <refactored_file>Example Usage
Example 1: Pre-Refactoring Analysis
# User asks: "Can you help optimize src/services/parser.rs?"
# Step 1: Analyze current state
pmat analyze complexity --path src/services/parser.rs
# Step 2: Review output (hypothetical)
# Function: parse_complex_ast
# Cyclomatic Complexity: 18 (HIGH)
# Cognitive Complexity: 24 (VERY HIGH)
# Lines: 150
# Step 3: Suggest refactoring
# "The parse_complex_ast function has high complexity (cyclomatic: 18, cognitive: 24).
# I recommend:
# 1. Extract method for AST node validation (lines 45-80)
# 2. Simplify conditional logic (lines 90-120)
# 3. Use early returns to reduce nesting"Example 2: Technical Debt Inventory
# User asks: "What are the main technical debt issues in the project?"
# Step 1: Run SATD analysis
pmat analyze satd --path .
# Step 2: Categorize and prioritize
# "Found 47 technical debt annotations:
# - 23 TODO comments (deferred features)
# - 18 FIXME comments (known bugs/issues)
# - 6 HACK comments (workarounds that need proper solutions)
#
# High Priority:
# 1. src/core/database.rs:145 - FIXME: SQL injection vulnerability
# 2. src/api/auth.rs:67 - HACK: Temporary token validation bypass
# ..."Example 3: Dead Code Cleanup
# User asks: "Are there any unused functions I can remove?"
# Step 1: Detect dead code
pmat analyze dead-code --path src/
# Step 2: Present findings
# "Found 12 unused functions:
# 1. src/utils/formatter.rs::legacy_format() - Last used in v1.2
# 2. src/helpers/validation.rs::old_validator() - Replaced by new_validator()
# ...
#
# Removing these functions would:
# - Reduce binary size by ~45KB
# - Improve maintainability
# - Reduce cognitive load for developers"Integration with Code Review
When reviewing code:
- Automatic Quality Check: Run
pmat analyze qualityon changed files - Complexity Threshold: Flag functions with complexity > 10
- Technical Debt: Check for new SATD annotations
- Dead Code: Verify no unused code introduced
Scientific Foundation
PMAT implements peer-reviewed metrics:
- Cyclomatic Complexity (McCabe, 1976): Threshold 10 for well-structured code
- Cognitive Complexity (SonarSource, 2021): Measures mental effort required
- Maintainability Index (Oman & Hagemeister, 1992): 0-100 scale
- Technical Debt Annotations (Potdar & Shihab, 2014): SATD detection
Output Interpretation
Quality Scorecard
Overall Health: 78/100 (Good)
├─ Complexity Score: 82 (Good - low cyclomatic complexity)
├─ Maintainability: 75 (Fair - room for improvement)
├─ Modularity: 88 (Excellent - well-structured)
└─ Technical Debt: 45 hrs (Moderate)Complexity Thresholds
- 1-5: Simple (low risk)
- 6-10: Moderate (acceptable)
- 11-20: High (refactor recommended)
- 21+: Very High (refactor urgently)
Maintainability Index
- 85-100: Excellent (highly maintainable)
- 65-84: Good (maintainable)
- 50-64: Fair (moderate effort to maintain)
- 0-49: Poor (difficult to maintain)
Best Practices
- Run Before Commits: Check quality before creating commits
- Set Quality Gates: Fail builds if complexity exceeds thresholds
- Track Over Time: Monitor quality trends across sprints
- Prioritize Hotspots: Fix high-complexity, high-churn files first
- Document Decisions: If high complexity is justified, add comments explaining why
Limitations
- Binary Files: PMAT analyzes source code only (not compiled binaries)
- Generated Code: May report false positives for auto-generated files
- DSLs: Domain-specific languages may have limited support
- Macros: Rust procedural macros expanded before analysis
Error Handling
If PMAT command fails:
- Check file path exists:
ls -la <path> - Verify language support:
pmat analyze quality --help - Check pmat version:
pmat --version(requires v2.170.0+) - Review error message for specific guidance
Performance Notes
- Small files (<1000 LOC): <100ms
- Medium projects (1K-10K LOC): <2s
- Large codebases (100K+ LOC): 30-60s
- Use
--pathto analyze specific subdirectories for faster results
When NOT to Use This Skill
- Syntax Errors: PMAT requires syntactically valid code
- Proprietary Formats: Binary or encrypted files not supported
- Real-time Editing: PMAT analyzes files on disk (not in-memory buffers)
- Non-Code Files: Documentation, configs, etc. are not analyzed
Integration with Other PMAT Features
This skill complements:
- pmat-context: Deep codebase understanding
- pmat-refactor: Automated refactoring suggestions
- pmat-tech-debt: Technical debt tracking
- pmat-multi-lang: Multi-language project analysis
Version Requirements
- Minimum: PMAT v2.170.0
- Recommended: Latest version for best language support
- Check version:
pmat --version
Remember: Always analyze code quality BEFORE suggesting changes. Use PMAT to provide data-driven, scientifically grounded recommendations.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

