gomaat

module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2026 License: GPL-3.0

README

gomaat

A Go port of code-maat — a command-line tool that mines git history to surface design insights. Identify logical coupling, code churn, authorship patterns, fragmentation, and more.

Inspired by the books Your Code as a Crime Scene and Software Design X-Rays by Adam Tornhill.


Table of Contents


Installation

From a GitHub Release

Prebuilt binaries for Linux, macOS, and Windows are published on the Releases page. Archives are named gomaat_<version>_<os>_<arch>.tar.gz (.zip on Windows) with a checksums.txt alongside them.

Linux (amd64):

curl -LO https://github.com/ethangardner/gomaat/releases/download/v1.2.0/gomaat_1.2.0_linux_amd64.tar.gz
tar -xzf gomaat_1.2.0_linux_amd64.tar.gz
sudo mv gomaat /usr/local/bin/

Use gomaat_1.2.0_linux_arm64.tar.gz on arm64 hosts. For a newer release, replace 1.2.0 in both the URL and the filename with the latest version number.

macOS (Apple Silicon / Intel):

curl -LO https://github.com/ethangardner/gomaat/releases/download/v1.2.0/gomaat_1.2.0_darwin_arm64.tar.gz
tar -xzf gomaat_1.2.0_darwin_arm64.tar.gz
sudo mv gomaat /usr/local/bin/

Use gomaat_1.2.0_darwin_amd64.tar.gz on Intel Macs. For a newer release, replace 1.2.0 in both the URL and the filename with the latest version number. The binary is unsigned, so the first run may require approving it via System Settings → Privacy & Security (or run xattr -d com.apple.quarantine /usr/local/bin/gomaat).

Windows (amd64):

  1. Download gomaat_1.2.0_windows_amd64.zip from the latest release (replace 1.2.0 with the current version).
  2. Extract the archive and move gomaat.exe into a folder on your PATH (e.g. C:\Program Files\gomaat\).
  3. Add that folder to PATH if it isn't already: System Properties → Environment Variables → Path → New.

Or via PowerShell:

Invoke-WebRequest -Uri https://github.com/ethangardner/gomaat/releases/download/v1.2.0/gomaat_1.2.0_windows_amd64.zip -OutFile gomaat.zip
Expand-Archive gomaat.zip -DestinationPath .
Move-Item gomaat.exe "C:\Program Files\gomaat\gomaat.exe"

Verify any download against checksums.txt from the same release.

From Source

Requirements: Go 1.27.1 or later, git on your PATH.

git clone <repo-url>
cd gomaat
go install ./cmd/gomaat/

Or build a binary directly:

go build -o gomaat ./cmd/gomaat/

Check the installed version with gomaat --version.


Workflow

  1. Generate a log from your git repository.
  2. Run an analysis against that log file.
# Step 1 — generate the log
gomaat generate-log --after 2023-01-01 --outfile logfile.log

# Step 2 — run an analysis
gomaat coupling -l logfile.log

All analyses read from a pre-generated log file rather than calling git directly. This makes repeated analysis fast and allows you to version-control the log for reproducible results.


Generating a Git Log

The generate-log subcommand runs the correct git log invocation so you don't have to remember the flags.

gomaat generate-log [flags]
Flag Default Description
--after (all history) Only include commits after this date (YYYY-MM-DD)
--before (all history) Only include commits before this date (YYYY-MM-DD)
--path . Path to the git repository
--outfile stdout Write the log to this file
--exclude (none) Exclude paths matching this pattern (repeatable, supports globs)
--exclude-author (none) Exclude commits by this author name (repeatable, case-sensitive, matches %aN; * is the only wildcard, so [bot] matches literally)
--ignore-revs-file (none) Drop commits listed in this file (one full SHA per line, same format as git blame --ignore-revs-file)

Examples:

# Current directory, all history, print to stdout
gomaat generate-log

# Last two years, save to file
gomaat generate-log --after 2023-01-01 --outfile logfile.log

# Fixed historical window, e.g. Q1 2025
gomaat generate-log --after 2025-01-01 --before 2025-04-01 --outfile logfile.log

# Different repo
gomaat generate-log --path /path/to/project --after 2022-06-01 --outfile logfile.log

