Skip to content

Behavioral Code Analysis: Mining Patterns From How Teams Work

Behavioral code analysis examines how teams interact with code, not just what the code looks like. It reveals risks no linter can catch.

8 min read
Illustrative pale wooden work surface shows repeated paths of gentle wear between three modular tool stations, with teal components resting where the routes meet.
On this page

Code doesn't write itself. Humans write it. And the patterns those humans follow (when they commit, how they review, where they concentrate their effort) reveal more about a codebase's future than any static metric.

I got hooked on behavioral code analysis after reading Adam Tornhill's "Your Code as a Crime Scene" in 2017. His central thesis was elegant: apply forensic psychology techniques to codebases. Instead of analyzing what the code looks like, analyze what the people who write it do. Since then, I've applied these techniques to every team I've led, and the results have been consistently more actionable than any SonarQube dashboard.

What Behavioral Code Analysis Is

VersioncontrolCommit historyCode reviewReview activityIssue trackersBugs and featuresStructuraldataEvaluate risk
Figure 1. Combine activity records with code structure before judging a risk.

Behavioral code analysis examines the patterns of human activity around a codebase. It uses data from:[1]

  • Version control: Who committed what, when, and how often
  • Code review systems: Who reviews what, how long reviews take, how many iterations
  • Issue trackers: Which commits link to bugs vs features
  • Communication tools: (In advanced implementations) Which code discussions happen on Slack vs in PRs

The goal is to answer questions that structural analysis can't: Use the code intelligence guide for the wider analysis. Inspect relationships with a codebase knowledge graph. For the history mechanics, see Git history analysis.

  • Which parts of the system are understood by only one person?
  • Where do knowledge silos exist?
  • Which modules have the highest social complexity (require coordinating many people to change)?
  • What patterns predict production incidents?

Pattern 1: Knowledge Silos

A knowledge silo exists when one developer is the sole expert on a critical piece of code. This is the single most dangerous pattern I find in behavioral analysis, and it exists in every team I've worked with.

Here's how I detect it:

python
from collections import Counter, defaultdict
import subprocess

raw = subprocess.check_output([
    "git", "log", "--since=12 months ago", "--no-merges",
    "--no-renames", "--format=%x1e%aE", "--name-only", "-z",
    "--", "*.ts",
])
counts = defaultdict(Counter)
for record in raw.split(b"\x1e")[1:]:
    author, _, names = record.partition(b"\0")
    names = names.removeprefix(b"\n")
    for filename in set(names.split(b"\0")) - {b""}:
        counts[filename][author] += 1
for filename, authors in sorted(counts.items()):
    total = sum(authors.values())
    dominant = max(authors.values()) / total
    print(filename.decode("utf-8", "replace"), len(authors), round(dominant, 2))

The log format separates commits from NUL-terminated paths. The %aE field uses canonical author emails from Git's mailmap configuration. This example excludes merge commits and treats renamed paths as separate historical paths.[2][3]

In practice, I use a Python script that produces a matrix: files as rows, developers as columns, commit counts as values. Files where a single developer accounts for more than 70% of commits in the last 12 months are investigation candidates. Confirm knowledge concentration with the team before classifying a module as a silo.

At one company, we found that 40% of the modules responsible for revenue-critical features had a bus factor of 1. A single senior developer's departure would have left those modules without anyone who deeply understood them. We immediately started a knowledge-spreading program: pair programming rotations, recorded architecture walkthroughs, and deliberate review assignments.

Within 6 months, we'd reduced single-author-dominant modules from 40% to 15%.

Pattern 2: Temporal Coupling

I covered the mechanics of temporal coupling in the git history article, but the behavioral insight goes deeper.[4]

When two files consistently change together, there are two possible explanations:

  1. Legitimate architectural coupling: The files genuinely need to change together (e.g., a component and its styles, a handler and its types).
  2. Accidental coupling: The files change together because of a hidden dependency that shouldn't exist.

The authorship and sequence of changes provide additional questions to investigate. Neither author identity nor commit timing alone distinguishes legitimate coupling from a hidden design problem.

When the same developer changes both files together, inspect whether the connection is intentional and documented. Knowledge of a relationship can coexist with an architectural problem.

When different developers change the files separately and follow-up fixes recur, inspect the changed behavior and the fixes. The sequence can suggest an undocumented dependency, but other causes must be checked.

I track this by analyzing commit sequences:

bash
# Find bug-fix commits that follow changes to specific files
# (Requires commits to reference issue numbers)
git log --oneline --all | grep -i "fix\|bug\|hotfix" | head -20

A more detailed analysis can link issue-tracker data with commits and inspect fixes following changes elsewhere. This highlights candidate dependencies for review. Confirm the relationship in the code before saying that a change to file A caused file B to fail.

Pattern 3: Review Bottlenecks

Code review patterns reveal organizational bottlenecks that don't show up in any code metric.

Questions to investigate:

  • Who reviews the most PRs? If one person reviews 40% of all PRs, they're a bottleneck and a burnout risk.
  • Which PRs take the longest to merge? If PRs touching module X take 3x longer than average, that module might have unclear ownership or excessive complexity.
  • What's the review-to-rework ratio? If a developer's PRs consistently require 3+ review cycles, they might need mentoring on that part of the codebase.

The GitHub CLI example below queries a bounded merged-PR sample and calculates open-to-merge times. Collect the same defined measures over consistent windows when tracking changes to the review process.[5]

