gitmyhub

tokei

Rust ★ 15k updated 1mo ago

Count your code, quickly.

Tokei is a fast command-line tool that counts lines of code, comments, and blank lines across 150+ languages in seconds, with output as a table, JSON, YAML, or CBOR for use in scripts and CI pipelines.

Rustsetup: easycomplexity 2/5

Tokei (pronounced like the Japanese word for "clock") is a command-line tool that counts the lines of code in a project. You point it at a folder, and it produces a table showing how many files exist per programming language, along with totals for lines of actual code, comment lines, and blank lines. It is written in Rust, a compiled systems programming language known for speed.

The tool is designed to be fast. According to the README, it can process millions of lines of code in seconds. It supports over 150 programming languages and their various file extensions. It also handles edge cases carefully, such as comments written inside strings (which should not be counted as real comments) and nested comment blocks.

Tokei can produce output in several formats beyond the default human-readable table. You can ask it to output JSON, YAML, or CBOR (a binary format), which makes it easy to feed the results into another program or store them for later comparison. You can also pass a previously saved result file back into Tokei and it will combine those old statistics with a new scan.

Common usage patterns include scanning a single folder, scanning multiple folders at once, excluding certain files or folders (using the same syntax as a .gitignore file), sorting results by code count or comment count, and listing per-file statistics instead of just per-language totals. A configuration file named tokei.toml or .tokeirc can set default behaviors.

Tokei is available on Mac, Linux, and Windows. It can be installed through many package managers, including Homebrew on Mac, Cargo (the Rust package manager), Scoop on Windows, Conda, and several Linux distribution package managers. It can also be used as a software library so other programs can call into its counting functionality.

Where it fits