# Exclude generated files and vendored dependencies
gomaat generate-log --exclude vendor/ --exclude '*.pb.go' --outfile logfile.log

# Drop bot accounts so they don't skew churn/coupling/ownership metrics
gomaat generate-log --exclude-author "dependabot[bot]" --exclude-author "renovate*" --outfile logfile.log

# Drop a mass-reformat commit (and any other commits listed in the file) by SHA
gomaat generate-log --ignore-revs-file .git-blame-ignore-revs --outfile logfile.log

The log is generated using:

git log --all --numstat --date=short --pretty=format:'--%H--%ad--%aN' --no-renames --no-merges [--after=DATE] [--before=DATE] [-- :(top) :(top,exclude,literal)DIR/ ...]

Note: --no-renames means renamed files are tracked as a delete + add rather than a rename. This avoids inflated coupling between old and new paths.

Note: --no-merges excludes merge commits, so a combined merge diff never gets double-counted against the commits it merges.

Note: author names come from %aN, which applies the repository's .mailmap automatically. To collapse one person committing under several names or emails into one canonical author, add a .mailmap at the repo root; no flag is needed.

Note: the log's rev field is the full commit hash (%H), not the abbreviated %h used in earlier versions, so it can be matched unambiguously against a .git-blame-ignore-revs-style file. Rev is treated as an opaque string everywhere it's consumed, so this only changes the value shown in output, not its meaning.

Note: --ignore-revs-file is not a native git log concept (--ignore-revs-file is a git blame flag) — gomaat reads the file itself and drops matching commits from its own output after git log runs.

Note: the file follows git blame's rules: # starts a comment anywhere on a line, blank lines are ignored, and every other line must be a full 40- or 64-character commit hash. An abbreviated hash (e.g. copied from git log --oneline or from v1.0's short-hash output) is an error, as it is for git blame, instead of silently matching nothing.

Note: generate-log's output is raw git log text (the format internal/parser reads), not CSV, so --format is a no-op here — --format json is rejected since there's no tabular data to convert.


Global Flags

These flags are available on every analysis subcommand.

Flag Short Default Description
--log -l (required) Path to the git log file
--outfile -o stdout Write output to this file
--rows -r 0 (no limit) Maximum number of result rows
--group -g (none) Architectural grouping spec file
--team-map-file -p (none) Team mapping CSV file
--format -f csv Output format: csv or json

Analyses

All analyses write CSV to stdout by default. Use -o <file> to write to a file instead, or --format json (-f json) to write a JSON array of objects instead of CSV.


authors

Count the number of distinct authors and total revisions per entity. Entities with many authors have a higher communication overhead and tend to accumulate more defects.

gomaat authors -l logfile.log

Output:

Column Description
entity File path
n-authors Number of distinct authors
n-revs Total revisions

Sorted by n-authors descending.

entity,n-authors,n-revs
src/core/Engine.java,8,42
src/api/Router.java,5,18
src/util/Parser.java,1,3

revisions

Count the total number of revisions per entity. Frequently changed files are higher-risk and worth prioritizing for quality improvements.

gomaat revisions -l logfile.log

Output:

Column Description
entity File path
n-revs Total revisions

Sorted by n-revs descending.


coupling

Detect temporal (logical) coupling — modules that change together more often than chance. Coupling that isn't visible in the code is often a sign of hidden dependencies or misplaced responsibilities.

gomaat coupling -l logfile.log [flags]
Flag Short Default Description
--min-revs -n 5 Minimum revisions for an entity to be included
--min-shared-revs -m 5 Minimum number of shared revisions between a pair
--min-coupling -i 30 Minimum coupling percentage to report
--max-coupling -x 100 Maximum coupling percentage to report
--max-changeset-size -s 30 Ignore commits that touch more than this many files (large refactors skew results)
--verbose-results false Add extra columns: per-entity revision counts and shared revision count

Coupling formula:

degree = (shared_revisions / average_revisions(A, B)) × 100

Output:

Column Description
entity First file
coupled Second file
degree Coupling percentage
average-revs Average revision count across both files

With --verbose-results, three extra columns are appended: first-entity-revisions, second-entity-revisions, shared-revisions.

Sorted by degree descending, then average-revs descending, then entity and coupled ascending.

