pr-loc-breakdown
Skill9 starsChanged 5 months agoMITView on GitHub
Break down pure-Python lines-of-code changes per file for a PR (or two git refs), excluding non-.py files, blank lines, comments, and docstrings. Uses an AST/tokenize-based programmatic counter — never hand-counted. Input format: "<PR_NUMBER>" (e.g. "277") or "<BASE_REF> <HEAD_REF>".
In this repository18 other files it gives its agents.
- backend/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/adhoc.mdcCursor rule
- .cursor/rules/agents.mdcCursor rule
- .cursor/rules/ai-engineering.mdcCursor rule
- .cursor/rules/backend-python.mdcCursor rule
- .cursor/rules/code-analysis.mdcCursor rule
- .cursor/rules/coding.mdcCursor rule
- .cursor/rules/guardrails.mdcCursor rule
- .cursor/rules/help.mdcCursor rule
- .cursor/rules/questions.mdcCursor rule
- backend-quality-gateSkill
- creating-commitsSkill
- deploy-requirementsSkill
- gain-backportSkill
- pr-descSkill
- release-notesSkill
- specflow-usability-checkSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 38
Run the bundled script from the repo root:
- Very specific: line 43
Add --json for a machine-readable blob in addition to the table.
- Distinctive: line 46
If the user asked only for additions (or only a subset), filter the reported rows accordingly — do not re-count by hand.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
PR Pure-Python LOC Breakdown
Produce an accurate per-file breakdown of pure Python code added/removed in a
PR. "Pure" means only executable Python: it excludes markdown/docs/other
non-.py files, blank lines, whole-line comments, inline comments, and
docstrings (module / class / function string-literal statements).
Why a script (not eyeballing the diff)
git diff --stat counts every changed line including blanks, comments, and
docstrings, so it overstates code churn. Counting by reading the diff by hand is
error-prone and not reproducible. This skill ships count_py_loc.py, which:
- Resolves the base & head SHAs (via
ghfor a PR number, orgit merge-basefor two refs — so churn that arrived frommainmoving forward is excluded). - Lists changed
.pyfiles withgit diff --name-only <base> <head> -- '*.py'. - Reconstructs each file's base and head content (
git show <ref>:<path>). - Strips comments + docstrings + blank lines from each version using Python's
ast(docstring line ranges) andtokenize(whole-line comments). - Diffs the two cleaned versions with
difflib.unified_diff(n=0)and counts+/-lines → real added/removed pure-code lines per file.
Because it diffs cleaned files, multi-line docstrings, reformatting, and comment churn never inflate the numbers.
Steps
- Parse
$ARGUMENTS:- One integer (e.g.
277or#277) → PR mode (resolves refs viagh). - Two refs (e.g.
main feature-branch) → ref mode. - Empty → defaults to
merge-base(main, HEAD)..HEAD.
- One integer (e.g.
- Run the bundled script from the repo root:
(usepython3 .claude/skills/pr-loc-breakdown/count_py_loc.py $ARGUMENTSpython3;pythonmay not be on PATH) Add--jsonfor a machine-readable blob in addition to the table. - Present the table to the user. Lead with the total pure-Python added/removed, then the per-file rows (already sorted by churn, largest first).
- If the user asked only for additions (or only a subset), filter the reported rows accordingly — do not re-count by hand.
Notes
- Requires
ghonly in PR mode; ref mode and the default usegitalone. - The script self-heals on unparseable revisions: if a file version doesn't parse (partial/invalid Python at that SHA), it falls back to a blank+comment line filter and still strips full-line comments and blanks.
- Renames are counted as the diff between the old path's base content and the new path's head content as Git reports them; pure-rename-only files show 0/0 and are omitted.
- To reuse for non-PR comparisons (e.g. a tag range), pass two refs directly.
Output Format
# Pure-Python LOC breakdown — PR #277
# base <sha> -> head <sha>
FILE +add -del net
------------------------------------ ------ ------ ------
backend/app/services/foo.py 120 14 +106
mcp_server/server.py 88 30 +58
...
------------------------------------ ------ ------ ------
TOTAL 512 110 +402
# N python file(s) with pure-code changesDoes it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

