git-xray
X-ray any git repository in one command. Find the code that hurts: hotspots, bus factor, hidden coupling, stale and orphaned files.
pipx install git-xray-tool # or: pip install git-xray-tool
# one-off run: uvx --from git-xray-tool git-xray
cd your-repo
git xray
The package is called git-xray-tool on PyPI; the command is git-xray, or just
git xray. No config, no server, no dependencies. Pure Python and git. It analyses Flask's
3,800 commits in under a second.
Why?
Your git history already knows where the problems are. The files that change all the time and are large are where bugs pile up and velocity goes to die. Directories that only one person understands are a risk. Files that always change together hint at a missing abstraction.
Tools like code-maat pioneered this
analysis (see Your Code as a Crime Scene), but they need a JVM, a log export
step and a spreadsheet. git-xray gives you the answers in one command.
What it shows
| Section | Question it answers |
|---|---|
| 🔥 Hotspots | Which files change most often and are big? Your best refactoring targets. |
| 🚌 Bus factor | How many people would have to leave before nobody knows a directory? |
| 🔗 Hidden coupling | Which files keep changing in the same commits, even though nothing says they're related? |
| 🧊 Stale code | Which big files has nobody touched in a year? |
| 👻 Orphaned code | Which files were mostly written by someone who is no longer active? |
| 👥 Contributors | Who did the work in this time range? |
| 🤖 PR check | Is this change risky? Did it forget a file? Who should review it? See below. |
Usage
git xray # whole history of the current repo
git xray --since "6 months ago" # recent activity only
git xray src/ lib/ # limit to some paths
git xray -n 25 # show 25 rows per section
git xray --depth 2 # bus factor per src/foo instead of src/
git xray -x "*.generated.ts" # extra excludes (repeatable)
git xray -C ~/code/other-repo # analyse another repo
Output formats
git xray --md > XRAY.md # Markdown: paste into a PR, wiki or issue
git xray --json | jq '.hotspots' # JSON: build your own dashboards or CI checks
git xray --diff origin/main # PR check for the current branch (also --md / --json)
All options
usage: git-xray [-h] [-C DIR] [--since WHEN] [-n TOP] [--depth DEPTH]
[--min-coupling N] [--stale-days N] [-x GLOB]
[--no-default-excludes] [--include-bots] [--json | --md]
[--color {auto,always,never}] [-V]
[paths ...]
| Option | Default | Meaning |
|---|---|---|
--since WHEN |
all history | Only commits newer than WHEN (anything git log --since accepts) |
-n, --top |
10 | Rows per section |
--depth |
1 | Directory depth used for bus-factor grouping |
--min-coupling |
5 | Minimum shared commits before a pair is reported |
--stale-days |
365 | Days without change before a file counts as stale / an author as inactive |
-x, --exclude |
Glob to skip, repeatable | |
--no-default-excludes |
Keep lockfiles, vendor/, dist/, changelogs, minified files… |
|
--include-bots |
Count dependabot, renovate and other bots | |
--color |
auto | Respects NO_COLOR and FORCE_COLOR |
--icons |
auto | emoji, plain (no emoji) or ascii. Also GIT_XRAY_ICONS |
Check every pull request 🤖
git xray --diff origin/main looks only at what your branch changes and asks history three
questions:
- 🔥 Does it touch a hotspot? Those files deserve a careful review.
- 🔗 Did it forget something? You changed
api.py, which changed together withschema.pyin 100% of past commits, but this PR leavesschema.pyalone. - 👀 Who should review it? The people who wrote most of these files.
As a GitHub Action
Add .github/workflows/git-xray.yml:
name: git-xray
on: pull_request
permissions:
contents: read
pull-requests: write
jobs:
xray:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0 # git-xray needs the history
- uses: ckh0at/git-xray@v0
Every pull request gets one comment that stays up to date as you push:
🔍 git-xray PR check: 🔴 High risk
This PR touches the repo's #2 hotspot and skips 1 file that usually changes together with the files it edits.
🔗 Possibly missing changes
schema.py: changed together withapi.pyin 100% of their commits (7×)👀 Know these files best: Alice (54%), Bob (46%)
| Input | Default | Meaning |
|---|---|---|
comment |
always |
always, risky (only medium/high risk) or never. The report is always in the job summary. |
fail-on |
never |
Fail the check at medium or high risk |
base |
PR base branch | Branch or commit to compare with |
since |
all history | Learn only from recent history, e.g. 2 years ago |
version |
latest | Pin a git-xray-tool version |
The action also sets an output risk (low, medium or high) for later steps. Forked
PRs get a read-only token from GitHub, so for them the report goes to the job summary only.
How the numbers are computed
- Hotspot score =
commits / max_commits × log(loc) / log(max_loc). Change frequency matters most; size is log-scaled so one giant file does not drown out everything else. - Bus factor = the smallest number of authors who together wrote more than 50% of the changed lines in a directory.
- Coupling degree =
shared_commits / average(commits of A, commits of B). Commits touching more than 30 files (mass renames, formatting) are ignored. - PR check: history up to the base branch is used, so the PR's own commits do not count. A changed file is a hotspot if it ranks in the repo's top 10 (or top 5%) with a score of at least 0.25. A file is possibly missing if it changed together with an edited file in at least 60% of their commits (3+ times). High risk means a top-3 hotspot in a repo with 20+ files, or a skipped partner coupled 90%+ over 5+ commits.
- Orphaned = the main author wrote at least 50% of the file and has made no commit in
--stale-days. - Renames are followed (
git log -M), so history survivesgit mv. Merge commits are skipped. Author identities respect your.mailmap.
These are heuristics, not verdicts. A hotspot can be a healthy, central module; the point is to know where to look.
FAQ
Is it fast on big repos? It runs git log once and parses it in a single pass.
Most repos take a second or two. On huge monorepos, narrow it down with --since or a path.
Does it send my code anywhere? No. It runs git locally and prints to your terminal.
I see boxes, garbled symbols or broken columns. git-xray picks a glyph set
from your terminal. In Japanese, Chinese and Korean locales it uses plain ASCII,
because those terminals draw box and block characters double-wide. Some other
terminals still can't draw emoji. Use
git xray --icons plain (no emoji) or --icons ascii, or set it once with
export GIT_XRAY_ICONS=plain (PowerShell: $env:GIT_XRAY_ICONS="plain").
Why git xray and not git-xray? Both work. git treats any git-<name>
executable on your PATH as a subcommand.
Contributing
Issues and PRs are welcome! Ideas we would love help with: an HTML report, GitLab / Bitbucket integration, and per-author knowledge maps.
git clone https://github.com/ckh0at/git-xray && cd git-xray
python -m venv .venv && .venv/bin/pip install -e . pytest
.venv/bin/pytest
License
MIT
Metadata
Release files for git-xray-tool 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| git_xray_tool-0.2.1.tar.gz | 23.5 kB | Without provenance | Details for git_xray_tool-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| git_xray_tool-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for git_xray_tool-0.2.1-py3-none-any.whl |
Total release size: 46.2 kB
Release files / git_xray_tool-0.2.1.tar.gz
| Download URL | git_xray_tool-0.2.1.tar.gz |
|---|---|
| Size | 23.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ab8da3f8bba285f4de4f4678babf48e80d768c694c87f2d6e2ec7d8b55fef550
|
|
BLAKE2b-256 checksum How to use checksums |
ddf6c2a03e40967a8cb74556fb41c303b5ce0c967a2b7b64bcaf6e5f69ae9406
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / git_xray_tool-0.2.1-py3-none-any.whl
| Download URL | git_xray_tool-0.2.1-py3-none-any.whl |
|---|---|
| Size | 22.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
99ffc5cfb925688e2db3c6d89b5f63e219cbca0a6117baf4c238c23daf61ef82
|
|
BLAKE2b-256 checksum How to use checksums |
21cfe1c92a44d52f60095d59dc8d18007be1068a77832c737cb97e77cada30c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Security for git-xray-tool 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.