Analyze code complexity, cyclomatic complexity, maintainability index, and code churn using metrics tools. Use when assessing code quality, identifying refactoring candidates, or monitoring technical debt.
Measure and analyze code quality metrics to identify complexity, maintainability issues, and areas for improvement.
Minimal working example:
import * as ts from "typescript";
import * as fs from "fs";
interface ComplexityMetrics {
cyclomaticComplexity: number;
cognitiveComplexity: number;
linesOfCode: number;
functionCount: number;
classCount: number;
maxNestingDepth: number;
}
class CodeMetricsAnalyzer {
analyzeFile(filePath: string): ComplexityMetrics {
const sourceCode = fs.readFileSync(filePath, "utf-8");
const sourceFile = ts.createSourceFile(
filePath,
sourceCode,
ts.ScriptTarget.Latest,
true,
);
const metrics: ComplexityMetrics = {
cyclomaticComplexity: 0,
cognitiveComplexity: 0,
// ... (see reference guides for full implementation)
Detailed implementations in the references/ directory:
| Guide | Contents | |---|---| | TypeScript Complexity Analyzer | TypeScript Complexity Analyzer | | Python Code Metrics (using radon) | Python Code Metrics (using radon) | | ESLint Plugin for Complexity | ESLint Plugin for Complexity | | CI/CD Quality Gates | CI/CD Quality Gates |
Copy a source-pinned command for your client. You run it yourself.
Destination: .claude/skills/code-metrics-analysis · pinned to the source commit
# Run from your project root
git clone https://github.com/aj-geddes/useful-ai-prompts.git .skillboard-tmp
git -C .skillboard-tmp checkout 3f5182cfd739fc113f4af5244a1cf342ad7f7911
mkdir -p ".claude/skills"
cp -r ".skillboard-tmp/skills/code-metrics-analysis" ".claude/skills/"
rm -rf .skillboard-tmpReview the source before running. This copies files into your project; it is not a one-click install and does not verify runtime safety.
sudo apt update && sudo apt install -y gitnpm install -g @anthropic-ai/claude-code# Run from your project root
git clone https://github.com/aj-geddes/useful-ai-prompts.git .skillboard-tmp
git -C .skillboard-tmp checkout 3f5182cfd739fc113f4af5244a1cf342ad7f7911
mkdir -p ".claude/skills"
cp -r ".skillboard-tmp/skills/code-metrics-analysis" ".claude/skills/"
rm -rf .skillboard-tmpDestination: .claude/skills/code-metrics-analysis
Scanner static-checks@0.1.0 · commit 3f5182cfd739. Static checks cannot prove runtime safety – review the source and the exact diff before installing. How checks work.
No static rules matched. This is not a safety guarantee.