rloc
A blazingly fast line-of-code counter written in Rust. Full-featured cloc replacement.
Quick Start
# Count lines in current directory
# Count lines in specific paths
# Output as JSON
# Show per-file breakdown
# Compare two directories
Example Output

Installation
From source
# Binary is at ./target/release/rloc
Cargo
Library Usage
rloc can also be used as a library in your Rust projects:
[]
= { = "0.1", = false }
Examples
use Path;
// Get the top language in a directory (by lines of code)
let top = top_language.unwrap;
println!;
// Fast mode: only count files by extension (no file reads)
let top_fast = top_language_fast.unwrap;
println!;
// Full analysis with all languages
let analysis = analyze.unwrap;
for lang in &analysis.languages
// Detect language for a single file
if let Some = detect_language
Configurable Analysis
use AnalyzeConfig;
let config = new
.include_langs
.exclude_dirs
.max_depth;
let analysis = analyze_with_config.unwrap;
Why rloc?
- Fast: Parallel processing with rayon. Typically 100-125x faster than cloc.
- Accurate: Language-aware comment parsing handles nested comments, string literals, and edge cases.
- Full-featured: Diff mode, archive support, custom languages, duplicate detection - everything cloc has.
- Modern defaults: Respects
.gitignoreand excludes common non-source directories by default. - Multiple output formats: Table, JSON, CSV, YAML, Markdown, SQL, and XML.
- Single binary: No runtime dependencies. Easy to install and distribute.
Performance
Benchmark on a large mixed-language monorepo (~40k files, ~6M lines of code):
| Tool | Time | Files/s | Lines/s | Speedup |
|---|---|---|---|---|
| rloc | 3.2s | 15,333 | 2,498,635 | 125x |
| cloc | 398s | 97 | 18,427 | 1x |
rloc achieves this through parallel file processing and efficient I/O.
Output Formats
Or use shorthand flags: --json, --csv, --yaml, --md, --sql, --xml
Filtering
By language
By extension
By file content
By path pattern
By directory
By file size
Advanced Features
Diff Mode
Compare two sets of files to see what changed:
Output shows lines of code that are same, modified, added, or removed:
Language Same Modified Added Removed
──────────────────────────────────────────────────────────
Rust 1500 200 150 50
JavaScript 800 50 25 10
──────────────────────────────────────────────────────────
SUM 2300 250 175 60
Archive Support
Process files inside archives without extracting manually:
Supports: .zip, .tar, .tar.gz, .tgz
Custom Language Definitions
Define new languages or override built-in definitions with YAML:
# custom_langs.yaml
MyLang:
extensions:
line_comments:
block_comment_start: "/*"
block_comment_end: "*/"
nested_comments: false
DSL:
extensions:
line_comments:
Force Language Detection
Treat files with specific extensions as a different language:
Duplicate Detection
By default, rloc detects and skips duplicate files (by content hash):
Strip Comments
Extract code or comments from source files:
Read File List
Process a predefined list of files:
Combine Reports
Merge multiple JSON reports:
Aggregate Small Results
Group languages with few files into "Other":
Percentage Output
Show percentages instead of absolute counts:
Git Integration
Options Reference
| Option | Description |
|---|---|
--by-file |
Report results for every source file |
--by-file-by-lang |
Group per-file results by language |
--format <FMT> |
Output format: table, json, csv, yaml, md, sql, xml |
--sort <FIELD> |
Sort by: language, files, code, comments, blanks, total |
--diff <PATH> |
Compare against another directory |
--exclude-dir <DIR> |
Exclude directories by name |
--exclude-ext <EXT> |
Exclude files by extension |
--exclude-lang <LANG> |
Exclude languages |
--include-ext <EXT> |
Only count files with these extensions |
--include-lang <LANG> |
Only count these languages |
--include-content <RE> |
Only count files matching content regex |
--exclude-content <RE> |
Exclude files matching content regex |
--match-f <REGEX> |
Only count files matching regex |
--not-match-f <REGEX> |
Exclude files matching regex |
--match-d <REGEX> |
Only count in directories matching regex |
--not-match-d <REGEX> |
Exclude directories matching regex |
--fullpath |
Use full path for regex matching |
--force-lang <L,E> |
Treat extension E as language L |
--read-lang-def <FILE> |
Load custom language definitions |
--list-file <FILE> |
Read file paths from file |
--extract-archives |
Process zip/tar/tar.gz files |
--follow-symlinks |
Follow symbolic links |
--hidden |
Include hidden files and directories |
--no-ignore |
Disable default directory exclusions |
--skip-gitignore |
Don't respect .gitignore files |
--skip-uniqueness |
Don't skip duplicate files |
--max-depth <N> |
Maximum directory depth |
--no-recurse |
Don't recurse into subdirectories |
--max-file-size <MB> |
Skip files larger than N megabytes |
--csv-delimiter <C> |
Custom CSV delimiter |
--summary-cutoff <N> |
Aggregate languages with <N files |
--sum-reports <FILE> |
Combine JSON report files |
--strip-comments <EXT> |
Write code-only files with extension |
--strip-code <EXT> |
Write comment-only files with extension |
--show-total |
Add column with total lines |
--by-percent |
Show percentages instead of counts |
--hide-rate |
Don't show processing rate |
--quiet |
Suppress progress output |
--out <FILE> |
Write output to file |
--threads <N> |
Number of threads (0 = auto) |
--show-lang |
List all supported languages |
--show-ext |
List all recognized file extensions |
Supported Languages
rloc recognizes 100+ programming languages including:
Ada, Aria, Assembly, AXAML, Bash, Bicep, BitBake, C, C#, C++, Clarity, Clojure, COBOL, CoffeeScript, Crystal, CSS, D, Dart, Elixir, Elm, Erlang, F#, Forth, Fortran, Go, GraphQL, Groovy, Haskell, HCL, HTML, Java, JavaScript, JSON, Julia, Kotlin, Less, Lisp, Lua, Magik, Makefile, Markdown, MATLAB, Nim, Nix, Objective-C, OCaml, Odin, Pascal, Perl, PHP, PowerShell, Prolog, Protocol Buffers, Python, R, Rego, Ruby, Rust, Sass, Scala, Scheme, Shell, SQL, Swift, Tcl, Terraform, TOML, TypeScript, USS, UXML, V, Verilog, VHDL, Vim Script, VSCode Workspace, Vue, XML, YAML, Yarn, Zig, and many more.
Run rloc --show-lang for the complete list with comment syntax.
Default Exclusions
By default, rloc excludes common non-source directories:
.git, .hg, .svn, node_modules, target, vendor, dist, build, __pycache__, .venv, venv, .tox, .env
Use --no-ignore to disable these exclusions.
Feature Comparison with cloc
| Feature | rloc | cloc |
|---|---|---|
| Speed | ~125x faster | Baseline |
| Parallel processing | Yes | No |
| Respects .gitignore | Yes (default) | No |
| Default exclusions | Yes | No |
| Duplicate detection | Yes | Yes |
| Archive support | Yes | Yes |
| Diff mode | Yes | Yes |
| Custom language defs | Yes | Yes |
| Strip comments/code | Yes | Yes |
| Content filtering | Yes | No |
| Git submodules | Yes | Yes |
| Sum reports | Yes | Yes |
How It Works
- Walk: Traverse directories using the ignore crate, respecting
.gitignorepatterns. - Detect: Identify language by file extension or special filenames (e.g.,
Makefile,Dockerfile). - Parse: Process each file with a state machine that tracks:
- Whether we're inside a string literal
- Whether we're inside a block comment (including nesting for languages that support it)
- Line comment prefixes
- Classify: Each line is classified as blank, comment, or code.
- Aggregate: Results are collected in parallel and merged by language.
License
MIT License. See LICENSE for details.