Skip to content

Tokei Importer

The Tokei importer turns the JSON output of Tokei into a cc.json map. Tokei counts code, comment and empty lines quickly and knows more than 200 languages. Use it when you need a size map of a codebase in a language the CodeCharta parsers do not cover.

Run Tokei in your project’s root folder and pipe its JSON straight into the importer:

Terminal window
tokei . --output json | ccsh tokeiimporter -o tokei.cc.json

Or save the Tokei result first:

Terminal window
tokei . --output json > tokei_results.json
ccsh tokeiimporter tokei_results.json -o tokei.cc.json
OptionDescription
[FILE]the JSON file Tokei wrote; reads piped input when omitted
-r, --root-name=<rootName>the folder you passed to Tokei, which is cut from every path (default .)
--path-separator=<pathSeparator>separator between folders in Tokei’s paths; detected on its own when omitted
-o, --output-file=<outputFile>output file; prints to stdout when omitted
-nc, --not-compressedwrite plain JSON instead of a gzip file
-h, --helpshow the help and exit
Usage: ccsh tokeiimporter [-h] [-nc] [-o=<outputFile>]
[--path-separator=<pathSeparator>] [-r=<rootName>]
[FILE]

When you run Tokei on a subfolder, pass the same folder with --root-name so the map starts inside it:

Terminal window
tokei src --output json | ccsh tokeiimporter -r src -o src.cc.json
MetricDescription
locall lines of the file: code, comments and empty lines
rloclines that contain code
comment_lineslines that contain only comments
empty_linesempty lines

Tokei offers binaries for Linux, macOS and Windows, and packages for most package managers. See the Tokei installation guide. With a Rust toolchain you can also install it with cargo install tokei. JSON output is part of every build.