entity,coupled,degree,average-revs
src/Order.java,src/Invoice.java,82,44
src/User.java,src/Auth.java,61,38

Tip: Start with looser thresholds (-n 2 -m 2 -i 10) to see the full picture, then tighten them to focus on the strongest signals.


soc (Sum of Coupling)

Aggregate the total coupling for each entity — how many co-change relationships it participates in across all revisions. High SOC entities are "hubs" that everything depends on.

gomaat soc -l logfile.log [flags]

Accepts the same threshold flags as coupling.

Output:

Column Description
entity File path
soc Sum of coupling (total co-change count)

Sorted by soc descending.


summary

Print a quick overview of the dataset: commit count, entity count, and author count.

gomaat summary -l logfile.log

Output:

statistic,value
number-of-commits,1432
number-of-entities,318
number-of-entities-changed,8741
number-of-authors,24

statistics

Descriptive statistics (count, min, q1, median, q3, max, mean, sample-stddev) for five core metrics: files and lines changed per commit, and revisions/authors/sum-of-coupling per entity. Useful for spotting outliers and understanding the overall shape of a codebase's history at a glance.

gomaat statistics -l logfile.log

Output:

Column Description
metric Which metric this row describes
count Number of data points
min Minimum value
q1 First quartile
median Median value
q3 Third quartile
max Maximum value
mean Arithmetic mean
stddev Sample standard deviation

metric is always the following five rows, in this order: files-changed-per-commit, lines-changed-per-commit, revisions-per-entity, authors-per-entity, soc-per-entity.

Unlike other analyses, statistics always reports on the whole dataset — it ignores coupling-style threshold flags (--min-revs, --max-changeset-size, etc.) since it's a codebase health report, not a filtered query.

metric,count,min,q1,median,q3,max,mean,stddev
files-changed-per-commit,48,1.00,1.00,2.00,5.00,28.00,4.73,6.06
lines-changed-per-commit,48,1.00,17.50,54.00,177.25,2244.00,194.75,399.44
revisions-per-entity,56,1.00,2.00,4.00,5.25,11.00,4.05,2.75
authors-per-entity,56,1.00,1.00,1.00,1.00,1.00,1.00,0.00
soc-per-entity,56,0.00,13.00,45.00,70.50,110.00,45.96,33.76

abs-churn

Absolute code churn aggregated by date — total lines added and deleted per day. Useful for identifying turbulent periods in development history.

gomaat abs-churn -l logfile.log

Output:

Column Description
date Commit date (YYYY-MM-DD)
added Lines added
deleted Lines deleted
commits Number of commits on that date

Sorted by date ascending.


author-churn

Lines added and deleted aggregated by author. Shows individual contribution volume.

gomaat author-churn -l logfile.log

Output:

Column Description
author Author name
added Total lines added
deleted Total lines deleted
commits Total commits

Sorted by author ascending.


entity-churn

Lines added and deleted aggregated by entity. Pre-release churn is one of the strongest predictors of post-release defects.

gomaat entity-churn -l logfile.log

Output:

Column Description
entity File path
added Total lines added
deleted Total lines deleted
commits Total commits

Sorted by added descending.


entity-ownership

Churn broken down by (entity, author) pair. Shows exactly how much each author contributed to each file in terms of lines written.

gomaat entity-ownership -l logfile.log

Output:

Column Description
entity File path
author Author name
added Lines added by this author
deleted Lines deleted by this author

Sorted by entity ascending.


main-dev

Identify the main developer per entity — the author responsible for the most lines added. Combined with entity-churn, this tells you who to talk to about a problematic file.

gomaat main-dev -l logfile.log

Output:

Column Description
entity File path
main-dev Author with the most lines added
added Lines added by main developer
total-added Total lines added to this entity
ownership Main developer's share (%)

Sorted by entity ascending.


refactoring-main-dev

Like main-dev, but ranks by lines deleted rather than added. Line deletions are a proxy for design decisions — the author who deletes the most often has the deepest understanding of the code.

gomaat refactoring-main-dev -l logfile.log

Output:

Column Description
entity File path
main-dev Author with the most lines deleted
removed Lines deleted by main developer
total-removed Total lines deleted from this entity
ownership Main developer's share (%)

Sorted by entity ascending.


entity-effort

Revision count per (entity, author) pair. Useful for understanding knowledge distribution without relying on line counts (which can be misleading for reformatted files).

gomaat entity-effort -l logfile.log

Output:

Column Description
entity File path
author Author name
author-revs Revisions by this author
total-revs Total revisions to this entity

Sorted by entity ascending, then author-revs descending within each entity, then author ascending.


main-dev-by-revs

Main developer per entity ranked by revision count rather than lines. Revision count is a more stable signal than line count for files that are frequently reformatted or auto-generated.

gomaat main-dev-by-revs -l logfile.log

Output:

Column Description
entity File path
main-dev Author with the most revisions
added Revisions by main developer
total-added Total revisions to this entity
ownership Main developer's share (%)

Sorted by entity ascending.


fragmentation

The fractal value (0–1) measuring how evenly development effort is distributed across authors for each entity.

  • 0.00 — single author owns this entity entirely
  • Approaching 1.00 — many authors contribute equally

Highly fragmented entities have diffuse ownership and are harder to reason about.

gomaat fragmentation -l logfile.log

Fragmentation formula:

fractal = 1 - Σ(author_revisions / total_revisions)²

Output:

Column Description
entity File path
fractal-value Fragmentation score (0.00–1.00)
total-revs Total revisions to this entity

Sorted by fractal-value descending.


bus-factor

The fewest authors who together own more than 50% of each entity, where ownership is lines added (the same measure as main-dev). A bus factor of 1 means a single person wrote most of the file — if they leave, most of its knowledge goes with them.

Authors are ranked by lines added (ties broken alphabetically) and taken from the top until their combined share passes 50%. Exactly 50% is not a majority, so two authors with an even split give a bus factor of 2. Entities with no added lines (deletions only) are omitted.

gomaat bus-factor -l logfile.log

Example output:

entity,bus-factor,top-owners,ownership
src/billing.go,1,Alice Smith,82.35
src/api.go,2,Bob Jones;Carol White,71.43

Output:

Column Description
entity File path (or group name with -g)
bus-factor Fewest authors whose combined lines added exceed 50%
top-owners Those authors, largest share first, separated by ;
ownership Their combined share of the entity's lines added (%)

Sorted by bus-factor ascending (riskiest first), then entity.


knowledge-loss

The share of each entity written by authors who have left. Pass a former authors file with --former-authors (required). Ownership is lines added, the same measure as main-dev and bus-factor.

gomaat knowledge-loss -l logfile.log --former-authors alumni.txt

Example output:

entity,former-added,total-added,knowledge-loss
src/legacy.go,240,240,100.00
src/billing.go,56,170,32.94
src/api.go,0,35,0.00

Output:

Column Description
entity File path (or group name with -g)
former-added Lines added by former authors
total-added Total lines added to this entity
knowledge-loss former-added as a share of total-added (%)

Sorted by knowledge-loss descending, then entity. Entities with no former-author contributions are still listed at 0.00; entities with no added lines are omitted. Names in the former-authors file that never appear in the log are ignored.

Results are only as accurate as author identity resolution: names are matched exactly, so someone who committed as both Alice Smith and alice needs both names listed — or add a .mailmap to the repository so generate-log collapses them to one canonical name first. With -p, matching happens after team mapping, so the former-authors file must list team names.


whoknows

Who currently knows a file or directory: authors ranked by lines added to it on or after --after (default: 12 months ago). Pass a directory to aggregate every file beneath it, . for the whole log, or a group name with -g.

gomaat whoknows -l logfile.log <path> [--after YYYY-MM-DD]
Flag Default Description
--after 12 months ago Count only commits on or after this date (YYYY-MM-DD)

How it differs from main-dev: both measure ownership as lines added, but main-dev counts every line ever added, per file, so it often names someone who wrote the file years ago and has since moved on. whoknows drops everything before --after, so the ranking reflects who has been working on the code recently, and it answers for one path at a time, including a whole directory.

