subamanis/mezura
subamanis/mezura has 73 GitHub stars and 2 forks. GitHot measured +1 stars in 24 hours and +15 in 7 days. Last checked 2026-11-24 16:30 UTC. Last push 2026-11-18.
Measured star growth
- in 24h
- +1
- in 7 days
- +15
- in 15 days
- Collecting history
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
About
Counts the lines of a codebase quickly and accurately, separates the test code from production code, counts user-defined keywords like classes and structs. Tracks how the figures move between runs, and between any two git revisions. Command line program, library and MCP server.
Developer ToolsREADME.md
Originalmezura
mezura counts the lines of a codebase quickly and accurately, along with user-defined keywords like classes and structs.
It tracks how the figures move between runs, and between any two git revisions.
It lets you decide what counts as what, and how the report looks.
The figures can be grouped by language, by module and by file.
Windows, Linux and macOS binaries are built and tested on every release.
The whole Linux kernel, in some of the bundled themes:

Table of contents
- Why mezura
- Installation
- Usage
- What is counted
- Taking the result elsewhere
- Tracking growth
- Configuration
- Themes
- Supported languages
- Accuracy and limitations
- How it compares
- Performance
- Contributing
- Acknowledgements
- License
Why mezura
Things it does that most counters do not:
- Ensures the right language for each file. When two languages claim one extension, the way
.his C, C++ and Objective-C, or.mis MATLAB, Objective-C and Mercury, every file is identified by its own content: a#!line first, then heuristics on its content. And you always have the last word: set your preferences globally inlanguage_conflicts.txt, or per-project through its configuration, or--force-languagefor one run, or even per module in the same run. See Supported languages. - Discards non-code files with a matching extension (no more Make dependency
.dfiles counted as the D language!). Alongside the minified and generated files that are skipped by default, they are reported as skipped. See What is skipped. - Test code detection. Each language's tests are a row under it and under the total. It automatically identifies test code
by the test marks inside the code, by what the toolchain names as a test, by what a build tool compiles for tests, and by the
default test names of a tool whose own file is in the project. It also gives you manual control for marking or unmarking code
as test code, with the
--testscommand. See Test code. - Local revisions and remote repositories. Count or diff any local git revision (
@v1.0,./src@main) or any remote repository directly by its URL (https://github.com/owner/repo,[email protected]:owner/[email protected]) without cloning it yourself first. - Keyword counting. Occurrences of words you pick per language, classes, structs, traits, anything, counted only where they appear as code.
- Nested languages. The
<script>and<style>blocks of HTML, Vue, Svelte and Astro files are counted as the distinct languages they hold, and so is the page a PHP file returns to after a?>, up to the next<?phpor the end of the file, with the scripts that page holds. - Modules. Give a name to parts of a project and the report is grouped by these parts as well as by language. This way you can split your project into e.g. Frontend and Backend and see distinct reports for each module in the same table in the same run. See Modules.
- Track the history of your codebase. Log runs and compare against earlier ones, or diff against a git revision. See Tracking growth.
- Diff view of git revisions, remote repositories or json files. You can see the diff between the current state and a git revision, between two local or remote revisions, or against an earlier run that was saved in a json file. See Diffs.
- Two counting models to pick from. By default a line counts by what it says: a blank line inside a comment
is blank, a lone
}is neither code nor comment.--counting regionswitches to the model most other counters use, so the behavior more closely matches theirs.
See The counting model. - Per-line explanations.
--explainshows one file line by line with the verdict for each line, for checking a count that looks wrong. See--explainin COMMANDS.md. - Very customizable output. You have a lot of control about how mezura counts, and also about how it presents the results to you. You don't like the layout? You find it very busy with many sections? You don't want the animations? You can change everything. See Commands.
- Themes. Everything printed can be styled and colored: 98 tokens, 15 bundled themes, and an interactive web editor to experiment. See Themes.
- Output for other places. An HTML page with
--output htmlto send around, a markdown table with--output markdownfor a pull request or a job summary, one JSON document with--output json, an SVG badge or card with--badgefor a README, and an MCP server so a coding assistant can run mezura itself. See Taking the result elsewhere. - Data driven. All the files, languages and the settings mezura uses are extracted to your machine, where they can be inspected, changed, or extended very easily. See The data directory.
Also, it's the fastest line counter. See How it compares.
And it's also the most accurate at what it measures. See Accuracy and limitations.
Installation
The only thing you need is the binary, and there are 3 ways to get it:
1. Install it with cargo
cargo install mezura
To update an existing installation to the latest version, just run the same command again: it will fetch the newest published version, rebuild, and replace the old binary.
2. Build it yourself
After cloning or downloading the repo:
cargo build --release --bin mezura
The program is then target/release/mezura. Without --bin mezura the MCP server is built beside it, as target/release/mezura-mcp.
3. Download the prebuilt binary
Grab the one for your platform from the latest release.
Usage
Quick start
mezura # count the current directory
mezura ./src # count one directory
mezura ./src ./tests # count two directories
mezura frontend=./web backend=./api # group the report by part (modules)
mezura @v3.2.0 # count a local git tag, branch, or commit
mezura https://github.com/owner/repo # count a remote git repository (or [email protected])
mezura ./src --diff main # what changed since main
mezura --by-file # show results for every file separately
mezura src/main.rs --explain # why each line was counted the way it was
Files that a .gitignore ignores are skipped by default, and so are minified and generated files, so build artifacts and dependencies do not pollute the stats. See What is skipped.
Commands
WHAT IS COUNTED
--targets the directories and files to count, and the names to group them under (modules)
--counting whether a line counts by where its words are or by where the line sits
--exclude paths to leave out, as glob patterns
--tests files and directories to count as test code, as glob patterns
--languages count only these languages and leave every other one out of the report
--exclude-languages count everything except these languages
--force-language count an extension as the language you pick, even if another one claims it
--no-gitignore count the files a .gitignore ignores
--no-ignore-files count the files a .ignore or a .rgignore hides
--search-in-dotted go into directories whose name starts with a dot
--count-minified count the minified files that are left out by default
--count-generated count the generated files that are left out by default
--count-not-code count the non-code files that are left out by default
--no-heuristics never try to automatically resolve the contest when two languages claim the same
extension
--no-shebang identify every file by its name, leaving the '#!' line inside it unread
--show-languages print the languages this installation knows, with their extensions, and stop
--show-presets print the test presets, the shipped ones and your own, and stop
HOW THE REPORT LOOKS
--layout the shape of the details section: a table, a box, a list, or a matrix of modules
--sort which column the languages and modules are ordered by
--top show only this many languages, and say how many were left out
--by-file give every file its own row, or only the biggest few of each language
--tests-breakdown the tests of each language as one row, split from the rest of it, or removed from the
rows
--hide parts of the output to leave unprinted
--theme apply a theme, which is a whole look kept in one file
--style override the color and attributes of one kind of printed text
--bar-thickness the character the overview's percentage bar is drawn with
--progress-bar the characters the live progress bar is drawn with
--number-separator the character between the thousands of every printed number
--decimal-separator the character before the decimals of every printed number
--show-themes print the themes this installation holds, each previewed, and stop
--theme-editor open a page for tuning the colors of the report, and stop
TAKING THE RESULT ELSEWHERE
--output text for a person, markdown for a pull request, one JSON document for a program, or one
HTML file
--badge an SVG badge of the count, for a README
--log append this run to the log of the loaded configuration
COMPARING WITH EARLIER RUNS
--compare how many earlier logged runs to show the difference against
--diff what changed since an earlier run, or between two of them
YOUR DATA DIRECTORY
--save save the flags of this run as a named configuration
--load take the flags of this run from a saved configuration file
--no-default-config ignore the default configuration of this machine
--save-theme save the way this run looks as a named theme
--save-preset save the test patterns of this run as a test preset of your own
--show-configs print the configurations this installation holds and stop
--restore put the data directory back to what this version ships, and stop
THE SETTINGS OF A PROJECT
--save-local save the flags of this run as the settings of this project
--no-local ignore the settings of the project being counted
TUNING AND DIAGNOSTICS
--explain show one file line by line
--threads how many threads walk the directories and how many parse the files
--show-faulty-files name the files that could not be parsed, and what went wrong with each
--show-skipped name the files that were left out as minified, generated or not code
THE PROGRAM ITSELF
--help this list, or the full help of the commands you name
--version the version of this binary and the day it was released
--changelog what changed in this version, or in every version with 'full'
Run --help <command> for the full text of one command, or --help full for all of them. The same
texts are in COMMANDS.md, so they can be read without a terminal.
Modules
Give a target a name and the report is grouped by that name as well as by language:
mezura frontend=./web backend=./api
mezura ./project tests=./project/tests
mezura tests=./api/tests,./web/tests
Every file belongs to exactly one module and the most specific path wins, so the second example
means "the tests there, the rest of the project here". Targets that were not explicitly claimed by a module
are shown under a row called (unnamed). Each argument is one target, and a name covers only the paths
of its own argument. So the third example is one module of two directories.
Each module gets its own block of rows, with its own languages and totals, and the history section then records how each module grew.

