skills/tech-debt-analysis/SKILL.md
Analyze codebase for structural tech debt using software design principles from Fowler's Refactoring, the Design Stamina Hypothesis, and the AWS Builders' Library
npx skillsauth add jankneumann/agentic-coding-tools tech-debt-analysisInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Perform a structural analysis of the codebase to identify tech debt — areas where design quality has degraded and future development velocity is at risk.
Grounded in principles from:
This is a read-only diagnostic skill — it does not modify code. Use its output to prioritize refactoring work via /plan-feature.
$ARGUMENTS - Optional flags:
--analyzer <list> (comma-separated analyzers; default: all)--severity <level> (minimum severity: critical, high, medium, low, info; default: low)--project-dir <path> (directory to analyze; default: auto-detect)--out-dir <path> (default: docs/tech-debt)--format <md|json|both> (default: both)--no-parallel (run analyzers sequentially)Valid analyzers: complexity, coupling, duplication, imports
Scripts live in <agent-skills-dir>/tech-debt-analysis/scripts/. Each agent runtime substitutes <agent-skills-dir> with its config directory:
.claude/skills.codex/skills.gemini/skillsIf scripts are missing, run skills/install.sh to sync them from the canonical skills/ source.
coupling analyzer: architecture artifacts must exist (docs/architecture-analysis/architecture.graph.json). Run /refresh-architecture first if missing.ast, hashlib, json, pathlib)complexity)Uses Python's ast module to detect:
| Code Smell | Metric | Threshold | Critical | Reference | |------------|--------|-----------|----------|-----------| | Long Method | Function line count | 50 | 100 | Fowler: Extract Method | | Large File / God File | File line count | 500 | 1000 | Fowler: Extract Class | | Complex Function | McCabe cyclomatic complexity | 10 | 20 | Fowler: Decompose Conditional | | Deep Nesting | Control-flow nesting depth | 4 | 6 | Fowler: Guard Clauses | | Long Parameter List | Parameter count (excl. self/cls) | 5 | 8 | Fowler: Introduce Parameter Object | | Too Many Definitions | Top-level classes + functions | 20 | 40 | SRP: Single Responsibility Principle |
coupling)Reads from existing architecture artifacts to detect:
| Code Smell | Metric | Threshold | Reference | |------------|--------|-----------|-----------| | High Fan-out | Outgoing dependencies | 10 | Shotgun Surgery / Feature Envy | | High Fan-in | Incoming dependents | 10 | Change Amplifier | | Hub Node | High fan-in AND fan-out | 8 each | God Object / Blob | | High Impact | Transitive dependents | 15 | AWS: Blast Radius |
Requires: docs/architecture-analysis/architecture.graph.json (from /refresh-architecture)
duplication)Uses structural fingerprinting to detect copy-pasted code:
imports)Builds a module-level import graph to detect:
| Code Smell | Description | Reference |
|------------|-------------|-----------|
| Circular Import | Cycles in the import graph | Fragile initialization order |
| Import Fan-out | Module importing 15+ other modules | Divergent Change |
| Star Import | from X import * | Namespace Pollution |
Before running the full analysis, ensure architecture artifacts are up to date for accurate coupling analysis:
# Check if architecture graph exists and is fresh (< 7 days old)
# If missing or stale, refresh it first:
make architecture
# Or invoke the skill:
# /refresh-architecture
The coupling analyzer automatically detects stale artifacts (> 7 days old) and warns in its output, but refreshing beforehand gives the most accurate results.
python3 <agent-skills-dir>/tech-debt-analysis/scripts/main.py \
--analyzer <analyzers-or-omit-for-all> \
--severity <level> \
--project-dir <path> \
--out-dir docs/tech-debt \
--format both
The orchestrator produces:
docs/tech-debt/tech-debt-report.md — human-readable report with hotspots, severity breakdown, and refactoring recommendationsdocs/tech-debt/tech-debt-report.json — machine-readable for downstream toolsSeverity Levels (descending): critical > high > medium > low > info
Severity mapping:
info)Hotspot files: Files with the most findings across all analyzers. These are the best candidates for refactoring investment.
/plan-feature proposal for significant refactoring effortsThis skill complements /bug-scrub:
Together, they provide a complete picture of codebase health. Run both before major planning sessions.
The coupling analyzer reads directly from /refresh-architecture artifacts. For best results:
/refresh-architecture to update the graph/tech-debt-analysis to analyze structural qualitypython3 -m pytest <agent-skills-dir>/tech-debt-analysis/tests -q
| Rationalization | Why it's wrong | |---|---| | "Our CI doesn't fail on complexity, so high cyclomatic complexity isn't a problem" | The Design Stamina Hypothesis: design quality affects velocity over time, not pass/fail today. CI cares about correctness now; tech-debt analysis catches the velocity decay CI cannot see. | | "Duplication is fine — the duplicated code is short" | Even short duplicates compound: a 6-line idiom copied 12 times becomes 72 lines that must change together at the next requirement shift. Fowler's Rule of Three exists to prevent that compounding. | | "We'll fix the hub node when we have time" | Hub nodes have the largest blast radius (AWS Builders' Library); they degrade every dependent feature simultaneously. Refactor them first, not last. | | "I'll skip refreshing architecture artifacts — the graph is probably fine" | The coupling analyzer reads stale fan-in/fan-out from a stale graph. Stale graph → stale findings → wrong refactoring priorities. The skill explicitly warns when artifacts are >7 days old; honor the warning. | | "Star imports are a stylistic preference" | Star imports break the import analyzer's ability to detect what depends on what; they also defeat IDE rename refactoring. They are a real design defect, not style. |
tech-debt-report.json produced without docs/architecture-analysis/architecture.graph.json being recent — the coupling analyzer either silently skipped or read stale data.complexity analyzer on a codebase >5k LOC — almost certainly the analyzer ran on the wrong --project-dir or excluded all source files.# noqa instead of resolved — fragile initialization order will eventually break in a new test runner / Python version.docs/architecture-analysis/architecture.graph.json exists and is <7 days old before running the coupling analyzer (the report's metadata includes a freshness flag — check it).findings array is non-empty for a non-trivial codebase, AND that at least two analyzers contributed findings (single-analyzer reports usually mean the others crashed silently).development
Open the artifacts relevant to a review (OpenSpec proposal, branch changes, or explicit paths) in VS Code, in a curated read-order, in the right worktree.
tools
Render and seed coordinator-owned task status block in OpenSpec tasks.md
testing
User-invocable skill that omits the tail block
tools
Missing several required keys