Contributions before the cutoff are dropped entirely, not weighted down (see ADR 0008 for why gomaat doesn't use time-decay weighting). If a slow-moving file has no commits in the window, the output is empty; move --after back to widen it.

Example output:

author,added,ownership
Bob Jones,182,71.65
Carol White,72,28.35
Alice Smith,0,0.00

Output:

Column Description
author Author (or team with -p)
added Lines added to the path since --after
ownership added as a share of all lines added to the path since --after (%)

Sorted by added descending, then author. Authors whose commits in the window only deleted lines are listed with 0.


communication

Map communication needs across the team. Author pairs who frequently modify the same entities need to coordinate — this analysis makes that implicit need explicit. Based on Conway's Law.

gomaat communication -l logfile.log

Strength formula:

strength = (shared_entities / ceil(avg(entities_A, entities_B))) × 100

where shared_entities is the count of entities both authors have touched.

Output:

Column Description
author First author
peer Second author
shared Number of entities both have touched
average ceil((total_entities_A + total_entities_B) / 2)
strength Communication need as a percentage

Sorted by strength descending, then author and peer ascending. Each pair appears twice (once per direction, with identical shared, average and strength), so filtering on author alone shows all of one person's peers. It also means -r counts rows, not pairs. A pair's two rows are only adjacent when no other pair ties on strength, so -r 10 can return anywhere from 5 to 10 distinct pairs, some in only one direction.


age

Months since each entity was last modified, relative to a reference date. Old, untouched code is either stable or forgotten — either way it's worth knowing about.

gomaat age -l logfile.log [--age-time-now YYYY-MM-DD]
Flag Short Default Description
--age-time-now -d today Reference date for age calculation

Output:

Column Description
entity File path
age-months Months since last modification

Sorted by age-months ascending (youngest first).


orphans

Files that appear in exactly one commit in the log, where that commit added at least --min-lines lines: code dropped in once and never revised since. A large, never-touched file can be speculative or generated code that nobody integrated or iterated on.

This is a heuristic, not proof of dead or unused code. It looks only at revision count and size. A flagged file may be legitimately stable, vendored, or generated-and-correct. gomaat doesn't check whether anything imports or calls the file. Treat the output as a list of files to look at, not a list of files to delete.

"Exactly one commit" means within the log you pass. A log generated with --after counts only commits in that window, so an old file edited once inside it will show up too.

gomaat orphans -l logfile.log [--min-lines 200]
Flag Default Description
--min-lines 200 Minimum lines added in the single commit (inclusive) to report

Example output:

entity,added-lines,date,author
src/generated/schema.go,2140,2025-03-11,Alice Smith
src/legacy/importer.go,612,2024-11-02,Bob Jones

Output:

Column Description
entity File path (or group name with -g)
added-lines Lines added in the entity's only commit
date Date of that commit
author Author of that commit (or team with -p)

Sorted by added-lines descending (biggest single-shot drops first), then entity.


identity

Dump the raw parsed commit records as CSV. Useful for debugging the log format or inspecting what gomaat sees before analysis.

gomaat identity -l logfile.log

Output:

Column Description
entity File path
rev Commit hash
date Commit date
author Author name
loc-added Lines added (0 for binary files)
loc-deleted Lines deleted (0 for binary files)

Repository Analyses

These analyses need more than the numstat line counts in a generate-log file, so they read the git repository directly (--path) and ignore --log, --group, and --team-map-file (setting them is an error).

rework

For each file, the share of added lines that were removed or substantially rewritten soon after they landed. Code that goes in and quickly comes back out is a strong signal that a change wasn't right the first time. It applies the same way whether a human or an agent wrote the code.

gomaat rework [pathspec...] [flags]
Flag Short Default Description
--path . Path to the git repository
--rework-window -w 14d How soon after landing a removal counts as rework: Nd, Nw, or a Go duration such as 36h
--after (none) Only walk commits after this date (YYYY-MM-DD). Lines that already existed are untracked
--before (none) Only walk commits before this date (YYYY-MM-DD). Lines are also judged as of this date (default: now)
--exclude (none) Exclude paths matching this pattern (repeatable; same rules as generate-log --exclude)
pathspec... (all) Limit the walk to these paths (git pathspecs, relative to --path; prefix with :/ for the repo root), e.g. known hotspots

--outfile, --rows, and --format work as for every other command.

Output:

Column Description
entity File the lines were added to
added-lines Non-blank lines added whose window has fully elapsed
reworked-lines Of those, lines removed or substantially rewritten within the window
rework-ratio reworked-lines / added-lines, as a percentage

Sorted by reworked-lines descending, then entity.

entity,added-lines,reworked-lines,rework-ratio
src/billing/invoice.go,1240,310,25.00
src/api/handlers.go,2210,265,11.99
coverage.out,197,197,100.00
src/util/strings.go,480,12,2.50
src/legacy/export.go,6,4,66.67

Reading the output.

  • reworked-lines shows where the most throwaway code went. The sort order puts the most effort spent writing code that didn't last at the top. Start there.
  • rework-ratio shows how often code in a file isn't right the first time. Read it together with added-lines. src/billing/invoice.go above is the stronger signal: a quarter of more than a thousand lines came back out within two weeks. The 66.67% on src/legacy/export.go is 4 of 6 lines, which is noise.
  • A ratio near 100% usually means the file isn't hand-written. Generated files, build output, or artifacts committed by mistake (like coverage.out above) get replaced wholesale. Drop them with --exclude and rerun.
  • There's no universal "good" ratio. It depends on the language, the team, and the window. Compare files within the same repo, or the same file across time periods (--after/--before), instead of against a fixed threshold.
  • The window changes what you're measuring. A short window (a few days) mostly catches immediate fix-ups: review feedback, a bug found right after merge, a follow-up commit. A longer window (a month or more) also catches design churn, where an approach was tried and then replaced.
  • Recent code is excluded. Lines younger than the window at --before/now aren't counted yet, so a file that's mostly new shows few added-lines even if it's changing a lot.

What to do with it. High rework is a question to investigate, not a verdict. Cross-check a file with the log-based analyses:

  • High rework on a file that's also at the top of revisions or entity-churn is a hotspot that keeps being gotten wrong. It's a candidate for clearer requirements, better tests, or a redesign.
  • High rework with many authors (authors, fragmentation) points to coordination problems. People are overwriting each other's work.
  • High rework on a file that's usually low suggests something changed in that period. Look at the commits: a rushed feature, a new contributor, or code generated without review.
# Default 14-day window over the whole history
gomaat rework -r 20

# Two-week window over the last year, scoped to two hotspots
gomaat rework --rework-window 2w --after 2025-01-01 src/billing/ src/api/handlers.go

# Skip vendored and generated code
gomaat rework --exclude vendor/ --exclude '*.pb.go'

How "reworked" is defined. gomaat walks the repo's first-parent history oldest-first using zero-context patches (git log --reverse --first-parent --diff-merges=first-parent -p -U0 --no-renames). It records which commit introduced every line. When a later commit removes a line, the removal is classified in order:

  1. Moved, not rework: the commit re-adds the same text somewhere else, in any file, ignoring whitespace. The line keeps its original landing time. This also carries lines across renames, which --no-renames reports as a delete plus an add.
  2. Edited, not rework: a line in the same hunk replaces it and is at least 60% token-similar (Dice coefficient over identifier and number tokens, ignoring punctuation). For example, if count > limit { becomes if count >= limit {. If either line has no identifiers or numbers, punctuation counts as tokens too, so ) becoming ), is an edit. The edited line keeps the original line's landing time.
  3. Otherwise it's removed. If that happens within --rework-window of the line landing, it counts as reworked.

Other rules:

  • A line only counts once its window has fully elapsed by --before/now. Younger lines are left out of both counts rather than counted as survivors.
  • Blank lines never count.
  • For merge commits, gomaat counts the merge's diff against its first parent as landing those lines at the merge's committer date. So merge-commit, squash-merge, and rebase workflows are measured the same way. Edits made on a branch before it merges aren't rework.

Known limitations (these are heuristics, not precise measurements):

  • Counted as rework but arguably not (false positives):
    • Code moved into a file outside the pathspec, or into one dropped by --exclude, looks like a deletion.
    • Splitting one line into several, or joining several into one, fails both the move and edit checks.
    • A reformat that changes tokens (not just whitespace) can fall below the similarity threshold.
  • Missed rework (false negatives):
    • A rewrite that keeps most of a line's tokens counts as an edit.
    • Deleting a line while an identical line (e.g. } or return nil) is added elsewhere in the same commit looks like a move.
  • Edits are paired by position within a hunk. If replaced lines are reordered, the pairing can be wrong in either direction.
  • Only first-parent history is analyzed. Churn that happened only on side branches is invisible.
  • Starting mid-history matters. With --after (or a shallow clone), lines that already existed when the walk starts are untracked. Their removal is never counted.

