Count blank, comment, and code lines across files, directories, archives, and git revisions.
$brew install cloc
Agent Compatibility
JSON Output
Agent Skill
MCP Support
AI Analysis
cloc is a source code line counter for files, directories, archives, and git revisions. It reports blank, comment, and code lines by language and can also diff two snapshots of a codebase.
What It Enables
- Measure language mix and code volume across a repo, directory tree, archive, or checked-out project.
- Compare two commits, branches, directories, or archives to see how blank, comment, and code counts changed.
- Generate per-file, JSON, XML, YAML, or SQL reports for audits, trend tracking, or downstream analysis.
Agent Fit
- Non-interactive flags, deterministic report modes, and support for file lists or VCS-backed inputs make it easy to drop into scripts and CI checks.
- JSON output is real and easy to parse, and
--by-file,--diff, and--vcs gitexpose useful inspection surfaces for repo analysis loops. - It is inspection-only: useful for audits, sizing, and change analysis, but it does not modify repos or understand code semantics beyond comment heuristics.
Caveats
- Counts are heuristic rather than parser-based, so embedded languages, comment markers inside strings, and docstrings can skew results.
- Some archive and VCS workflows depend on external tools like
git,rpm2cpio, ordpkg-debbeing available.