Skip to content

loc

The loc command scans a directory tree, detects built-in languages, and reports:

  • code lines
  • comment lines
  • empty lines
  • size in bytes

The default output is a terminal table with per-language rows, totals, and elapsed time.

Use --path for local analysis or --url to clone and analyze a remote repository directly.

Terminal window
sephera loc --path . # count every language in this tree
sephera loc --path crates/sephera_core --format markdown # one crate, as a pastable report
sephera loc --path . --format json # the same counts, machine-readable

Run from inside the repository you want to measure.

--format selects the rendering, and --output writes it to a file instead of standard output:

Terminal window
sephera loc --path . --format json --output reports/loc.json
sephera loc --path . --format csv
sephera loc --path . --format markdown
formatfor
tablea terminal; the default
jsona dashboard or a script, with elapsed time included
csva spreadsheet
markdownpasting into a pull request

CSV quotes every language label unconditionally. No built-in language name contains a comma today, but a label chosen outside the tool that silently produces a wrong column count the first time it changes is worse than one that is always right.

Terminal window
sephera loc --path .

Analyze a remote repository directly:

Terminal window
sephera loc --url https://github.com/Reim-developer/Sephera

Analyze a repository tree URL:

Terminal window
sephera loc --url https://github.com/Reim-developer/Sephera/tree/master/crates
Scanning: crates
╭──────────┬───────┬─────────┬───────┬──────────────╮
│ Language ┆ Code ┆ Comment ┆ Empty ┆ Size (bytes) │
╞══════════╪═══════╪═════════╪═══════╪══════════════╡
│ Rust ┆ 28897 ┆ 7818 ┆ 4437 ┆ 1448814 │
│ TOML ┆ 533 ┆ 28 ┆ 70 ┆ 21184 │
│ Markdown ┆ 380 ┆ 0 ┆ 159 ┆ 20564 │
│ Totals ┆ 29810 ┆ 7846 ┆ 4666 ┆ 1490562 │
╰──────────┴───────┴─────────┴───────┴──────────────╯
Files scanned: 183
Languages detected: 3
Elapsed: 3.539 ms (0.003539 s)
sephera loc --path crates/sephera_core fast table output with totals and elapsed time
Terminal demo of sephera loc showing per-language totals in a table.

loc reads [project] and [loc] from .sephera.toml, so the format, the output path and the ignore list do not have to be typed every time:

[project]
ignore = ["vendor"]
[loc]
format = "markdown"
output = "reports/loc.md"
Terminal window
sephera loc --path . # writes reports/loc.md in markdown
sephera loc --path . --format json # a typed flag still wins

An unknown key in that file is an error naming the correction, not a setting that quietly does nothing. See .sephera.toml for profiles and aliases.

Repeat --ignore to combine multiple patterns:

Terminal window
sephera loc --path . --ignore target --ignore "*.snap"

Patterns containing *, ?, or [ are treated as globs and matched against both the file name and the path relative to the base, so dist/** and **/node_modules/** each exclude a whole tree. Other patterns are compiled as regexes and matched against the relative path, where an unanchored pattern such as target matches anywhere in it.

Every analysis also reads the repository’s own .gitignore and .sepheraignore, applying each one to the directory that holds it. Pass --no-gitignore to analyse the tree as it is on disk instead. Explicit --ignore patterns outrank the repository’s rules, so a pattern you typed is never undone by a ! line in .gitignore.

loc draws a progress bar while it works, on standard error so that standard output carries the report and nothing else:

Reading files ####>--------------------------- 3,204/8,901 (36%)

The count is real, not an animation. It appears once the walk has finished and the file count is known, which is why the bar is a spinner until then — a percentage of a total nobody has counted yet would be a decoration.

--progress takes three values:

valuebehaviour
autothe default: draw only when standard error is a terminal
alwaysdraw even without a terminal, for a CI log or a screen recording
nevernever draw

Nothing needs --progress never in a script. Piping or redirecting standard error already makes auto silent, and every machine-readable format is written to standard output, so a captured report is unaffected either way.

For repo URLs, use --ref to analyze a specific branch, tag, or commit:

Terminal window
sephera loc --url https://github.com/Reim-developer/Sephera --ref v0.6.0

--ref applies to repo URLs only. Tree URLs already encode the ref in the URL itself.

The checkout is temporary and shallow: --url clones the branch tip only, because counting lines reads the working tree rather than the history. On the Linux kernel that is roughly 1.3 GB instead of 6 GB, and most of the difference is download time. Naming a ref other than the branch tip needs the history to resolve it, so --ref clones in full.

git streams its own progress while it clones, so a large repository shows byte counts and a rate rather than appearing to hang. Press Ctrl+C to stop: the clone is killed, the temporary checkout is removed, and the process exits 130 with nothing on stderr — the same code a shell reports for a program it stopped, so a script can tell “the user cancelled” from “it failed”.

Sephera’s scanner is byte-oriented and comment-token aware. It is designed to be fast, stable, and portable across newline styles, rather than to fully parse each language grammar.

In practice, that means:

  • support for LF, CRLF, and classic CR
  • support for the built-in comment styles declared in the language registry
  • stable behavior across all supported language lookups

For the current language metadata source of truth, see config/languages.yml.

Count the lines of code comments and the blanks between the tale in numbers