Performance. rework streams the full patch history rather than numstat, so it costs far more than the log-based analyses:

  • Time grows with the total number of changed lines, plus the current length of each file every time it's touched.
  • Memory holds one provenance record per line of every tracked file.

Measured on an i7-1255U:

Repository Scope First-parent commits walked Time Peak memory
gomaat full history 59 0.1 s 31 MB
uswds since 2023 334 1.1 s 101 MB
uswds full history (16k commits, mostly on branches) 931 4.0 s 247 MB
kubernetes pkg/scheduler/ since 2024 605 1.9 s 229 MB
kubernetes whole repo since 2025-06, --exclude vendor/ 4,047 13 s 398 MB

On large repos, don't run it repo-wide over all history on every commit. Scope it with pathspecs (for example the top of revisions or entity-churn) and --after, and exclude generated files, which dominate otherwise (lockfiles, *.pb.go, vendored bundles).


Code Metrics

cloc

Count lines of code, comments, and blank lines across a directory. Unlike the analysis commands, cloc works directly against source files and does not require a git log.

gomaat cloc [flags]
Flag Default Description
--path . Directory to analyze
--by-file false Show results per file instead of per language
--exclude (none) Exclude paths matching this pattern (repeatable, supports globs)
--outfile stdout Write output to this file
--rows 0 (no limit) Maximum number of result rows
--format csv Output format: csv or json

