| name | contextlevy-cli | ||||
|---|---|---|---|---|---|
| description | Install and use the ContextLevy CLI for local AI context cost checks from git diffs. Covers npm install, scan/fix/badge/hook commands, JSON output, exit codes, and pre-push hooks. Use when the user asks about contextlevy diff, pre-push context checks, local ContextLevy setup, or installing contextlevy via npm. | ||||
| metadata |
|
ContextLevy is a repo hygiene linter for agent-heavy teams. It flags diffs that will make coding-agent review noisy — generated output, coverage, build artifacts, lockfile churn, and agent instruction changes.
Privacy: No LLM calls, no code upload, no external API. Runs on your machine.
For PR comments in GitHub, use the contextlevy skill.
npx skills add nonlooped/contextlevyThe wizard lets you pick contextlevy-cli (this skill), contextlevy, or both. To install only this skill: --skill contextlevy-cli.
npm install -g contextlevyRequires Node.js 20+ and git on PATH.
# Start here (no config required)
npx contextlevy check --base main
# Baseline repo context debt (tracked files)
npx contextlevy scan
# Scaffold config + workflow + pre-push hook
npx contextlevy init --full
# Suggest ignore patterns (dry-run by default)
npx contextlevy fix
npx contextlevy fix --write
# README/PR badges
npx contextlevy badge --style debt
npx contextlevy badge --from check --style risk
# Install hooks (Husky, lefthook, or .git/hooks)
npx contextlevy hook install
npx contextlevy hook install --pre-commit --no-pre-push
# Working tree vs main
contextlevy check --base main
# Staged changes only
contextlevy check --staged
# JSON for scripts / hooks
contextlevy check --base origin/main --format json
# Apply fail settings from contextlevy.config.yml
contextlevy check --base main --fail-on-config
# Strict category gate (dist/, coverage/, etc.)
contextlevy check --base main --strict| Code | Meaning |
|---|---|
0 |
Below fail thresholds |
1 |
Fail threshold exceeded |
2 |
Usage, config, or git error |
- Analyzes tracked changes visible to
git diff. Stage new files withgit add, or pass--staged. scanandfix --from scanusegit ls-filesfor a repo-wide baseline.- Reuses the same config file and estimation modes as the GitHub Action.
Prefer the built-in installer:
npx contextlevy hook installOr wire manually:
{
"scripts": {
"contextlevy": "contextlevy check --base origin/main --fail-on-config"
}
}Add contextlevy.config.yml at the repo root (or see CONFIG.md for all supported paths).
Minimal example:
mode: advisory
allow-paths:
- "packages/api/src/generated/**"Key options:
| Key | Default | Purpose |
|---|---|---|
token-threshold |
1000 |
Skip PR comment below this token total |
fail-on-severity |
unset | Fail at low / medium / high / critical or above |
fail-above-tokens |
unset | Fail when total estimated tokens exceed this value |
ignore-paths |
[] |
Globs excluded from analysis |
allow-paths |
[] |
Globs counted but not flagged as high-impact |
estimation-mode |
simple |
simple (chars÷4) or tokenizer (local BPE) |
comment-format |
default |
default or compact (Action/CLI human output) |
Editor autocomplete: point YAML at docs/schema/contextlevy.schema.json in the ContextLevy repo.
For full config tables, severity levels, and recipes, see reference.md and CONFIG.md.
| Category | Examples |
|---|---|
| Coverage | coverage/lcov.info, htmlcov/ |
| Generated | generated/client.ts, protobuf/OpenAPI dumps |
| Build output | dist/, build/, .next/ |
| Lockfiles | package-lock.json, pnpm-lock.yaml |
| Agent config | .agents/, AGENTS.md, skill packs |
| Large files | Any path above large-file-token-threshold |
When helping a user set up the ContextLevy CLI:
- Ask whether they need local checks (CLI), PR comments (contextlevy), or both.
- Run
contextlevy scanfirst for repo-wide debt, thencontextlevy checkbefore opening PRs. - Use
contextlevy fix --writeto append missing ignore patterns; usecontextlevy init --fullfor one-shot setup. - Add
contextlevy.config.ymlwithfail-on-severityorfail-above-tokenswhen using--fail-on-config. - For monorepos, use
ignore-pathsfor vendored/generated trees andcustom-rulesfor project-specific paths. - Recommend
contextlevy hook installorfail-on-configin pre-push hooks; usefail-on-severity: highin CI for advisory-first teams.