| name | codebase-inspection |
| description | Inspect codebases w/ pygount: LOC, languages, ratios. Also: remote GitHub repo analysis via gh CLI API. |
| version | 1.1.0 |
| author | Hermes Agent |
| license | MIT |
| metadata | {"hermes":{"tags":["LOC","Code Analysis","pygount","Codebase","Metrics","Repository","GitHub","Deep Analysis","Repo Review"],"related_skills":["github-repo-management"]}} |
| triggers | ["分析这个仓库","深度分析","repo analysis","what is this repo","代码行数","LOC","language breakdown","代码分析"] |
| prerequisites | {"commands":["pygount"]} |
Codebase Inspection with pygount
Analyze repositories for lines of code, language breakdown, file counts, and code-vs-comment ratios using pygount.
When to Use
- User asks for LOC (lines of code) count
- User wants a language breakdown of a repo
- User asks about codebase size or composition
- User wants code-vs-comment ratios
- General "how big is this repo" questions
Prerequisites
pip install --break-system-packages pygount 2>/dev/null || pip install pygount
1. Basic Summary (Most Common)
Get a full language breakdown with file counts, code lines, and comment lines:
cd /path/to/repo
pygount --format=summary \
--folders-to-skip=".git,node_modules,venv,.venv,__pycache__,.cache,dist,build,.next,.tox,.eggs,*.egg-info" \
.
IMPORTANT: Always use --folders-to-skip to exclude dependency/build directories, otherwise pygount will crawl them and take a very long time or hang.
2. Common Folder Exclusions
Adjust based on the project type:
--folders-to-skip=".git,venv,.venv,__pycache__,.cache,dist,build,.tox,.eggs,.mypy_cache"
--folders-to-skip=".git,node_modules,dist,build,.next,.cache,.turbo,coverage"
--folders-to-skip=".git,node_modules,venv,.venv,__pycache__,.cache,dist,build,.next,.tox,vendor,third_party"
3. Filter by Specific Language
pygount --suffix=py --format=summary .
pygount --suffix=py,yaml,yml --format=summary .
4. Detailed File-by-File Output
pygount --folders-to-skip=".git,node_modules,venv" .
pygount --folders-to-skip=".git,node_modules,venv" . | sort -t$'\t' -k1 -nr | head -20
5. Output Formats
pygount --format=summary .
pygount --format=json .
pygount --format=summary . 2>/dev/null
6. Interpreting Results
The summary table columns:
- Language — detected programming language
- Files — number of files of that language
- Code — lines of actual code (executable/declarative)
- Comment — lines that are comments or documentation
- % — percentage of total
Special pseudo-languages:
__empty__ — empty files
__binary__ — binary files (images, compiled, etc.)
__generated__ — auto-generated files (detected heuristically)
__duplicate__ — files with identical content
__unknown__ — unrecognized file types
7. Remote GitHub Repo Analysis (no clone needed)
Use gh api to inspect a repo without cloning it — useful for quick assessment, comparison, or deciding whether to invest time in a deeper look.
gh repo view owner/repo --json name,description,stargazerCount,forkCount,primaryLanguage,createdAt,updatedAt,licenseInfo,homepageUrl
gh api repos/owner/repo/contents --jq '.[] | {name, type, size}'
gh api repos/owner/repo/contents/path/to/dir --jq '.[] | {name, type, size}'
gh api repos/owner/repo/contents/README.md --jq '.content' | base64 -d
gh api repos/owner/repo/contents/path/to/file.md --jq '.content' | base64 -d | head -100
gh api repos/owner/repo/contents/src --jq '[.[] | .name | split(".")[-1]] | group_by(.) | map({ext: .[0], count: length})'
gh api repos/owner/repo/contributors --jq '.[] | {login, contributions}'
gh api repos/owner/repo/commits --jq '.[] | {sha: .sha[:8], message: .commit.message[:80], date: .commit.author.date}'
Deep Analysis Pattern (for user reports)
When the user asks to "deeply analyze" a GitHub repo:
- Overview:
gh repo view for metadata (stars, forks, language, license, dates)
- Structure:
gh api repos/.../contents for top-level directory layout
- README: Read README.md for project purpose and usage
- Key files: Read package.json, setup.py, Cargo.toml, or equivalent for dependencies/tech stack
- Scripts/CI: Check
.github/workflows/, scripts/, Makefile for build/test patterns
- Specific deep dives: Read representative source files from key directories
Report format: Overview → Architecture → Tech Stack → Key Features → Strengths/Weaknesses → Comparison (if relevant).
Pitfalls
- Always exclude .git, node_modules, venv — without
--folders-to-skip, pygount will crawl everything and may take minutes or hang on large dependency trees.
- Markdown shows 0 code lines — pygount classifies all Markdown content as comments, not code. This is expected behavior.
- JSON files show low code counts — pygount may count JSON lines conservatively. For accurate JSON line counts, use
wc -l directly.
- Large monorepos — for very large repos, consider using
--suffix to target specific languages rather than scanning everything.