Output (by language, default):

Column Description
Language Programming language
Files Number of files
Blank Blank lines
Comment Comment lines
Code Lines of code

Sorted by Code descending, then Language ascending. A TOTAL row is always appended.

Language,Files,Blank,Comment,Code
Go,42,410,180,3100
YAML,5,12,0,88
Makefile,1,8,4,22
TOTAL,48,430,184,3210

With --by-file, each row represents a single file sorted by path, with a File column replacing Language and a Language column added.

Examples:

# Count lines in the current directory
gomaat cloc

# Analyze a different repo
gomaat cloc --path /path/to/project

# Exclude vendored and generated files
gomaat cloc --exclude vendor/ --exclude '*.pb.go'

# Per-file breakdown saved to CSV
gomaat cloc --by-file -o cloc.csv

# Top 10 largest files by code
gomaat cloc --by-file -r 10

# Per-language breakdown as JSON
gomaat cloc --format json

The --exclude patterns follow the same rules as generate-log --exclude: patterns ending in / match directory prefixes; all others are matched as globs against both the full path and the base filename.


Advanced Usage

Architectural Grouping

Map file paths to named architectural boundaries before running analysis. Results are aggregated at the component level rather than the file level — useful for large codebases where file-level coupling is too noisy.

Create a grouping spec file (one rule per line):

# Lines starting with # are ignored
src/orders    => Orders
src/payments  => Payments
src/users     => Users
^src/shared/  => Shared

Plain paths are matched as prefixes (src/orders/ matches src/orders/Model.java). Lines starting with ^ are treated as regular expressions.

gomaat coupling -l logfile.log -g groups.txt

Files that don't match any group are excluded from the analysis.


Team Mapping

Replace individual author names with team names before running analysis. Social metrics like communication and fragmentation then operate at the team level.

Create a CSV file mapping authors to teams:

author,team
Alice Smith,Backend
Bob Jones,Backend
Carol White,Frontend
Dave Brown,Platform

The header row is optional and automatically skipped.

gomaat communication -l logfile.log -p teams.csv
gomaat fragmentation -l logfile.log -p teams.csv

Authors not present in the map are excluded from analysis.


Former Authors

knowledge-loss takes a list of authors who have left via --former-authors. The file uses the same conventions as the team mapping CSV: one author per line, an optional author header row, and # comment lines.

author
Alice Smith
Dave Brown

A CSV with extra columns is also accepted — only the first column is read, so you can keep notes alongside each name:

author,left
Alice Smith,2024-03-01
Dave Brown,2025-01-15
gomaat knowledge-loss -l logfile.log --former-authors alumni.csv