bash
# GitHub CLI: bounded sample of PR open-to-merge times from the last 30 days
cutoff=$(python3 -c 'from datetime import datetime, timedelta, timezone; print((datetime.now(timezone.utc) - timedelta(days=30)).date().isoformat())')
gh pr list --state merged --search "merged:>=$cutoff" --limit 50 --json number,createdAt,mergedAt,reviewDecision | \
  jq '.[] | {number, days_to_merge: (((.mergedAt | fromdateiso8601) - (.createdAt | fromdateiso8601)) / 86400 | floor)}'

Pattern 4: Coordination Costs

Conway's Law says that systems mirror the communication structures of the organizations that build them. Behavioral code analysis lets you see Conway's Law in action.

Social complexity measures how many different teams or individuals need to coordinate to change a module. High social complexity means changes require cross-team communication, scheduling, and sign-off, all of which slow delivery and increase error rates.

I measure it by counting the number of distinct authors per module per quarter. Modules where 5+ developers from 3+ teams make regular changes have high social complexity. These modules tend to have:

  • Higher defect rates (3-4x average, in my experience)
  • Longer PR cycle times (2-3x average)
  • More merge conflicts
  • More "this broke when I changed that" incidents

The fix is usually organizational, not technical. Either refactor the module along team boundaries or change the team structure so one team owns the entire module.

Pattern 5: Development Rhythm

The cadence of commits reveals how your team actually works:

  • Spike-and-silence pattern: Intense activity followed by quiet periods. Common when teams don't break work into small increments. Leads to large, risky PRs.
  • Steady rhythm: Consistent daily commits. Indicates well-scoped work and good development habits.
  • Friday afternoon surge: A disproportionate number of commits on Friday afternoon. Often means developers are rushing to complete sprint work. These commits have a higher-than-average defect rate in every dataset I've analyzed.
  • After-hours commits: Regular commits at 10 PM or on weekends invite a conversation about time zones, working preferences and workload. Timestamps alone cannot establish burnout or unrealistic deadlines.
bash
# Commit distribution by hour and day
git log --since="6 months ago" --format='%ad' --date=format:'%u %H' | \
  awk '{day=$1; hour=$2; count[day" "hour]++} END {for (k in count) print count[k], k}' | \
  sort -k2,2n -k3,3n

The Framework: PEOPLE Analysis

P - Patterns: Mine your git log and PR data for the five patterns above: knowledge silos, temporal coupling, review bottlenecks, coordination costs, and development rhythm.

E - Evaluate risk: For each pattern, assess the risk. A knowledge silo in a logging module is less dangerous than one in the billing engine.

O - Overlay with structural data: Cross-reference behavioral patterns with structural metrics. Knowledge silos in high-complexity modules are your top priority. Review bottlenecks on high-churn files are your second priority.

P - Plan interventions: Design specific actions for each high-risk finding. Pair programming assignments, review rotations, module refactoring, team restructuring.

L - Loop: Re-run the analysis quarterly. Track whether your interventions are working. Behavioral patterns are slow to change, so don't expect overnight results.

E - Expand: Once you've addressed the highest-risk patterns, expand your analysis to cover more of the codebase. Start with your revenue-critical paths and work outward.

PatternsGit and PR dataEvaluate riskOverlay structurePlaninterventionsPair and refactorLoop andexpandQuarterly review
Figure 2. Re-run the analysis after an intervention and inspect what changed.

The Contrarian Take: Code Quality Is a People Problem

The uncomfortable truth that behavioral code analysis reveals is that most "code quality" problems are actually people problems. The code is messy because the team is under pressure. The architecture is tangled because the team structure doesn't match the system structure. The bugs keep recurring because knowledge is concentrated in one person.

You can run every linter and static analyzer on the market, and you still won't catch these issues. They live in the space between the code and the humans who write it.

Behavioral code analysis bridges that gap. It takes the human dimension of software development, the part we usually address with retrospectives and gut feelings, and turns it into data.

Data doesn't replace good management. But it does replace guessing with knowing. And that changes everything.

Frequently asked questions

Does commit ownership prove that only one person knows a module?

Commit history records contributions under the identities present in Git. Reviews, pairing, prior work and shared knowledge may be absent from that record. Use author concentration to choose where to investigate, then confirm the knowledge risk with the team.

Does changing two files together prove a bad dependency?

Co-change is a signal to inspect. A component and its tests may properly evolve together, while an unexpected cross-module change may reveal a hidden dependency. Read the changes and compare them with the intended architecture before deciding what to alter.

How should author identities be handled?

Use canonical identities so a developer's different email addresses are not counted as separate people. Git supports a mailmap for this purpose. Record the analysis window and how merges, generated files and renamed paths were handled.

Should after-hours commits be used to judge individuals?

Commit times can reflect time zones, flexible schedules or delayed pushes as well as workload. Discuss the context with developers and review patterns at team level. A timestamp alone cannot establish burnout, poor planning or individual performance.

Sources

  1. [1]Your Code as a Crime Scene · The Pragmatic Bookshelf
  2. [2]Git - git-log Documentation · Git
  3. [3]Git - gitmailmap Documentation · Git
  4. [4]Change Coupling: Visualize Logical Dependencies — CodeScene 1 Documentation · CodeScene
  5. [5]GitHub CLI · GitHub CLI

Checked against these sources on

Related Articles