codeint can be called directly from JavaScript, TypeScript, and Rust without parsing terminal text.
Both APIs expose check, diff, trend, and init, while codeint update remains CLI-only.
checkanddiffreturn a structured result on both exit0(passed) and exit1(Budget or Regression failed).- Operational errors (exit
2, such as an invalidcodeint.json, a missing folder, or a directory outside Git) throwCodeintErrorin JavaScript/TypeScript or returnErr(CodeintError)in Rust.
Install the codeint npm package, which ships dual ESM and CommonJS modules, TypeScript declarations, and the native platform binary with zero runtime dependencies:
npm install --save-dev codeintimport { CodeintError, check, diff, init, resolveBinary, trend } from "codeint";
const checked = await check({ cwd: process.cwd(), all: false });
if (!checked.passed) {
console.error("Budget failures:", checked.failures);
console.log("Production erosion:", checked.report.source_sets.production?.erosion.ratio);
}
const diffed = await diff("origin/main", { cwd: process.cwd() });
if (!diffed.passed) {
console.error("Regressions:", diffed.failures);
}
const history = await trend({ cwd: process.cwd(), since: "2026-01-01" });
console.log("Commits measured:", history.commits);
const { configPath } = await init({ cwd: process.cwd() });
console.log("Starter config:", configPath);
console.log("Bundled native binary:", resolveBinary());CommonJS callers can import the same functions with require("codeint").
Pass binaryPath in any options object to override the native executable path.
Catch CodeintError to inspect error.exitCode and error.stderr on operational errors.
Within the workspace or from a path dependency on crates/cli, import the typed library functions directly:
use std::path::Path;
use codeint_cli::{CheckOptions, DiffOptions, ReportFormat, TrendOptions, check, diff, init, trend};
let folder = Path::new(".");
let checked = check(folder, &CheckOptions::default())?;
if !checked.passed {
for failure in &checked.failures {
eprintln!("{failure}");
}
}
let json = checked.report.render(ReportFormat::Json)?;
let diffed = diff(folder, "origin/main", &DiffOptions::default())?;
let history = trend(folder, &TrendOptions::default())?;
let created = init(folder)?;Operational failures return Err(CodeintError), which exposes message() and remedy().