--layout matrix crosses them instead, languages down and modules across, one figure per cell.

--hide modules drops the grouping for a single run, so a configuration that names its targets
prints as one flat report. The full rules (glob patterns, repeated names, ordering) are under --targets in
COMMANDS.md.
Layouts
The details section comes in four shapes. table is the default and boxed draws the same figures
inside a frame, both of them aligned so a column can be read down. list gives each language a
sentence instead, reading left to right, and matrix answers a different question, languages down
and modules across.
The four layouts on the same run
--layout table

--layout boxed

--layout list

--layout matrix

--hide takes any part of the output away, whole sections or single columns, and --sort, --top
and --by-file decide what the rows are and in what order. They are all listed in
COMMANDS.md.
What is counted
The counting model
By default, mezura judges a line by what it holds. A blank line inside a
block comment is not a comment, because it documents nothing. A line holding only } or ); is
neither code nor comment, because it carries no data and no instruction: those are tokens the
language demands, placed wherever your style puts them, and whether the brace goes on its own line
is not a fact about how much code you wrote.
So under this model code and comments do not add up to lines. What is left over is grouped as
extra, and it is the part of the file that carries nothing. This is the default, and it can be
asked for explicitly with --counting content.
Counters that group by region answer the other question, "which block is this line inside", and
give the blank line to the comment and the brace to the code. Neither reading is wrong, they answer
different questions, and it is worth knowing which one you are reading. For the more conventional
region-based counting, run mezura --counting region.
What is skipped
Files and folders named in a .gitignore, .ignore or .rgignore are skipped (see --no-gitignore
and --no-ignore-files). Directories whose name starts with a dot are skipped unless
--search-in-dotted is given, and .git is never traversed at all.
Three checks on a file's head can also set it aside, each reported above the table with its own
count: minified (an average line of 1000 bytes or more), generated (a marker like do not edit or
@generated in the first 512 bytes), and non-code files (give-away text listed per extension in
language_conflicts.txt, the way a .d dependency file is not the D language and a ProGuard
.pro is not Prolog). Each check has its own flag that turns it off: --count-minified,
--count-generated, --count-not-code. The not-code check is also off under --no-heuristics.
--show-skipped prints the paths, and --explain on such a file says which check set it aside.
The reasoning behind the tests is in Accuracy and limitations.
A path you write out yourself is always counted, even if it is ignored, dotted, a link, minified, generated or not code. The matches of a glob pattern are paths mezura found, so those are skipped like any other found path.
Test code
mezura separates test code from production code, displaying a tests row under each language that
has tests and one under the total.
Out of the box, mezura detects test code only when it is unambiguous:
- Source markers and annotations: inline test blocks (
#[cfg(test)]and#[test]in Rust,unittestin D,testin Zig) and file-level test annotations (@Testin Java/Kotlin,[Fact]and[Test]in C#). - Toolchain file names and build directories: test file suffixes required by a toolchain
(
*_test.go, Perl's*.t) and standard test directories next to their build file (such astests/next toCargo.tomlorsrc/test/next topom.xml/build.gradle). - Test runner presets: when a test tool's config file is present in a folder (such as
jest.config.ts,vitest.config.ts,conftest.py, or.rspecnext to aGemfile), mezura enables that tool's default test patterns under that folder and lists the active presets below the report, unless a configuration file already declares test patterns. When apackage.json,pyproject.toml,Gemfileorcomposer.jsonnames a test tool and no test of it was found, a note with the tool and the--teststhat declares them goes to the error output, into the JSONwarningsand onto the markdown page.
For anything else, pass glob patterns or preset names (@pytest, @dotnet, !@jest) to --tests:
mezura ./ --tests "spec/,!spec/fixtures/"
mezura ./ --tests "__tests__/,*.test.ts,*.test.tsx"
mezura ./ --tests "@pytest,!tests/data/"
Run --show-presets to list all built-in and custom presets, or --save-preset <name> to save the
patterns of a run for reuse. To change how test code is shown in the report, use
--tests-breakdown split (separate production and tests rows), --tests-breakdown removed
(subtract tests from all counts), or --hide tests (disable test detection completely). Full
details and per-language rules are in
Test detection.
--tests-breakdown share

--tests-breakdown split

Taking the result elsewhere
Markdown output
--output markdown prints the report as markdown tables and lists, for a build step to leave in a pull request or a job summary.
mezura ./src --diff origin/main --output markdown >> $GITHUB_STEP_SUMMARY

The modules, the languages under them and the changed files under those are all rows of the one table, at the depth the printed report draws them at.
It is the report itself, so --hide, --sort and --top cut and order it exactly as they do the printed one, --by-file hangs the files under each language, --layout matrix crosses languages with modules, and --compare adds the History section as a list. The other --layout values draw the same markdown table, and the colours and the overview bar are left out as terminal drawings.
A warning that puts the numbers in doubt, an unreadable language file among them, is written under the table as well as to the error output, since whoever reads the page is the one deciding on those numbers. So is the note that a test tool the project names found no tests. The ones that only report an ignored setting stay on the error output, where the build log keeps them.
Counting a git revision needs the full history, so a workflow doing the above wants fetch-depth: 0 on its checkout.
JSON output
--output json replaces the printed report with a single JSON document, so that a build step or another program can read a run easier. Everything that is not the document itself,
warnings included, goes to the error output, so mezura ./src --output json > stats.json leaves a file
that a parser accepts. The same holds for --explain --output json, where the document answers for
one file with one verdict per line. The document is written even when there was nothing to count, and even when
every file failed to parse: a consumer never has to tell "no output" apart from "no code found", and
a run that failed still writes a document, with the failure in it.
mezura ./src --output json | jq '.total.code'
mezura ./src --output json | jq -r '.languages[] | "\(.name) \(.lines)"'
scope echoes
the settings that can change a number, so that two documents are not compared when one of them was
produced with a different --exclude or --counting, and under test_presets the test presets a
tool's file turned on, with the folder and the file, since the report's list of them is not in the
document. Every total, language, section and file row
also carries a classes block holding the nine raw per-line counts both counting models fold from,
so a consumer can compute either model whatever the scope names. format is the version of the
document itself, separate from mezura_version, and it only moves when a key is removed or changes
meaning, so a parser can check that one and ignore which build wrote the file.
faulty_files names every file that was found and could not be parsed, and unreadable_dirs every
directory the scan could not open, whose whole contents are therefore missing from every number in
the document.
warnings carries what the run said on the error output, which whoever reads the document never
sees. Each entry has a code that is safe to branch on, a message that is safe to show and free to
be reworded, the subject it is about, and an affects of counts or settings. That last one is
the useful question: an unreadable language file means a whole language went uncounted, while a
setting that was ignored leaves every number intact, and a consumer can gate on it without keeping a
list of every code that exists.
mezura ./src --output json | jq -e '[.warnings[] | select(.affects == "counts")] | length == 0'
test-preset-unapplied means a test tool the project names found no tests, so they count as
production until --tests declares them.
Exit codes. 0 means mezura ran and told you what it found, including when it found nothing, because zero is an answer. 1 means the run failed: a mistake in what was asked for, a name that does not exist, a set of files where every one of them failed to be parsed, or a scan that found nothing after failing to open a directory, since that zero is not a count of anything. The failing cases still write the whole JSON document, faulty files and unreadable directories included, so the failure can be read in full.
HTML page
--output html writes the run as one HTML file that opens anywhere, fonts and themes inside it.
Contains every shipped theme and every user-defined theme, and more presentation options.
mezura ./src --output html > report.html

The page of mezura itself is written at every release.
The page carries the document of --output json for the same command line. --sort, --top and
the five --hide names the document obeys (keywords, nested-languages, tests, modules,
timing) cut it as they cut the document. The other --hide names leave the page as it is.
--diff and --explain are refused with --output html.
A badge for the README
--badge writes only an SVG to the output. Without a word it is a pill with the lines
of code, mezura on the left. The cells are the words typed, always in the order lines,
code, comments, tests, files, languages. card draws the box GitHub draws for a
repository's languages, with a bar, the biggest languages and the figures.
mezura --badge > badge.svg
mezura --badge code tests languages > badge.svg
mezura --badge card --top 4 > card.svg
The project's .mezura/config.txt applies, so a badge made in a build step counts with the
project's own --tests and --exclude once --save-local has written them. The link to mezura
is the markdown around the image:
[](https://github.com/subamanis/mezura)
The mezura badge action draws it in a GitHub
workflow on every push. It keeps the SVG on a separate branch, mezura-badge, and its README
holds the whole workflow.
- uses: subamanis/mezura-badge@v3
with:
args: --badge code comments tests
The image then comes from that branch, with your owner and repository in the URL.
[](https://github.com/subamanis/mezura)
Coding agents (MCP)
mezura-mcp is a second, separate binary that lets a coding assistant run mezura on its own.
Install it beside mezura:
cargo install mezura-mcp
Then add it to whichever file your editor keeps its servers in:
{
"mcpServers": {
"mezura": { "command": "mezura-mcp" }
}
}
It runs the mezura binary to count, so mezura has to be installed too.
It looks for it next to itself first, then on the path. If it lives somewhere else, name it:
{
"mcpServers": {
"mezura": { "command": "mezura-mcp", "env": { "MEZURA_BIN": "/opt/tools/mezura" } }
}
}
Three tools are offered. count_lines_of_code counts a directory, a file, a local git revision (@v1.0, src@main) or a remote repository URL, or compares what changed with diff, and answers with the
report (splitting each language with tests into production and tests rows), which is what to ask for when a person is going to read the answer. count_lines_of_code_as_json
answers with the JSON document instead, for when the numbers are going to be compared or added up.
explain_file goes through one file line by line (on disk or at <file>@<revision>) and says why each line was counted the way it was,
which is what to reach for when a number looks wrong; it takes a range of lines, so a long file can
be asked about without the whole of it coming back.
Every
call starts mezura afresh, so nothing of one answer can leak into the next, and a project's own
.mezura settings apply exactly as they do on the command line. An answer too long to be read at
once is refused, together with a narrower question to ask.
As a library
The counting engine is a crate of its own, mezura-core,
so a program of yours can count a directory without shelling out to a binary and parsing what comes
back.
cargo add mezura-core
You get the walk, the language identification, the per-line counting, the keywords and
explain_file, and both counting models out of a single run. You do not get the report: the
layouts, the colors and the themes live in the command line program and are not published. The
API documentation has the whole surface.
Tracking growth
Logs and history
Inside the 'data/logs' folder, the program will save log files that correspond to saved
configurations with target paths when --log is given on a run that counts those targets. A log is
a .jsonl file: one JSON entry per line, the newest first, so it is read by any JSON tool one line at
a time. Each entry records the settings the run was counted with (the target directories, the
counting model, and so on, so you can see if at some point the configuration got modified).
A run that names its targets records its modules in the entry, and the history section then carries one narrow line per module: which of them grew, and by how much. A module that was not there last time, or that is not there any more, is named as such. An entry written by a run that named none has no such block.
By using the --compare <N> flag, the (N) previous logged executions will be retrieved from the
file and will be compared and printed to the screen. For example for N = 2, it would look like this:

Both --log and --compare need a log to belong to, which means either a configuration with
target paths loaded or saved by name or a project with a .mezura folder, and a run that counts
those same targets. A checked-out revision or remote repository that carries a committed
.mezura/log.jsonl also shows its logged history and obeys --compare, while --log only
writes to a local working tree or named configuration.
Diffs
--diff shows what changed between two runs, in place of the report:
mezura ./src --output json > baseline.json
mezura ./src --diff baseline.json
mezura ./src --diff main
mezura ./src --diff ./other-repo/[email protected]
mezura ./src --diff v2.0.1..v3.0.0
mezura https://github.com/owner/repo --diff v1.0..v2.0
A reading is a JSON document an earlier run wrote, a git revision of the target's repository, a
local path at a revision (<path>@<revision>), or a remote repository URL (optionally ending in
@<revision>), checked out to a temporary directory and counted on the spot.

A language only one side has is marked new or gone, and a figure that did not move is a dash.
Add --by-file and the files that changed get rows of their own under each language, marked new
and gone the same way; a number keeps the biggest movers of each language.
With --output json the comparison is a document of its own, every count carrying from, to and
change.
Configuration
If you plan to run the program many times for a project, it can be bothersome to specify all the
flags every time, especially if they contain a lot of targets and exclude dirs. That's why you can
specify many flags in a configuration file, and have the program just load that file (see
--load).
Your own configurations
Configurations can be created automatically by specifying all the flags once, along with the
command --save, and a name for the configuration. Then the program, along with its normal
execution, will automatically create a config file with the name you specified, and dump all the
flags in there. Target paths are saved only when you specify them on the command line (or they
were already in a configuration --load brought in on the same run), and default holds none, so
saving without a target path creates a settings bundle you can load in any directory; saving with
explicit target paths (mezura ./ --save <config_name>) remembers those paths too:
mezura --load <config_name>
By default, there is a configuration file named "default" already present in the "config" folder of
your data directory, that gets loaded on every run. There, you can customize your preferences and they will
apply to all runs, unless overridden by giving a different command on the command line, or by
loading a specific configuration. mezura <flags> --save default adds those flags to the file and keeps the
settings it already holds. With --no-default-config it starts the file over. Notes written by hand in
the file are lost, and a setting is removed by editing it. For example, if you prefer the counting model of the other
counters, you can run mezura --counting region --save default or put a "===> counting" block holding "region" there. --no-default-config leaves that file
out of a single run, so the run answers with mezura's own defaults and counts the same on any machine.
The settings of a project
If you want the config to live inside the project instead, so it can be shared through version control, put it in a .mezura folder beside the code:
your-project/
.mezura/
config.txt
log.jsonl
src/
config.txt is the same format a saved configuration has, and log.jsonl the same format a log has. Write the folder with mezura <flags> --save-local, or by hand.
It is found without being asked for. A run looks for the folder in the directory holding its targets and then in each directory above it, taking the nearest one, so it applies from anywhere inside the project and a project nested in another one shadows it. A run using one names the file it read. Ignore it for one run with --no-local. A run naming a configuration other than "default" with --load or --save leaves it out, unless --save-local writes it.
It is safe to commit. Its targets are written relative to the folder, so it names the same places on somebody else's disk. For everything that decides a number, anything it does not set falls back to mezura's own defaults, which are the same for everybody, so two people get one answer. The theme, the layout and the separators still come from the personal config, since there the point is that everyone has their own.
The priorities of the specified flags are:
- cmd
- Specific config file
- The project's own config file (left out when --load or --save names a configuration other than "default", unless --save-local writes it)
- Default config file
- Internal defaults
The data directory
There is a "data" folder in the repository, that contains some already provided language files, themes and the default configuration file. The program, at compile time, includes the "data" folder in the binary, and during the first execution, it saves it with the same structure in a persistent path, inside the user's computer, according to the platform's specification. More specifically, the paths per operating system are:
Windows: %APPDATA%\mezura\data
Linux: /home/$USER/.local/share/mezura
MacOs: /Users/$USER/Library/Application Support/mezura
The languages, themes, configurations and logs are then read from those folders, on that first execution as much as on every one after it, so you can reach them and change them: add languages of your own, add themes, or edit the default configuration.
Set MEZURA_DATA_DIR and that folder is used instead, created and filled on the first run there
exactly as the usual one was. It is what you need when two versions of mezura have to run on the
same machine. A newer version rewrites a shared folder into the shape it expects. From 3.4 on, an
older one refuses to run in a folder that a newer release wrote. A run using it prints a line about it every time, because a variable set once and forgotten
hides every configuration and theme you saved.
Installing a new version updates the language files there, so a correction to a language reaches
you without you having to do anything. One that you changed yourself is replaced too, since a
language file that has fallen behind counts wrongly, but your copy is kept under
data/replaced/<version>/<date and time>/ and the program names it, so you can carry your changes
over. Each update or --restore writes its own folder there, so two of them never mix and the
newest is the one at the bottom. A language file or a theme of your own is never touched, and
neither is your default configuration, which is written only when it is absent. A shipped theme you edited, other than Mezura.txt, stays yours through every update,
also when a version stops shipping it, and only --restore puts it back to what ships, with your
copy saved under replaced. A version that brings new styles adds them to your edited copy, with
every style you set kept and your file as it stood saved under replaced. Mezura.txt is the
default look written as a file, so a version that changes it replaces your edited copy as it would
a language file, and saves yours under replaced. A look of your own belongs under a name of your own, which
--save-theme writes. A language_conflicts.txt you have not edited is brought whole to each new version;
an edited one is merged, with your lines kept and your file as it stood saved under replaced.
Themes
Everything the program prints can be styled: 98 tokens, each taking a text color, a background color, and any of bold, italic, underline, dim and reverse. Colors are hex values or one of the 16 standard terminal color names, which follow the color scheme of your terminal. You can set just the background and leave the text to the terminal, or the other way round. The live progress bar can also take a gradient between two colors, or a rainbow. Run --help --style for the full list of tokens.
A theme is a plain .txt file of token = value lines, in the "themes" folder of your data directory. It holds only how the output looks, so it can be shared as it is. Apply one with --theme <name>, list the ones you have with --show-themes, and write the current look into a new one with --save-theme <name>.
15 themes are bundled. Mezura is the default look, and it paints its text in the colors of your terminal's own scheme, so it reads well on any terminal, light or dark. The others are prettier and made for one kind of terminal: Catppuccin, Dracula, Forest, Gruvbox, Meadow and Ocean for a dark background, each with a -light version for a light one, and Mezura-classic, the look of earlier versions, for a dark one. Uncolored has no color at all and keeps the report readable with nothing but bold, italic and dim. See them all with --show-themes or in the theme editor, and pick the one that suits your terminal. Edit any of them but Mezura, which follows the default look, or add your own by dropping a file there.
--show-themes previews each of them on the same figures, which is where these three come from:

The four languages of the overview and the folded 'others' entry are five ordinary tokens, language-1 to language-4 and language-others, so a theme sets them the same way it sets everything else. A theme that gives none of them a color prints no overview, since its bar would be one shade from end to end.
The usual environment variables for color are followed. NO_COLOR, set to anything, takes the colors out of the report and keeps its bold, italic and dim, and under the default look the report takes the look of Uncolored. CLICOLOR=0 or a pipe prints plain text with no styling at all, and CLICOLOR_FORCE=1 keeps every color even in a pipe.
To make authoring one easier, there is an interactive editor: one run of mezura with a picker for every token that draws it, its color, its background and its attributes, contrast readings beside them, and a button that hands back the lines of a theme file.
Open the theme editor online to play with the bundled themes, or run mezura --theme-editor to open it with the themes found on your own machine, including the ones you created.
Supported languages
Mezura ships with over eighty languages, which realistically will contain any real language you will ever use. Still, this number is considerably smaller than the 200+ languages supported by some other counters, and most of the difference is what gets called a language: their lists carry JSON, XML, SVG, Markdown and plain text, which are not code, and a report that counts those is answering a different question than the one you asked. The rest of the difference is that an extension is only worth claiming when the files carrying it really are that language, which has a separate answer for each extension: on GitHub, 91 of every hundred .pl files are Perl, and 1 of every hundred .pro files is actually Prolog. A language you are missing is easy to add yourself (see below), and if you think an important one is missing for everyone, open an issue or a PR.
All the supported languages can be found in the data directory. Every language is a text file that can be inspected and even modified, and you can easily expand the collection of languages with your own definitions, by adding more text in files there. --show-languages prints them all with the extensions each one claims, and puts a star on an extension that another language holds.
If two or more language files claim the same extension, each file of it is identified by its own content: a #! line first, then the evidence the language files declare, so a .m opening with @interface counts as Objective-C, one opening with function counts as MATLAB, and one opening with :- module counts as Mercury. A file whose content says nothing falls back to the winner named in the language_conflicts.txt file of the data dir, which ships with an answer for every contest between the languages that come with the program. An extension that nobody has named there goes to the language that comes first alphabetically, and the program reports it, since that is only a tie-break. --force-language overrides all of it for a single run, or through a configuration file for a single project. It can also answer differently per module in the same run, so mezura ios=./ios analysis=./matlab --force-language ios/m=objective-c,analysis/m=matlab counts one repository's .m files as Objective-C in one folder and as MATLAB in the other. In --languages and --exclude-languages an extension that several languages claim names all of them, so --languages m is --languages matlab,objective-c,mercury. Each file is identified by its content, as in any run. --exclude-languages matlab leaves out only the files identified as MATLAB, and Objective-C's .m files stay.
A file with no extension at all is named by the same #! line, so a script called configure is counted as the language that line names, and a whole file name a language claims, like Makefile, is answered before either. --no-shebang turns that first line off everywhere, which is how a run is made comparable with a counter that only knows extensions: files with no extension go uncounted and are never opened, and a contested extension is settled without it.
Language choices is the short page behind those answers: which language gets each contested extension, and which files are left out of the count.
The language files guide is a separate page: a whole language file to copy, every block with an example, which of the seven string blocks a symbol belongs in, and the two mistakes that cost people the most time.
Accuracy and limitations
The program is able to understand and parse correctly arbitrarily complex code structures with intertwined strings and comments. This way it can identify if a line contains something other than a comment, even if the comment is partitioned in multiple positions and it can identify valid keywords, that are not inside strings or comments.
For example in a line like /*class"*/" class" aclass, it will not count "class" as a keyword since the first is inside a comment, the second inside a string and the third has a prefix.
Additionally:
It checks for escaped characters, for example
/"will not be counted as a string symbolIt resolves symbols that are side by side, for example
*/*is normally identified as both a closing and an opening comment symbol, but the program will understand the correct usage.A language that writes comments in more than one way gets all of them, and each one ends only with its own closing symbol. Pascal writes
{ }and(* *), D writes/* */and/+ +/, and a stray*)inside a{ }comment is just text.A comment written inside another comment does not end it early. This is how OCaml, Rust, Haskell, F#, Scala, Kotlin, Swift, Julia, Elm, Lisp, Scheme, MATLAB and WebAssembly text read their own code, so commenting out a block that already had comments in it counts as the comment it is. In C and the languages that follow it the first
*/really does end the comment, and that is what the program does there.Lua's
--[==[comments are read to their real end, so a]]written inside one is text.A comment that ends and another that begins on the same line (
]]--[[in Lua,--><!--in HTML) are read as two comments.Strings are read with the same care. A quote left open by mistake costs only its own line, a Python docstring or a JavaScript backtick still runs for as many lines as it likes, and the raw forms that end with a different symbol than they started with, like Rust's
r#"..."#or C#'s@"...", end where the language says they do even when they finish with a backslash.
All of this is measured against the LineJudge conformance suite, once per counting model:
--counting content and
--counting region
With that said, it is important to mention the following limitations:
Another language inside a file is only found where a tag opens it, the way
<script>and<style>do, the tag running over as many lines as it needs, and where PHP's?>returns to its page until the next<?or the end of the file. The section begins on the line after the tag and the line holding either tag belongs to the language around the section, so a?>followed by markup on its own line leaves that markup to PHP. A.phpfile is PHP from its first byte, so markup written before its first<?phpcounts as PHP. Languages that interleave mid-line are outside that: the ERB, JSP and Blade family are read as one language from beginning to end. A section fenced by something that is not a tag is outside it too: the---frontmatter at the top of an Astro file holds TypeScript, and its//lines are counted as code. The<script>and<style>blocks of the same file are read as the languages they hold, as they are in Vue and Svelte.Keywords are counted as words. Every
classin code is counted, whatever it means there, unless the language file says what follows a definition: C'sstructand C++'sstructandclasscount where a name or none and then{(or:in C++) follow them, so a declaration, a parameter, a cast or asizeofadds nothing. A definition with anything but names before the brace, like__attribute__((packed)), is missed.Hard links count twice. Symbolic links and nested targets are dropped, but a hard link is indistinguishable from an ordinary file.
A heredoc is read in the shells, Perl, Ruby and PHP. A regular expression of Perl or Ruby and Ruby's
%[...]and$'are read as code, so an apostrophe inside one opens a string, and a heredoc opener that string runs past is missed.Case is ignored in extensions, so the Unix convention where
.Cis C++ and.cis C is lost.A
*after a character in a block comment symbol or a paired string symbol means "any number of that character", as in Lua's--[=*[and Rust'sr#*", so a language whose symbol really contained such a run could not be declared. None is known.Two languages claiming one extension is settled per file, by a
#!line or by evidence the language files declare. A file whose content decides neither way follows the standing order oflanguage_conflicts.txt, and is parsed with that winner's symbols.--force-languagedecides outright,--no-heuristicsturns the content reading off, and--no-shebangtakes the#!line out of the whole business, the naming of files that carry no extension included.On Linux and macOS a file is read without asking its size first, and the first read that comes back short is taken as its end. A read that fails partway through, on a failing disk or a network mount that answers short, hands back what it managed and reports the error only on the next call, which is never made: such a file is counted with the part that was read and does not appear among the faulty files. Asking would cost one system call per file, and that was decided against. On Windows the size comes with the directory listing and the whole file is read.
On Linux and macOS a file of 256 KB or more is mapped into memory, since mapping it costs less than copying it out of the page cache. If another program truncates that file in place during the few milliseconds mezura spends on it, the run dies with a bus error. If it writes into the file in place without truncating it, that file is counted from a mix of its old and new bytes. Both take a write into that same file, landing inside that window, on a file of that size. A save through a new file renamed over the old one (the way editors and git write) leaves the mapped file untouched. A file modified in the last five seconds is read the old way, so one being generated at that moment is never mapped. ripgrep's memory maps have the same exposure, and its help documents it.
How it compares
Against codestats, scc and tokei, on the Linux repository tree, measured with linebench 0.4 over 3 warmups and 30 timed runs per command, in both command orders.
On native Debian 13:
| tool | time | vs fastest | lines/s | files | lines |
|---|---|---|---|---|---|
| mezura 3.5.0 | 67 ms ± 2 | 1.00x | 540.7M | 63,743 | 36,019,013 |
| codestats 1.1.0 | 79 ms ± 1 | 1.19x | 454.4M | 63,738 | 36,018,801 |
| scc 4.1.0 | 208 ms ± 3 | 3.12x | 173.1M | 63,738 | 36,018,801 |
| tokei 15.0.0 | 411 ms ± 3 | 6.17x | 87.7M | 63,793 | 36,027,518 |
On Windows 11, the same machine and the same tree:
| tool | time | vs fastest | lines/s | files | lines |
|---|---|---|---|---|---|
| mezura 3.5.0 | 175 ms ± 15 | 1.00x | 205.6M | 63,772 | 36,017,987 |
| codestats 1.1.0 | 212 ms ± 15 | 1.21x | 169.7M | 63,767 | 36,017,775 |
| scc 4.1.0 | 521 ms ± 36 | 2.97x | 69.1M | 63,767 | 36,017,775 |
| tokei 15.0.0 | 617 ms ± 20 | 3.52x | 58.4M | 63,822 | 36,026,522 |
The comparison is doing equal work: the same languages over the same tree for all of them,
mezura pinned to the same counting model the others use, the gitignore not taken into
consideration by anyone, and each tool's unique feature apart from counting turned off
(keyword counting for mezura, complexity and cost estimates for scc).
The files and lines columns are the proof of the equal work.
Measured on a Ryzen 7 9700X with 16 threads and a Lexar NQ790 PCIe gen4 NVMe disk.
The exact flags, the trust checks every run carries, the full methodology and the recorded numbers of each run for equal work and program defaults, over the Linux, JDK and CPython trees, are in benchmarks.
Performance
Threads and phase timing
--threads <producers> <consumers> sets how many threads walk the directories and how many parse
the files. Without it both numbers are chosen from the machine, and the default asks for far more
consumers than cores on purpose: a consumer spends most of its life waiting for a file to open, so
the speed comes from how many reads are in flight. Raising the
consumers is worth up to twice the speed on a slow disk, or on the first run after a reboot.
To see what a run actually spent its time on, set the environment variable MEZURA_PHASE_TIMING
to 1:
MEZURA_PHASE_TIMING=1 mezura <some_big_directory>
$env:MEZURA_PHASE_TIMING = "1"; mezura <some_big_directory>
The report goes to the error output, one line each:
| Line | What it measures |
|---|---|
[startup] |
Each step before the counting: the arguments, the data directory and keeping it in step with the binary, the language files, the conflict rules, the configuration |
[phase] producers alive |
How long the directory walk ran, how long the counting went on after it, how many files were still queued when the walk ended |
[phase] N consumers |
Where the counting threads' time went: starved (an empty queue while the walk still ran), opening, reading, parsing, summed over every thread, so the shares are the point |
[phase] N files |
How many files and megabytes were read, and at what rate per thread |
[phase] consumers' exit |
When the first counting thread ran out of work and when the last one finished, the tail that one thread carries by itself |
[phase] test modules |
Rust modules declared on a line of test code, the files that made test code whole, and how long that took. Printed only when there is one |
[finish] |
The counting, the printing, and the whole command |
With more consumers than the machine has hardware threads, a thread waiting for a core is counted
in whatever phase it was in, so a large "open" share can mean threads queued for a core while the
disk sits idle. One more [phase] line is printed then, as a reminder.
A deep queue and little starvation mean the parsing is the constraint, and more consumers pay. An empty queue and heavy starvation mean the walk is the constraint.
Windows and antivirus
Opening a file is far more expensive on Windows than on Linux: every open walks the object manager, the security descriptor and the whole filter driver stack, which is where antivirus and other minifilters sit. Since mezura opens one file after another, this dominates: on Windows the program is I/O bound, and most of its time is spent waiting on File::open. On Linux the same open is nearly free, and the run's cpu goes almost entirely into mezura's own work.
The practical consequence is that the same repository on the same machine is measurably faster to analyze from Linux.
That baseline cost is structural and does not go away. What can be removed is what sits on top of it: because every open traverses the filter stack, real-time antivirus protection ends up inside mezura's hot path, inspecting each file as it is opened, and it multiplies an already expensive operation. Excluding mezura from that scanning makes a very big difference on the performance.
To exclude mezura from Windows Defender real-time scanning:
- Open PowerShell as Administrator
- Run:
Add-MpPreference -ExclusionProcess "mezura.exe" - Restart your terminal
To remove the exclusion later:
Remove-MpPreference -ExclusionProcess "mezura.exe"
Note: This is a common requirement for file-scanning tools (similar to build tools, IDEs, etc.). Only add this exclusion if you trust the source of the executable.
The exclusion is matched on the exact filename, so a copy you renamed to anything else does not have it, and on this machine that by itself measured 1.28x on a large repository with byte-identical binaries. Worth knowing if you keep several builds around, or if you ever time one against another.
Contributing
See CONTRIBUTING.md for how to get a change in. Pull requests go against dev.
Acknowledgements
Thanks to cloc and scc, for the inspiration and motivation to push the boundaries, for setting a high bar and for years of high quality work. They are what pushed every part of mezura to be the best I could make it.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
The HTML page embeds the Inter and JetBrains Mono fonts, which come under the SIL Open Font License (LICENSE-Inter.txt, LICENSE-JetBrainsMono.txt).
Any contribution intentionally submitted for inclusion in this work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Explore related projects
Loading…
