Lint, score, and compress your AI agent context files.
ContextLint scans CLAUDE.md, AGENTS.md, .cursorrules, Cursor rules, README.md, docs/**/*.md, and GitHub Copilot instructions to find duplicate, outdated, risky, and token-wasting context before Claude, Cursor, Codex, Gemini, or another AI coding agent reads it.
Production-usable Rust CLI. Current focus: reliable local scanning, CI usage, and low-friction install.
Implemented:
contextlint scancontextlint scan --jsoncontextlint scan --fail-under <score>contextlint report --format markdowncontextlint report --format jsoncontextlint initcontextlint generate agentscontextlint completions <shell>- GitHub Action via
uses: arsyadal/[email protected] - File discovery for common AI context files
- Approximate token estimation
- Duplicate instruction detection
- Noisy section detection
- Risky phrase detection
- Outdated note detection
- Missing backtick file reference detection
- Missing command/script detection
- Basic dependency/technology mismatch detection
- Inline and config ignore support
Via Homebrew:
brew tap arsyadal/tap
brew install contextlintVia Cargo:
cargo install contextlintUpgrade:
brew upgrade contextlint
# or
cargo install contextlint --forcecargo install --path .contextlint scan
contextlint scan --json
contextlint scan --path ./my-project --fail-under 70
contextlint report --format markdown --output contextlint-report.md
contextlint report --format json
contextlint init
contextlint completions bash > contextlint.bash
contextlint generate agents --output AGENTS.generated.mdTry demo fixture:
contextlint scan --path examples/fixtures/messy-contextExample output (abridged):
ContextLint v0.1.3
Project: examples/fixtures/messy-context
Files scanned: 6
✓ README.md (349 tokens)
✓ docs/noisy.md (5152 tokens)
Score: 0/100
Status: Very Noisy
Issues found:
[CRITICAL] Risky instruction contains 'drop table'. <!-- contextlint-ignore -->
[MEDIUM] Duplicate instruction found in 4 files.
[MEDIUM] Referenced command `npm run build` is not available.
[MEDIUM] Referenced path `docs/missing-architecture.md` does not exist. <!-- contextlint-ignore -->
[MEDIUM] Section 'Noisy Historical Context' is noisy/long.More docs:
The marketing site lives in site/ and is built with Next.js, shadcn-style components, Radix UI primitives, and Framer Motion.
cd site
npm install
npm run dev
npm run buildname: ContextLint
on:
pull_request:
jobs:
contextlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: arsyadal/[email protected]
with:
fail-under: "70"CLAUDE.md
AGENTS.md
.cursorrules
.cursor/rules/*
README.md
docs/**/*.md
.github/copilot-instructions.mdCreate config:
contextlint initExample .contextlintrc.json:
{
"include": ["CLAUDE.md", "AGENTS.md", ".cursorrules", "README.md", "docs/**/*.md"],
"exclude": ["node_modules/**", "dist/**", "build/**", "docs/archive/**"],
"scoreThreshold": 70,
"tokenEstimator": "approximate",
"ignore": ["risky-instruction:docs/archive/**"],
"rules": {
"duplicateInstruction": true,
"outdatedArchitecture": true,
"riskyInstruction": true,
"noisySection": true
}
}Inline ignore:
<!-- contextlint-ignore-next-line -->
Ignore tests during refactor.
Ignore tests during refactor. <!-- contextlint-ignore -->Config ignore supports rule IDs, path globs, and rule-id:path/glob/**:
{
"ignore": [
"duplicate-instruction",
"docs/archive/**",
"risky-instruction:docs/stale-context/**"
]
}ContextLint starts at 100 and subtracts issue penalties:
critical = -20
high = -12
medium = -6
low = -2Score bands:
90–100 = Excellent
75–89 = Good
60–74 = Needs Cleanup
40–59 = Risky
0–39 = Very Noisycargo fmt --check
cargo check --locked
cargo clippy --locked -- -D warnings
cargo test --locked
cargo run -- scanThe best AI context is not the longest context. It is the clearest, safest, and most relevant context.
