code-hotspots
Skill0 starsChanged 3 months agoMITView on GitHub
This skill should be used when the user asks "where should we start refactoring", "which files are riskiest", "what is our tech debt priority", "which files always change together", "what is the bus factor", or asks to mine git history for code health signals. Combines change frequency with complexity to rank refactoring candidates.
In this repository29 other files it gives its agents.
- algorithmic-complexity-attacksSkill
- cache-stampedeSkill
- clocks-and-timeSkill
- connascenceSkill
- connection-poolingSkill
- consistent-hashingSkill
- coordinated-omissionSkill
- cyclomatic-complexitySkill
- database-queuesSkill
- dependency-confusionSkill
- expand-contractSkill
- floating-pointSkill
- hyrums-lawSkill
- index-designSkill
- isolation-anomaliesSkill
- keyset-paginationSkill
- metamorphic-testingSkill
- module-depthSkill
- mutation-testingSkill
- mvcc-and-bloatSkill
- parse-dont-validateSkill
- query-plansSkill
- queueing-and-utilizationSkill
- retry-amplificationSkill
- start-hereSkill
- tail-latencySkill
- unicode-pitfallsSkill
- universal-scalability-lawSkill
- write-amplificationSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 24
Use a 6 to 12 month window, matching how far back the team remembers.
- Distinctive: line 53
Read results as questions:
- Distinctive: line 99
Never publish an ownership map as a performance metric.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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
Code hotspots
Complexity costs money only in code that changes. A gnarly file untouched for four years costs nothing. A moderately complex file edited twice a week absorbs the bugs and the time.
So the ranking signal is not complexity:
hotspot = change frequency x complexity
Git already recorded which code is hard, for free. Every commit to a file is evidence that somebody had to understand it. This is behavioral code analysis, from Adam Tornhill's Your Code as a Crime Scene.
Step 1: change frequency
git log --format=format: --name-only --since=12.months \
-- ':!*lock*' ':!*generated*' ':!vendor/*' ':!*.snap' \
| sed '/^$/d' | sort | uniq -c | sort -rn | head -25Use a 6 to 12 month window, matching how far back the team remembers. Longer windows include code that has since stabilized. Exclude lockfiles, generated code, vendored directories, and snapshots.
Step 2: cross with complexity
Churn alone over-ranks config files and routers. Multiply by size or complexity:
git log --format=format: --name-only --since=12.months | sed '/^$/d' | sort | uniq -c | sort -rn | head -50 \
| while read count file; do
[ -f "$file" ] && echo "$((count * $(wc -l < "$file"))) $count $file"
done | sort -rn | head -20For a real complexity term, feed the top churned files to a complexity tool such as radon cc -s or lizard --sort cyclomatic_complexity. See cyclomatic-complexity.
The top five of that list is the refactoring backlog. Five files, not the codebase.
Step 3: change coupling
Files that keep changing in the same commit are coupled even when nothing in the code says so. This finds what static analysis cannot: a client and server that must ship together, or two "independent" services sharing an implicit contract.
git log --format='%H' --name-only --since=12.months \
| awk '/^[0-9a-f]{40}$/{c=$0; next} NF{print c" "$0}' \
| awk '{a[$1]=a[$1]" "$2} END{for(c in a) print a[c]}' \
| awk '{for(i=1;i<=NF;i++)for(j=i+1;j<=NF;j++) print ($i<$j? $i" "$j : $j" "$i)}' \
| sort | uniq -c | sort -rn | head -20Read results as questions:
- Source plus its own test: healthy, ignore
- Two modules in different packages coupled 80% of the time: a missing abstraction, or a boundary in the wrong place
- One file coupled to many unrelated files: a god object or a shared config
Step 4: bus factor
git log --format='%an' --since=24.months -- path/to/file | sort | uniq -c | sort -rnA hotspot with a bus factor of 1 is the highest-risk combination available: complex, constantly changing, and understood by one person. Escalate that combination rather than the raw complexity score.
Reading the grid
| Low churn | High churn | |
| Low complexity | Healthy, leave it | Healthy but busy, check it is not accumulating responsibilities |
| High complexity | Dormant. Do not refactor for its own sake: no return, and real risk of breaking something nobody remembers | Hotspot. This is the entire list |
The most valuable output of this analysis is permission to skip the bottom-left quadrant.
Keep blame honest
Bulk reformatting and renames destroy the signal. Record them so tooling skips them:
git config blame.ignoreRevsFile .git-blame-ignore-revsOne commit SHA per line. GitHub honors this file automatically.
Tools
| Tool | Purpose |
code-maat | Tornhill's CLI: churn, coupling, ownership, age from a git log export |
| CodeScene | Hosted equivalent with trend lines |
git-of-theseus | Plots how much code from each year survives |
hercules | Fast history analysis including code-age burndown |
Limits
- Churn is not badness. An actively developed feature legitimately churns. This finds candidates, not defects.
- Splitting a hotspot into three files improves the metric without necessarily improving the code. Verify each piece is independently understandable. See
module-depth. - Never publish an ownership map as a performance metric. It measures who touched code, not who contributed, and becomes meaningless the moment it becomes a target.
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.

