Point gitstory at a line range and it quotes what git knows about why that code is there: who wrote it, when, the commit messages, and linked PRs.
pip install git+https://github.com/calasdan-sketch/gitstory.git
Needs Python 3.10 or newer and git. Not on PyPI yet; once it is, pip install gitstory-cli will work (the command is still gitstory).
$ gitstory app.py 2-3 --no-gh
gitstory: app.py:2-3
SUMMARY:
First written by Calas Automations on 2026-11-27: add retry helper
Last changed by Calas Automations on 2026-11-27: fix: retry 5 times, the upstream API drops the first calls
2 commit(s) in this range's history. Original reason: subject line only, no extended message.
LINES (blame, -w -C):
2: fc5fbbb Calas Automations 2026-11-27 — for _ in range(5):
3: cf33c41 Calas Automations 2026-11-27 — try:
WHY (from the commit messages — quoted, not reconstructed):
[fc5fbbb] fix: retry 5 times, the upstream API drops the first calls
Three tries was not enough in production.
[cf33c41] add retry helper (no extended message — reason undocumented beyond the subject line)
(... WHO WROTE IT, WHAT IT REPLACED, WHAT BREAKS sections omitted here; see the full example below)
Real output from a throwaway two-commit repo, trimmed for length (the omitted sections are marked). A longer, untrimmed run on a real repo is further down.
- Assembles the evidence. Blame, line history, commit messages and linked PRs/issues, in one short narrative with a cited short hash on every claim.
- Never invents a why. A commit message of "fix stuff" gives "reason undocumented", not a made-up story. Inference is labeled.
- Local and read-only. No LLM calls, no account, no telemetry; it never writes to your repo. The only network use is optional read-only
gh.
Quickstart
gitstory src/app.py 42-58 # a line range
gitstory src/app.py:42 # one line
gitstory auth.py::Auth.login # a Python function or class
gitstory --help shows these examples. Add --json for structured output, --blame-only if history is slow.
Limits up front
- Team tier (shared narratives, IDE plugin) — later, not v0.2.0.
- LLM narration — flagged, not built (hallucinated whys).
- Native GitHub API calls — gh only, best-effort.
- History beyond the line range (no whole-file archaeology mode).
- Windows: the test suite passes on Windows (gh stubs run via .cmd wrappers); live use on Windows is not verified.
- Not tested here: live
gh pr viewon a#Nreference written in a commit message, live review quoting, and submodules. More detail in Live-tested vs fixture-driven.
Why this exists
Every developer, every week, stares at a weird block and asks why. The answer is scattered across blame, PRs, issues, and commit messages — assembling it by hand takes 20 minutes and usually gets skipped, so the weird code stays weird (or gets "fixed" and regresses).
gitstory assembles it for you: one command for a line range — blame + linked PRs/issues + commit messages, into a short narrative: who, when, why, what it replaced, what breaks if you touch it.
Full example
gitstory shortleash/cli.py 10-12
gitstory: shortleash/cli.py:10-12
SUMMARY:
First written by Calas Automations on 2026-10-15: initial commit
Last changed by Odin on 2026-10-19: v0.3.0: panel-approved improvements
2 commit(s) in this range's history. Original reason: subject line only, no extended message.
LINES (blame, -w -C):
10: 256b601 Odin 2026-10-19 — import json
11: fc33d73 Calas Automations 2026-10-15 — import os
12: fc33d73 Calas Automations 2026-10-15 — import signal
WHO WROTE IT, AND WHEN:
256b601 Odin 2026-10-19 (line(s) 10): v0.3.0: panel-approved improvements
fc33d73 Calas Automations 2026-10-15 (line(s) 11, 12): initial commit
WHY (from the commit messages — quoted, not reconstructed):
[256b601] v0.3.0: panel-approved improvements
- advisor: pre-run go/no-go (baseline + fleet pool, exit 0/3, audit log)
- loop fingerprinting: identical-args / error-retry / output-geyser tripwires (default on)
- cross-harness telemetry parsers: codex, opencode, gemini (+claude), auto-detect, --harness
- downgrade: graceful step-down at --downgrade-at of --budget, receipt-chained, budget-breach only
- fleet budget pools: single-host ledger, exit-2 refusal, atomic debit, fleet status
- sim: --loop mode, distinct task descriptions, --model/--resume flags
… (message truncated — full text in --json or --full)
[fc33d73] initial commit (no extended message — reason undocumented beyond the subject line)
WHAT IT REPLACED:
[256b601] these lines were added new — no prior version in this file (range history)
[fc33d73] these lines were added new — no prior version in this file (range history)
WHAT CHANGED SINCE FIRST APPEARANCE (kind labels are message-pattern inference, not fact):
256b601 Odin 2026-10-19 [change, classified by message pattern] [current form]: v0.3.0: panel-approved improvements
first appearance: fc33d73 Calas Automations 2026-10-15: initial commit
WHAT BREAKS IF YOU TOUCH IT:
- introducing commit(s) 256b601, fc33d73 also changed test file tests/test_cli.py [related by name to this file — evidence that tests exist alongside this code, not proof they cover these lines]
- introducing commit 256b601 also changed 6 other test file(s) (unrelated by name to this file — count only, not listed; full list in --json)
- introducing commit fc33d73 also changed 7 other test file(s) (unrelated by name to this file — count only, not listed; full list in --json)
- file shortleash/__main__.py imports this module [heuristic: git grep for import statements — evidence of coupling, not proof these lines are covered]
LINKED PRS / ISSUES:
none referenced in the commit messages.
Method: blame -w -C + line history + commit messages; deterministic template assembly, no LLM. INFERENCE is limited to message-pattern classification, labeled above.
The example above is real (one author name redacted): run against the shortleash repo on this machine (hashes 256b601, fc33d73 are that repo's actual commits).
Install (local)
python3 -m venv .venv
.venv/bin/pip install -e .
.venv/bin/gitstory <file> <line-range>
No dependencies beyond Python 3.10+ and git. No account, no network (except optional gh enrichment), no telemetry, no phone-home.
Usage
gitstory <file> <line-range> [--json] [--full] [--no-gh] [--blame-only] [--no-ignore-revs]
<line-range>:42for one line,42-58for a range. A range may span multiple commits; each line is attributed to its own introducing commit.gitstory a.py:40-58andgitstory a.py -L 40,58mean the same asgitstory a.py 40-58. Thefile:rangeform splits on the last colon followed by digits, soC:\repo\a.py:3is fileC:\repo\a.py, line 3.- Python symbols:
gitstory auth.py::loginorgitstory auth.py::Auth.loginresolves the function or class to its lines (decorators included) with Python'sast, from the working-tree file, and prints the resolved range first. Python only; a non-.pyfile or an unknown name exits 2. - The repo is found from the FILE's location, not the caller's cwd:
gitstory /other/repo/src.py 10from anywhere uses /other/repo. --json: structured evidence (blame entries, introducing commits, history, changes, breaks, references, agent trailers) instead of narrative text.--full: append the raw evidence dump (blame porcelain, line history, diffs) to the text narrative.--no-gh: skip gh PR/issue enrichment entirely.--blame-only: skipgit log -Lhistory (faster on long histories; narrative uses blame only, and says so).- Formatting commits: if
blame.ignoreRevsFileis configured, or the repo has a.git-blame-ignore-revsfile, blame skips the revisions listed there and SUMMARY says how many and from which file. This applies to blame (LINES, WHO WROTE IT); thegit log -Lhistory still lists those commits.--no-ignore-revsturns it off.
Exit codes: 0 narrative produced, 2 error (not a repo, file not tracked, bad range, range outside the file, git failure).
What the narrative contains
- Summary — first written / last changed / commit count / whether the original reason is documented, in three lines, before the evidence. The fast answer; the rest is the proof.
- Lines — blame for the range (
-wignores whitespace,-Cattributes lines moved from another file in the same commit to their origin; both labeled). - Who / when — per introducing commit: author, date, subject, short hash.
- Why — the commit message, quoted. A message of "fix stuff" with
no body yields "reason undocumented in history", not a reconstructed
story. Text output folds long bodies (first 6 lines + a pointer to
--json/--full); subjects cap at 120 chars in text only. Reason trailers in the message's last paragraph (Why:,Why-Rationale:,Why-Alternatives:,Reason:,Rationale:— the "git why" convention) are also quoted verbatim as[trailer Why] …, and the summary says "documented in trailer" when the first commit has one. - What it replaced — the removed lines from the range-scoped diff
of the introducing commit (or "added new" when there was no prior
version; capped at 20 lines in text, full diff in
--json/--full). Falls back to the commit's diff for the file, or for the path the code moved from, labeled as such. A previous filename equal to this file is normal continuation, NOT a move — only a different previous filename renders as "moved into this file from …". - What changed since first appearance — the line range's history,
newest first, from first appearance to now, with blame commits marked
[current form]. Kind labels are message-pattern inference, stated in the section header. - What breaks if you touch it — evidence only: later fix/revert
touches in the range's history (classified by message pattern,
labeled), test files changed in the introducing commits (related by
name listed individually and deduplicated across commits, the rest
collapsed to a count; full list in
--json), files that import this module (heuristicgit grepfor import statements, word-bounded soimport clinever matchesimport click; capped at 5 in text, full list in--json), and later touches mentioning breakage. If nothing in history says what breaks, it prints "unknown from history" — that absence is itself a finding. - Linked PRs / issues —
#Nandowner/repo#Nreferences parsed from commit messages. Whenghis available AND the repo has a remote, PR titles/states/URLs are fetched (PR first, then issue fallback); GitHub Enterprise hosts work viaGH_HOST. For a resolved PR, text output quotes the first 6 non-blank lines of the PR body ([PR #N body]) and up to 3 non-empty review bodies, each cut to 200 characters ([review by X]) — quoted verbatim, never paraphrased;--jsoncarries the full body and every review. An introducing commit whose message has no#Nis looked up withgh api repos/{owner}/{repo}/commits/{sha}/pulls; a PR found that way is labelled[found via commit->PR lookup for <sha>], and a failed or empty lookup prints an "unresolved" note, never a guessed link. These lookups go first and share the cap below. Enrichment is capped at 10 gh lookups (the rest shown unresolved with a note). When gh or the remote is absent, references are listed unresolved and the narrative says so — never a fabricated link.--no-ghdisables enrichment. - Agent-authorship note — only when commit metadata says so (e.g. a Co-Authored-By trailer naming an AI tool), quoted verbatim, with a count of trailer-carrying commits. Never guessed from code style.
Honesty contract (this IS the product's trust)
- NEVER invent a why. The narrative distinguishes EVIDENCE (commit message text, blame, diffs, PR titles) from INFERENCE, and inference is labeled and kept to message-pattern classification only.
- Every claim traces to a cited short hash.
- Subjects are first lines, not git's paragraph-collapsed
%s: a message with no blank line after the first line would otherwise collapse into one space-joined "subject" with an empty body. - Blame
previousis parent-commit bookkeeping, not move evidence: only a previous filename different from this file indicates a rename or copy origin. Lines copied from a file untouched in the copy commit attribute to the copy commit (verified: single-Cand-C -Cagree there) — git cannot see that copy, and the narrative does not pretend otherwise. - No LLM calls. LLM narration risks hallucinated whys and breaks the $0 contract — flagged for a later version, not built.
- No network calls except optional read-only
ghenrichment. - gitstory never writes to the repo. All git invocations are reads
(
blame,log -L,show,ls-files,rev-parse,remote,grep). - Non-UTF-8 or binary content renders with replacement characters, never a traceback.
Live-tested vs fixture-driven
- Live-tested: the example above (real shortleash history, real
blame ranges, real multi-commit ranges); a single-commit repo
(adr-drift) end-to-end; a venv install check (
gitstory --version→ 0.2.0, real CLI run from the installed entry point); a never-modifies-the-repo check (git statusclean before and after). - Fixture-driven: empty-history files, uncommitted changes in
range, ranges spanning a rename, single lines, files not in git,
moved code (blame
-Cattribution + diff fallback), PR references with gh present (stubghbinary in PATH) and absent, AI trailers, fix/revert classification,--jsonstructure, exit codes, non-UTF-8 files, merge commits (--first-parentfile lists), Enterprise remotes (GH_HOST), the 10-reference enrichment cap, importer word boundaries, repo-from-file resolution. - Live gh, once: on 2026-11-07, on Windows,
gitstory pre_commit_hooks/check_case_conflict.py:72 --blame-onlyin a clone of pre-commit/pre-commit-hooks found PR #677 (MERGED) via the commit->PR lookup and quoted its body. That is one run of one path. - Not tested here: live
gh pr viewon a#Nreference written in a commit message, and live review quoting (the stub path proves the mechanics). Also: submodules.
What's new in v0.2.0
- SUMMARY lead: first written / last changed / commit count / reason documented, in three lines before the evidence.
- Text output stays SHORT: WHY bodies fold after 6 lines, subjects
cap at 120 chars, replaced lines cap at 20 — full text always in
--json/--full. - Breaks section strengthened: related test files deduplicated across
commits, and importer evidence (
git grep, word-bounded) added. - Two honesty bugs fixed, both caught live: (1) blame
previousmisread as move evidence — a plain added import rendered as a "move"; now only a different previous filename counts. (2) git's%scollapses no-blank-line messages into one space-joined subject with an empty body; gitstory now splits raw messages on the first line itself. - Robustness: non-UTF-8/binary content renders instead of
trace-backing;
-Lhistory parser tolerates empty diffs and missing blank lines instead of silently dropping records; merge commits list files via--first-parent. - Usability: repo found from the file's location (not the cwd);
--blame-onlyskips slow-Lhistory; Enterprise remotes viaGH_HOST; gh enrichment capped at 10 references; timeout errors suggest a smaller range or--blame-only. -C -Ctested and NOT adopted: identical attribution to-Con move-with-delete and pure-copy fixtures, at higher cost.
Changes: CHANGELOG.md. Panel review notes: REVIEW.md. License: MIT, see LICENSE.
Made by Calas Automations (CAL-us). Need help? Call Cara 431-244-9026.
Metadata
Release files for gitstory-cli 0.2.2
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 |
|---|---|---|---|---|
| gitstory_cli-0.2.2.tar.gz | 45.6 kB | Without provenance | Details for gitstory_cli-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gitstory_cli-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for gitstory_cli-0.2.2-py3-none-any.whl |
Total release size: 76.1 kB
Release files / gitstory_cli-0.2.2.tar.gz
| Download URL | gitstory_cli-0.2.2.tar.gz |
|---|---|
| Size | 45.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f542db2454b604d45867478ec07e79ba414ba4d514f4fb952ea9dbf0a568bb72
|
|
BLAKE2b-256 checksum How to use checksums |
d0692f49d937385c4d0bdd637f29fcbd2f182f446994bf4ab37d84778abc5432
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / gitstory_cli-0.2.2-py3-none-any.whl
| Download URL | gitstory_cli-0.2.2-py3-none-any.whl |
|---|---|
| Size | 30.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a2d5f8fcc6462b14c9584ba0ad46b196a361e5ae92ace9804270b46d907db326
|
|
BLAKE2b-256 checksum How to use checksums |
457511d443e04bf75d275bc0e331138ff669f9a76c6f9b791e005a5febd2a0c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Security for gitstory-cli 0.2.2
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.