monthly-loc
v1.1.0
Published
CLI tool to fetch and aggregate monthly lines of code contributions from GitHub
Maintainers
Readme
monthly-loc
A CLI tool to fetch and aggregate monthly lines of code (additions/deletions) contributed by a user across all their GitHub repositories.
Features
- 📊 Track additions, deletions, and net lines of code
- 📅 Support for single month or multi-month ranges (last 12 months, etc.)
- 🏢 Works across personal repos AND organization repos
- 🚫 Exclude specific repositories
- 📁 Multiple output formats: table, JSON, CSV
- ⚡ Optimized API usage with GitHub's commit search
Installation
npm install -g monthly-locOr run directly with npx:
npx monthly-loc --months 3Setup
Create a GitHub Personal Access Token with repo and read:user scopes:
- Go to https://github.com/settings/tokens
- Click "Generate new token (classic)"
- Select scopes:
repoandread:user - Copy the token
Set it as an environment variable:
export GITHUB_TOKEN="ghp_your_token_here"Usage
# Current month stats
monthly-loc
# Last 3 months
monthly-loc --months 3
# Last 12 months (full year)
monthly-loc --months 12
# Specific month
monthly-loc --month 2025-06
# Exclude specific repos
monthly-loc --exclude "test-repo,sandbox"
# Output as JSON
monthly-loc --months 6 --output json
# Output as CSV
monthly-loc --output csv > contributions.csv
# Check another user's public contributions
monthly-loc --user octocat --months 3
# Include forked repositories
monthly-loc --include-forks
# Only count specific file types (e.g., only code files)
monthly-loc --include-files "*.ts,*.js,*.tsx,*.jsx"
# Only count Python files
monthly-loc --include-files "*.py"
# Exclude specific file types from line count
monthly-loc --exclude-files "*.md,package-lock.json"
# Combine both: only JS/TS but exclude tests
monthly-loc --include-files "*.ts,*.js" --exclude-files "*.test.ts,*.spec.js"
# Show individual file stats for each repo
monthly-loc --show-files
# Combine with other flags
monthly-loc --months 3 --show-files --include-files "*.ts,*.js"Options
| Option | Description | Default |
| -------------------- | ---------------------------------------------------- | ------------- |
| -u, --user | GitHub username to fetch contributions for | Token owner |
| -e, --exclude | Comma-separated list of repository names to skip | None |
| -f, --exclude-file | Path to file with repos to exclude (one per line) | None |
| -m, --month | Target month in YYYY-MM format | Current month |
| -n, --months | Fetch last N months (e.g., 12 for full year) | 1 |
| -o, --output | Output format: json, csv, table | table |
| --include-files | Only count files matching these patterns | All files |
| --exclude-files | Exclude files matching these patterns | None |
| --show-files | Show individual file stats for each repo | false |
| --include-forks | Include forked repositories | false |
Sample Output
Table Format (Multi-Month)
GitHub Contributions - 2025-10 to 2025-12
User: akulsr0
================================================================================
📅 MONTHLY BREAKDOWN
--------------------------------------------------------------------------------
Month Commits Additions Deletions Net Lines
--------------------------------------------------------------------------------
Oct 2025 6 +2,085 -53 +2,032
Nov 2025 33 +63,297 -3,337 +59,960
Dec 2025 5 +621 -201 +420
--------------------------------------------------------------------------------
TOTAL 44 +66,003 -3,591 +62,412
📦 BY REPOSITORY
--------------------------------------------------------------------------------
Repository Commits Additions Deletions Net Lines
--------------------------------------------------------------------------------
repo-1 24 +58,241 -3,464 +54,777
bazaar 17 +7,745 -123 +7,622
repo-2 2 +8 -1 +7
--------------------------------------------------------------------------------
TOTAL 44 +66,003 -3,591 +62,412
📊 3 months | 4 repos with activity | 44 commitsJSON Format
monthly-loc --months 3 --output json{
"period": "2025-10 to 2025-12",
"user": "akulsr0",
"summary": {
"total_additions": 66003,
"total_deletions": 3591,
"net_lines": 62412,
"repos_with_activity": 4,
"commits": 44,
"months_analyzed": 3
},
"monthly_breakdown": [...],
"repositories": [...]
}Exclude File Format
Create a text file with one repository name per line:
# repos-to-exclude.txt
old-archive
test-sandbox
experimental-stuffThen use it:
monthly-loc --exclude-file repos-to-exclude.txtRequirements
- Node.js 18.0.0 or higher
- GitHub Personal Access Token
License
MIT © Akul Srivastava
