Skip to main content

Count lines of code from GitHub pull requests

Project description

trueloc - Lines of Code Counter

PyPI Python License Downloads CI Docs

trueloc Logo

A CLI tool to analyze your coding activity via GitHub pull requests and direct commits:

  • Total lines written since any date
  • Per-PR and per-commit breakdown showing when each contribution was made
  • File type analysis revealing which languages you've worked with most

Counts ALL lines touched across every commit in a PRโ€”even for squash merges where GitHub only shows the final diff. For example, a PR where you add 1000 lines, delete them, then add 1 line shows +1001 / -1000 (not just +1).

Installation

Recommended (installs in isolated environment):

uv tool install trueloc

Or run directly without installing:

uvx trueloc count USERNAME --since 1m

Alternatively, with pip:

pip install trueloc

Requires the GitHub CLI (gh) to be installed and authenticated:

gh auth login

Usage

# Count lines from PRs and direct commits since a date
trueloc count USERNAME --since 2023-01-01

# Use relative dates
trueloc count USERNAME --since 5d      # 5 days ago
trueloc count USERNAME --since 2w      # 2 weeks ago
trueloc count USERNAME --since 3m      # 3 months ago
trueloc count USERNAME --since 1y      # 1 year ago
trueloc count USERNAME --since "last month"

# Specify a date range
trueloc count USERNAME --since 2024-01-01 --until 2024-06-30

# Count only net diff (not per-commit)
trueloc count USERNAME --since 2023-01-01 --net

# Exclude direct commits (PRs only)
trueloc count USERNAME --since 2023-01-01 --no-direct-commits

# Hide file extension breakdown
trueloc count USERNAME --since 2023-01-01 --no-extensions

# Disable caching (fresh API calls)
trueloc count USERNAME --since 2023-01-01 --no-cache

# Output as JSON for scripting/postprocessing
trueloc count USERNAME --since 2023-01-01 --json

# Clear the cache
trueloc clear-cache

CLI Reference

Main Commands

echo '```'
trueloc --help
echo '```'
                                                                                
 Usage: trueloc [OPTIONS] COMMAND [ARGS]...                                     
                                                                                
 Count lines of code from GitHub pull requests.

โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ --install-completion            Install completion for the current shell.    โ”‚
โ”‚ --show-completion               Show completion for the current shell, to    โ”‚
โ”‚                                 copy it or customize the installation.       โ”‚
โ”‚ --help                -h        Show this message and exit.                  โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
โ•ญโ”€ Commands โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ count         Count lines of code from merged PRs and direct commits.        โ”‚
โ”‚ clear-cache   Clear the disk cache.                                          โ”‚
โ”‚ count-local   Count lines of code from a local git repository.               โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Count Command Options

echo '```'
trueloc count --help
echo '```'
                                                                                
 Usage: trueloc count [OPTIONS] USERNAME                                        
                                                                                
 Count lines of code from merged PRs and direct commits.

 By default, counts all lines touched across all commits in each PR,
 plus direct commits to the main branch (not from PRs).

 Example: a single PR where you add 1000 lines, delete them, then add
 1 line = +1001 / -1000 (even though the PR's net diff shows only +1).
 Additions and deletions are summed separately across all commits.

 Use --net to count only the final diff (net additions/deletions).
 Use --no-direct-commits to exclude direct commits to main branch.

โ•ญโ”€ Arguments โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ *    username      TEXT  GitHub username [required]                          โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
โ•ญโ”€ Options โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ *  --since           -s                         TEXT  Start date (e.g., 5d,  โ”‚
โ”‚                                                       2w, 3m, 1y, 'last      โ”‚
โ”‚                                                       month', 2024-01-01)    โ”‚
โ”‚                                                       [required]             โ”‚
โ”‚    --until           -u                         TEXT  End date (e.g., 1d,    โ”‚
โ”‚                                                       'yesterday',           โ”‚
โ”‚                                                       2024-12-31)            โ”‚
โ”‚    --no-cache                                         Disable disk cache     โ”‚
โ”‚    --extensions          --no-extensions              Show breakdown by file โ”‚
โ”‚                                                       extension              โ”‚
โ”‚                                                       [default: extensions]  โ”‚
โ”‚    --per-commit          --net                        Count all lines        โ”‚
โ”‚                                                       touched per commit     โ”‚
โ”‚                                                       (default) vs net diff  โ”‚
โ”‚                                                       only                   โ”‚
โ”‚                                                       [default: per-commit]  โ”‚
โ”‚    --direct-commits      --no-direct-commits          Include direct commits โ”‚
โ”‚                                                       to main branch (not    โ”‚
โ”‚                                                       from PRs)              โ”‚
โ”‚                                                       [default:              โ”‚
โ”‚                                                       direct-commits]        โ”‚
โ”‚    --json                                             Output results as JSON โ”‚
โ”‚                                                       for scripting          โ”‚
โ”‚    --repo            -r                         TEXT  Only process a single  โ”‚
โ”‚                                                       repository (e.g.,      โ”‚
โ”‚                                                       'owner/repo' or        โ”‚
โ”‚                                                       'repo')                โ”‚
โ”‚    --help            -h                               Show this message and  โ”‚
โ”‚                                                       exit.                  โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Features

  • Per-commit counting (default): Counts every line touched in every commit
  • Net diff mode: Alternative mode that only counts final diff (--net)
  • Direct commits: Includes commits pushed directly to main (not via PR)
  • File extension breakdown: Shows which languages you've worked with
  • JSON output: Machine-readable output for scripting (--json)
  • Disk caching: Uses diskcache to avoid hammering the GitHub API
  • Rate limit handling: Automatically waits when rate limited with progress bar
  • Flexible dates: Supports relative (5d, 2w, 3m, 1y) and natural language (last month)

Caching Strategy

  • Immutable data (cached forever): commit stats, PR commits, PR files
  • Mutable data (1 day TTL): user repos, merged PR lists

Cache is stored in ~/.cache/trueloc/.

Tech Stack

Development

# Install dev dependencies
uv sync --group dev

# Run tests
pytest

# Run linting
ruff check .
ruff format .
mypy .

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trueloc-0.3.0.tar.gz (75.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trueloc-0.3.0-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file trueloc-0.3.0.tar.gz.

File metadata

  • Download URL: trueloc-0.3.0.tar.gz
  • Upload date:
  • Size: 75.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for trueloc-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a35666529467721f0557768dd28c427e00fc3a1d0cdbee1ce465647981822dfa
MD5 68ca3e2c2c62f99d0a928b6c51a2c5fd
BLAKE2b-256 44439f66c650f0a8b7e58b530160f804cd82e4b407b754b19dd33c4e3d5942b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for trueloc-0.3.0.tar.gz:

Publisher: release.yml on basnijholt/trueloc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trueloc-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: trueloc-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for trueloc-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 29ed1ea9ce4c5a622efd2a5e6d4e28d118376f056860090d4ee4467152674a96
MD5 eb9f5c8823ad490080b61c42553abcd7
BLAKE2b-256 36bf0685ee3a6cc160cf78eb7b55e75bfd4a1bfe4adfa1cffd47914d9075242a

See more details on using hashes here.

Provenance

The following attestation bundles were made for trueloc-0.3.0-py3-none-any.whl:

Publisher: release.yml on basnijholt/trueloc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page