Skip to content
Latchkey

tokei: Count Lines of Code by Language

tokei scans a directory and reports lines of code, comments, and blank lines broken down by programming language.

tokei answers "how big is this codebase, and in what" in well under a second. It distinguishes code from comments and blanks, which wc cannot.

What it does

tokei walks the tree, detects each file language, and tallies code, comment, and blank lines plus file counts, printing a per-language table sorted by code lines. It respects .gitignore by default and supports JSON, YAML, and other machine-readable outputs.

Common usage

Terminal
tokei                            # whole repo, table output
tokei src/ tests/                # specific directories
tokei --output json > loc.json   # machine-readable
tokei -t Python,Rust             # only these languages
tokei --exclude vendor --exclude '*.min.js'

Options

FlagWhat it does
-o / --output <fmt>Output format: json, yaml, cbor (needs build support)
-t / --types <list>Count only the listed languages
-e / --exclude <pat>Exclude paths matching the pattern (repeatable)
--no-ignoreDo not honor .gitignore
-f / --filesList individual files, not just per-language totals
-s / --sort <col>Sort by lines, code, comments, blanks, or files

In CI

Emit --output json and pipe to jq to publish a LOC metric or to gate on a budget (for example, fail if a generated file balloons). tokei is deterministic and fast enough to run on every build without slowing the pipeline.

Common errors in CI

"tokei: command not found" (install via cargo install tokei, brew install tokei, or a GitHub release binary). --output json failing with "unsupported output format" means the binary was built without that feature; use a release build or the cargo install. Counts that look low usually mean files were skipped by .gitignore; add --no-ignore.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →