c8: coverage from the engine instead of from instrumentation
output coverage reports using Node.js' built in coverage
At a glance
- What is it?
- c8 does not instrument your code. It reads the coverage data Node's V8 engine already produces, converts it into Istanbul's report format so every existing reporter keeps working, and inherits nyc's configuration file names so that migrating is mostly deleting a file. The flag that decides whether the number means anything is off by default.
- Who is it for?
- Adopt c8 if you want coverage numbers without adding instrumentation to your build, and turn on `--all` before you trust a single figure, because by default it measures only the files your tests happened to load. Migrating from nyc should be cheap, since c8 reads .nycrc files and takes its default include, exclude and extension lists from the same schema package nyc uses.
- Can I use it commercially?
- Yes. ISC is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 1 day ago.
- What is it written in?
- Mainly JavaScript, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- bcoe/c82,126 ★ · +5
| Repository | 2026-09-30 | 2026-11-25 |
|---|---|---|
| bcoe/c8 | 2.1k | 2.1k |
5 Stars in the last 56 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
The engine was already collecting it
The premise is simple enough that it is easy to miss why it matters. Node.js has a built-in code coverage facility in V8, and c8's entire job is to consume what that facility produces and turn it into reports.
That is a different architecture from the one most Node coverage tools use. Instrumenting coverage means rewriting your source before it runs, inserting counters, and reporting on the rewritten program. That approach buys branch coverage at the cost of a build step, a source transformation, and a source map that maps your code onto code nobody wrote. c8 skips all of it. Your code runs as written, and the coverage comes from the engine that ran it.
The two lines that make it feel like nothing is happening:
npm i c8 -g
c8 node foo.jsThere is no configuration, no Babel step and no cache directory. The tool wraps whatever Node command you give it, collects the engine's coverage output into a temporary directory, converts it, and prints the report.
The conversion is where the actual work lives, and it is why the dependency list includes a library whose job is remapping V8 output onto Istanbul's format. Istanbul is the report schema that the whole JavaScript ecosystem's reporters understand, from the plain text summary to HTML, to lcov files that a CI service will read. By emitting that format rather than inventing one, c8 gets every existing reporter and every existing CI integration for free, and users do not have to relearn the reporting half of coverage.
The same reasoning explains why c8 inherits its defaults from the schema package that nyc uses. Its default include and exclude patterns and its default file extensions are not c8's opinions; they are the same lists, which is why a project that already has a nyc configuration gets the same behaviour after switching tools.
The flag that decides whether the number means anything
By default, V8 gives coverage only for files the engine actually loaded. The README states that plainly and then gives the example that makes it concrete.
If your `main.js` loads `a.js` and `b.js`, but your unit tests only load `a.js`, your total coverage can show as 100% for `a.js` while `main.js` and `b.js` are entirely uncovered. Nothing is wrong and nothing is hidden; the measurement is simply of what the tests exercised.
This is the central caveat of every native-coverage tool, and it is worth being precise about why it is dangerous. The default is flattering. Files your tests never load cannot fail, so they cannot drag the percentage down, and the report describes a smaller program than the one you ship. If you raise the threshold to 95% and the real number is 60%, a coverage gate built on the default will pass and tell you nothing.
The fix is `--all`, and it is off by default. With it on, the threshold you gate on is finally the number that describes your program rather than your test suite's import graph:
c8 --check-coverage --lines 100 npm testConcretely, `--all` makes every file inside the directories named by `--src`, which defaults to the current working directory, that also passes the `--include` and `--exclude` checks get loaded into the report. Anything still uncovered is then factored in at 0%.
Read that carefully, because it has a second-order effect. `--all` does not run your tests differently; it changes what counts as part of the program being measured. Once it is on, the include and exclude patterns stop being cosmetic, because they now decide which zero-percent files appear in your report. A pattern that is too broad and you will drown in untested vendor code; too narrow and the same flattering number returns.
So the order matters when you turn it on: get your include and exclude patterns right first, accept the lower number, and only then decide what threshold is realistic.
It reads nyc's config filenames on purpose
Configuration comes from three places: command-line flags, a section in package.json, or a JSON file on disk. The file is chosen with `--config` or `-c`, and when you do not choose one, c8 searches for four filenames in order, starting from the working directory and walking up the filesystem tree: `.c8rc`, `.c8rc.json`, `.nycrc` and `.nycrc.json`.
Two of those four belong to nyc, c8's predecessor. That is a deliberate compatibility decision rather than a leftover, and it shows up in the repository itself, which ships a `.nycrc` file at the root and carries a badge linking to its nyc configuration on GitHub. The project dogfoods its own migration path.
The syntax rule is the other half of compatibility. When you configure through package.json or a config file, you write the long-form option name without the leading dashes. That is a different grammar from the command line, and it is the sort of thing that produces a silently ignored setting rather than an error, so it is good that the README calls it out.
There is one dependency that explains the defaults precisely. The exclude and extension defaults are listed in the README as coming from a schema package's default-exclude and default-extension files. That package is the same one nyc uses for its own defaults. So a project that never wrote a coverage configuration gets identical behaviour from both tools, which means switching is not a re-tuning exercise.
Taken together, this is what a well-behaved replacement looks like: it accepts the old configuration, reproduces the old defaults, and emits the old report format. The only thing a migrating team has to change is the package name and the command.
Regenerating reports without re-running the tests
There is a subcommand that exists only because the coverage data outlives the process: `c8 report`.
The V8 coverage output is written to a temporary directory, and the path is configurable with `--temp-directory`, which defaults to whatever the `NODE_V8_COVERAGE` environment variable holds. Once that data is on disk, the conversion and reporting can be repeated as many times as you like without running a single line of your code again.
That is more useful than it sounds. A coverage run that produces six reporter formats through six separate executions is slow for reasons that have nothing to do with your tests. With the data cached, you run the suite once and then render. It also means report formats become a presentation decision rather than a test-run decision, which is the right way round, because you should be able to add lcov output to a CI step without adding a second test run.
The temporary directory also explains `--clean`, which defaults to true: before the script executes, previous coverage files are removed. That is correct for continuous integration, where a stale file from a failed or cancelled run would otherwise contaminate the report, and it is wrong if you were relying on accumulating coverage across a session. Turning it off is how you get a coverage figure for a suite you can only run in pieces.
One more small command with a real use: the ignore comment. `/* c8 ignore next */` suppresses the following line, block or function. The reason the feature exists is the honest one, given as an example: you run your tests on Linux, and some logic only executes on Windows. That is a legitimate exclusion. A threshold that needs three of these to pass is a threshold you have agreed to lie about, and the tool cannot tell the two apart.
Source maps decide whose coverage you are measuring
If you write TypeScript or JSX, the coverage you care about is the coverage of the file you wrote, not of the JavaScript the compiler produced. c8 handles source maps for exactly that reason, and the README spends a paragraph on the two shapes they come in.
Just-in-time instrumented codebases tend to insert the map inline, as a footer on the generated code, which is what a register hook can be configured to do. Pre-instrumented codebases, where a compiler emits a build folder before the tests run, may produce either an inline map or a separate `.map` file on disk. c8 handles both.
Then there is the flag that resolves an ambiguity you cannot design away: `--exclude-after-remap`. Exclusion patterns name paths, and the path of a file changes when you remap from build output to source. A pattern written for your `dist/` folder will not match `src/`, and a pattern that excludes generated output may, after remapping, exclude the source file that generated it. So the same pattern list produces different reports depending on whether it is applied before or after remapping, and the flag makes that choice explicit rather than implied.
This is where most of the real configuration effort goes for a typed project, and it is also where c8's numbers stop being comparable with a historical nyc report. Instrumented coverage knows about branches because it inserted the branch checks; engine coverage sees blocks the interpreter actually ran. Both are legitimate measurements of different things, and the README does not pretend otherwise, which is the behaviour you want from a tool you will use as a gate.
Monocart, and the shortcut that skips the hard part
There is an experimental flag, `--experimental-monocart`, and it exists because the conversion step is the fragile part of this tool.
The usual path is: the engine emits coverage as byte offsets into the generated code, and something has to translate those offsets into Istanbul's structured format. That translation is the complex transformation step, and c8's default does it with a dedicated library.
Monocart offers a way out. It can output V8 coverage as Istanbul reports, but it also provides reporters built directly on V8's byte-offset output, such as `console-details` and `v8`, which removes the transformation entirely. The README's own framing is that this may be less bug prone in some environments, which is a candid admission that the default path has failure modes.
Using it:
c8 --experimental-monocart --reporter=v8 --reporter=console-details node foo.jsIt needs a separate package, and the README is explicit about it:
npm i monocart-coverage-reports@2 --save-devThat arrangement is visible in the package metadata too, where the monocart package is a peer dependency marked optional rather than a hard dependency. The right reading is that c8 works fully without it and that the experimental path is an opt-in for people who have hit the conversion's rough edges, not a direction the project has committed to.
It measures itself, and the thresholds are yours
The repository's own scripts are the last detail worth noting, because they are unusually honest about how this project is verified.
The test script runs the c8 command line interface under c8 itself, against a mocha suite:
cross-env TS_NODE_SKIP_PROJECT=true node ./bin/c8.js mocha --timeout=10000 ./test/*.jsAnd the coverage script is the same line with a coverage threshold check added. So a tool that reports on other projects' code coverage is enforcing a coverage threshold on itself in its own test run. The env variable in that command stops the TypeScript loader from picking up the project configuration, and the formatter is wired in as a post-test step, so a style violation fails the suite rather than being noticed later.
Expected output is snapshot-tested, with a dedicated environment variable to update the snapshots when you intend to. That is the right technique for a tool whose product is text output: you cannot assert on a coverage percentage meaningfully, but you can assert that the report looks the same as it did.
Maintenance numbers are healthy. The licence is ISC, which is about as permissive as a permissive licence gets, and the repository carries a maintainers guide, a changelog and a Renovate configuration for dependency updates. Releases come as major versions: a 10.x line, then 11.0.0 in February 2026, then 12.0.0 in July 2026, with the last push on 2026-09-24. Major bumps in a coverage tool are worth pausing on, since they usually mean the Node range or the report format moved, and the declared engine range now excludes anything older than a fairly recent release.
So the practical guidance is short. Install it, turn on `--all`, spend an afternoon getting the exclude patterns right while the number gets worse, and only then decide what the threshold should be.
Editorial conclusion
Adopt c8 if you want coverage numbers without adding instrumentation to your build, and turn on `--all` before you trust a single figure, because by default it measures only the files your tests happened to load. Migrating from nyc should be cheap, since c8 reads .nycrc files and takes its default include, exclude and extension lists from the same schema package nyc uses. Do not expect its numbers to match nyc's historical ones, since engine block coverage and instrumented branch coverage are different measurements, and keep `/* c8 ignore next */` for code you genuinely cannot exercise rather than as a way to make a threshold pass.
Frequently asked questions
How does c8 differ from nyc?
c8 uses Node's built-in V8 coverage instead of instrumenting your source, then converts the engine output into Istanbul's report format so existing Istanbul reporters keep working. It also reads nyc's configuration filenames and takes its default include, exclude and extension lists from the same schema package, so migrating from nyc is largely a matter of changing the package name.
What does the --all flag do in c8?
By default V8 only reports files the engine loaded, so files your tests never load are absent from the report. With `--all`, every file under the `--src` directories that also passes the `--include` and `--exclude` checks is loaded into the report, and anything still uncovered is counted at 0%.
How do I make c8 fail a build when coverage drops?
Run `c8 check-coverage --lines 95 --functions 95 --branches 95` after your tests, or use the shorthand `c8 --check-coverage --lines 100 npm test` to run the tests and check in one step. Add `--per-file` to check thresholds per file, and `--100` as shorthand for setting all four dimensions to 100.
Can c8 work with TypeScript and JSX projects?
Yes, it handles source maps to remap coverage from generated code back to the original source files, and it supports both inline source maps and separate .map files on disk. The `--exclude-after-remap` flag controls whether exclusion patterns are applied before or after the remapping, which matters because paths change when you remap.
What is the experimental monocart option in c8?
Monocart is an alternative library for converting V8 coverage into Istanbul reports, and it also provides reporters built directly on V8's byte-offset output, such as `console-details` and `v8`, which removes the transformation step entirely. Use it with `--experimental-monocart` and install the optional peer package `monocart-coverage-reports` at version 2.
How do I ignore code that cannot be covered in c8?
Use the `/* c8 ignore next */` comment before the line, block or function you want excluded. The intended use is code that only executes on another platform, for example Windows-only logic in a suite that runs on Linux, rather than code excluded to make a coverage threshold pass.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/bcoe-c8)Star history chart for your README
[](https://hysenlabs.com/projects/bcoe-c8)Was this useful?