Inspect a Codebase with pygount

Analyze repositories for lines of code, language breakdown, file counts, and code-vs-comment ratios using pygount.

Hermes OpenClaw Intermediate Copied: 0
1 resource

Requirements

  • Requires the pygount command to be available.

How to use

Use this when the user asks for a lines-of-code count.

Use this when the user wants a language breakdown of a repository.

Use this when the user asks about codebase size or composition.

Use this when the user wants code-vs-comment ratios.

Use this for general questions about how big a repository is.

First, install pygount on the system.

pip install --break-system-packages pygount 2>/dev/null || pip install pygount

Run the basic summary from the repository root to 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 and build directories, otherwise pygount will crawl them and take a very long time or hang.

Adjust the common folder exclusions based on the project type.

Separate skip lists are shown for Python projects, JavaScript/TypeScript projects, and a general catch-all.

# Python projects
--folders-to-skip=".git,venv,.venv,__pycache__,.cache,dist,build,.tox,.eggs,.mypy_cache"

# JavaScript/TypeScript projects
--folders-to-skip=".git,node_modules,dist,build,.next,.cache,.turbo,coverage"

# General catch-all
--folders-to-skip=".git,node_modules,venv,.venv,__pycache__,.cache,dist,build,.next,.tox,vendor,third_party"

Filter the analysis by specific languages when you only want certain file types counted.

# Only count Python files
pygount --suffix=py --format=summary .

# Only count Python and YAML
pygount --suffix=py,yaml,yml --format=summary .

Use the default format for a detailed file-by-file breakdown, and pipe through sort to order files by code lines.

# Default format shows per-file breakdown
pygount --folders-to-skip=".git,node_modules,venv" .

# Sort by code lines (pipe through sort)
pygount --folders-to-skip=".git,node_modules,venv" . | sort -t$'\t' -k1 -nr | head -20

Choose an output format: a summary table, JSON for programmatic use, or pipe-friendly output.

# Summary table (default recommendation)
pygount --format=summary .

# JSON output for programmatic use
pygount --format=json .

# Pipe-friendly: Language, file count, code, docs, empty, string
pygount --format=summary . 2>/dev/null

Always exclude .git, node_modules, and venv: without --folders-to-skip, pygount will crawl everything and may take minutes or hang on large dependency trees.

Markdown shows 0 code lines because pygount classifies all Markdown content as comments, not code; this is expected behavior.

JSON files show low code counts because pygount may count JSON lines conservatively; for accurate JSON line counts, use wc -l directly.

For very large monorepos, consider using --suffix to target specific languages rather than scanning everything.

Source: nousresearch/hermes-agent and its contributors. License: MIT.

Copyright (c) 2025 Nous Research

Translation and editorial adaptation by ClawCases.

>Resources

>Related Use Cases

>More at this level: Intermediate