Names must match the log's author names exactly (see the identity note under knowledge-loss). Because the file is read as CSV, a name containing a comma must be double-quoted ("Doe, Jane"); quotes inside an unquoted name (Bob "The Builder" Smith) are kept as-is.


Tracking Metrics Over Time

gomaat has no built-in trend command — every analysis operates on a single, static log file. To see how a metric changes over time (e.g. is statistics's soc-per-entity getting worse release over release?), generate one log per period with generate-log --after/--before, run the same analysis against each, tag the results with their period, and combine them yourself. This works for any analysis, but is most useful for whole-dataset reports like statistics and summary.

There are two ways to window each period, and they answer different questions:

  • Cumulative — --before <date> only, no --after. Each log is "everything up to this point," so statistics/summary show how the codebase's overall shape has evolved to date. Best for metrics like revisions-per-entity or soc-per-entity, where you care about accumulated history.
  • Windowed — --after <start> --before <end> per period. Each log contains only that slice's activity, so results reflect what happened during the period, not the whole history. Best for churn-style, period-over-period comparisons.

Example — quarterly cumulative snapshots of statistics, combined into one JSON time series:

#!/usr/bin/env bash
for cutoff in 2024-04-01 2024-07-01 2024-10-01 2025-01-01; do
  gomaat generate-log --before "$cutoff" --outfile "log-$cutoff.log"
  gomaat statistics -l "log-$cutoff.log" --format json \
    | jq --arg period "$cutoff" '[.[] | . + {period: $period}]'
done | jq -s 'add' > statistics-over-time.json

The result is a single JSON array with one object per metric per period (each carrying a period field), ready to load into a spreadsheet, filter with jq (e.g. jq '[.[] | select(.metric=="soc-per-entity")]' statistics-over-time.json to isolate one metric's trend), or feed into a plotting tool.

Prefer CSV? Prepend a period column with awk instead of using --format json:

echo "period,metric,count,min,q1,median,q3,max,mean,stddev" > statistics-over-time.csv
for cutoff in 2024-04-01 2024-07-01 2024-10-01 2025-01-01; do
  gomaat generate-log --before "$cutoff" --outfile "log-$cutoff.log"
  gomaat statistics -l "log-$cutoff.log" | tail -n +2 \
    | awk -v period="$cutoff" '{print period "," $0}' >> statistics-over-time.csv
done

This pattern combines well with Architectural Grouping and Team Mapping — add -g/-p to each per-period run to track one component's or team's metrics over time instead of the whole codebase.


Limiting Output Rows

Use -r to cap the number of result rows. Useful when piping to other tools or when you only care about the top N results.

# Top 10 most coupled module pairs
gomaat coupling -l logfile.log -n 2 -m 2 -r 10

# Top 5 most revised files
gomaat revisions -l logfile.log -r 5

Writing to a File

Use -o to write CSV output to a file instead of stdout.

gomaat authors -l logfile.log -o authors.csv
gomaat coupling -l logfile.log -o coupling.csv

Example End-to-End Session

# 1. Generate a log 
gomaat generate-log \
  --path /path/to/your/project \
  --after 2024-01-01 \
  --outfile logfile.log

# 2. Overview: how big is the dataset?
gomaat summary -l logfile.log

# 3. Which files change the most?
gomaat revisions -l logfile.log -r 20

# 4. Which files have the most authors?
gomaat authors -l logfile.log -r 20

# 5. Are there hidden dependencies?
gomaat coupling -l logfile.log --min-revs 10 --min-shared-revs 5

# 6. Where is knowledge fragmented?
gomaat fragmentation -l logfile.log -r 20

# 7. Who should talk to whom?
gomaat communication -l logfile.log

# 8. What code has gone untouched for years?
gomaat age -l logfile.log -r 20

# 9. Find the largest files
gomaat cloc --by-file | sort -t, -k5 -nr

License

Copyright (C) 2026 Ethan Gardner

gomaat is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version (GPL-3.0-or-later).

Directories

Path Synopsis
cmd
gomaat command
internal
gitdiff
Package gitdiff parses the patch output of
Package gitdiff parses the patch output of
loadfile
Package loadfile opens input files and hands them to a parser, so every gomaat loader reports open and close errors the same way.
Package loadfile opens input files and hands them to a parser, so every gomaat loader reports open and close errors the same way.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL