Code Hotspots: Finding the 20% of Code Causing 80% of Problems
Use code hotspots analysis to combine Git change frequency with complexity, inspect high-risk files, and choose focused tests or refactoring work for your team.
In 2024, I inherited a codebase with 380,000 lines of code. SonarQube flagged 12,000 code smells. The previous team had quit trying to address them because the number was so overwhelming that no amount of effort seemed to make a dent.
I fixed the most impactful quality issues in 6 weeks, working about 20% of sprint capacity. Not by being smarter or working harder, but by targeting hotspots. Exactly 14 files, out of roughly 2,400, were responsible for 73% of the bugs filed in the previous year. Fix those 14 files, and the metrics transformed.
That's the power of hotspot analysis. Most debt isn't evenly distributed. It's concentrated. Find the concentration, and you can achieve outsized results with minimal investment.
Figure 1. Investigate the combination of frequent change and complexity.
A hotspot is a file (or module) that scores high on two dimensions simultaneously:[1]
Change frequency: How often is this code modified?
Complexity: How hard is this code to understand and change safely?
A complex file with little activity ranks lower on this activity-based measure. Check its security and operational risks separately. Frequent changes to a simple file can reflect routine feature work.
The danger zone is the intersection: complex code that changes often. Every change carries risk, and the changes are frequent. This is where bugs breed.
Create a simple scatter plot (a spreadsheet works fine):
File
Changes (6mo)
Lines of Code
Hotspot Score
payments/processor.ts
47
842
39,574
api/routes/orders.ts
43
521
22,403
auth/session-manager.ts
38
687
26,106
components/Dashboard.tsx
35
234
8,190
utils/validators.ts
31
156
4,836
Hotspot Score = Changes x Lines of Code. This is a rough prioritisation heuristic using size as a proxy, not a calibrated defect prediction model.
payments/processor.ts is screaming for attention. 47 changes to a 842-line file means someone is touching this monster nearly twice a week. Use the code complexity metrics guide to check which measurements fit the language and the code.
If you want more precision, these tools do the analysis for you.
CodeScene (my recommendation for teams with budget): Behavioral code analysis that identifies hotspots, tracks trends, and even predicts where bugs will appear based on code patterns. It's the best tool I've used for this specific purpose.
git-of-theseus: Open source tool that analyzes code survival rates. Code that keeps getting rewritten is a hotspot signal.
Code Maat: Adam Tornhill's open source tool for mining Git history. It does hotspot analysis, coupling analysis, and more.[4]
bash
# Generate the format recommended by Code Maatgit log --all --numstat --date=short --pretty=format:'--%h--%ad--%aN' --no-renames --since="6 months ago" > git_log.txtjava -jar code-maat.jar -l git_log.txt -c git2 -a revisions
Sometimes you can't refactor a hotspot right away. In that case, wrap it in tests to make changes safer, and record the remaining problem in your technical debt register.
typescript
// Integration tests for the payments processor// These don't fix the complexity, but they catch regressionsdescribe('PaymentProcessor', () => { it('processes a valid credit card payment', async () => { const result = await processor.charge({ amount: 5000, currency: 'USD', cardToken: 'tok_visa', }); expect(result.status).toBe('succeeded'); expect(result.chargeId).toBeDefined(); }); it('retries on gateway timeout', async () => { gateway.simulateTimeout(1); // fail first attempt const result = await processor.charge({ /* ... */ }); expect(result.status).toBe('succeeded'); expect(gateway.attemptCount).toBe(2); }); it('does not retry on card declined', async () => { gateway.simulateDecline(); const result = await processor.charge({ /* ... */ }); expect(result.status).toBe('failed'); expect(gateway.attemptCount).toBe(1); // no retry });});
Hotspot analysis benefits from repeated checks. Track your top hotspots monthly and carry the findings into the technical debt measurement process.
HOTSPOT HEALTH TRACKER - March 2026
File | Feb Changes | Mar Changes | Trend | Status
payments/processor.ts | 12 | 5 | DOWN | Improving (split completed)
api/routes/orders.ts | 11 | 9 | DOWN | Monitoring
auth/session-manager.ts | 8 | 12 | UP | Investigate
When a hotspot changes less often after remediation, compare the trend with incident counts, delivery effort and feature demand. A quieter file alone does not establish that the fix worked. Investigate newly active files before choosing a response.
I was wrong about code quality tools for years. I thought wall-to-wall static analysis was the answer to code health. Run SonarQube on everything, fix everything it flags, and you'll have a great codebase.
That's backwards. Fixing a code smell in a file that hasn't been modified in 2 years is pure waste. The code works, nobody needs to change it, and your time is better spent elsewhere. Hotspot analysis flips the script: instead of measuring code quality everywhere and trying to improve it everywhere, measure activity patterns and improve quality only where it matters.
It's the difference between cleaning your entire house every day and cleaning the kitchen. Both are "clean" strategies. One respects reality.
Focus on the 14 files that cause 73% of your bugs. Ignore the 2,386 files that are fine. That's how you make a dent.
Frequently asked questions
Is every large file a hotspot?
Size alone does not make a hotspot. This method looks for code that is both difficult to change and frequently modified. A large stable file still needs separate checks for security and operational risk.
Can I find hotspots without a paid tool?
Start with Git history to count how often files change, then inspect complexity with a suitable analyser. A spreadsheet can help you compare the two measures before investigating the files that stand out.
Should I refactor every hotspot immediately?
Investigate why each file changes and what the changes cost. The response may be a focused refactor, a split by responsibility or stronger tests. Prioritise a small number of files with demonstrated impact.
Does a lower change count prove the fix worked?
A lower count is one signal to investigate. Check it alongside defect history and delivery effort because less activity may also reflect a change in feature demand. Compare equivalent periods and record what changed.
Five predictions for where code intelligence is heading by 2028, based on 6 years of building tools in this space. Includes what's real, what's overhyped, and a maturity model for planning.
Most code quality dashboards fail because they track too many metrics and live outside the team's workflow. Here are exactly 7 metrics and a 3-week adoption plan that actually works.
Compare cyclomatic and cognitive code complexity with change risk. Check corrected examples, understand each measure’s limits and target refactoring effort.
Use Git history analysis to find frequently changed files, co-change patterns and contributor concentration. Run reproducible queries and inspect their limits.
No single person can hold a large codebase in their head. A knowledge graph externalizes understanding into a queryable structure. Here's the 4-week playbook to build one.