@yawlabs/ctxlint 0.12.0 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,564 +1,564 @@
1
- # ctxlint
2
-
3
- [![npm version](https://img.shields.io/npm/v/@yawlabs/ctxlint)](https://www.npmjs.com/package/@yawlabs/ctxlint)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
- [![GitHub stars](https://img.shields.io/github/stars/YawLabs/ctxlint)](https://github.com/YawLabs/ctxlint/stargazers)
6
- [![CI](https://github.com/YawLabs/ctxlint/actions/workflows/ci.yml/badge.svg)](https://github.com/YawLabs/ctxlint/actions/workflows/ci.yml)
7
- [![Release](https://github.com/YawLabs/ctxlint/actions/workflows/release.yml/badge.svg)](https://github.com/YawLabs/ctxlint/actions/workflows/release.yml)
8
- [![MCP Compliance](https://raw.githubusercontent.com/YawLabs/ctxlint/main/compliance-badge.svg)](https://github.com/YawLabs/mcp-compliance)
9
-
10
- **Lint your AI agent context files, MCP server configs, and session data against your actual codebase.** Context linting + MCP config linting + session auditing. 16 AI tools, 8 MCP clients, cross-project consistency, auto-fix. Works as a CLI, CI step, pre-commit hook, or MCP server.
11
-
12
- Your `CLAUDE.md` is lying to your agent. Your `.mcp.json` has a hardcoded API key. ctxlint catches both.
13
-
14
- [![Add to mcp.hosting](https://mcp.hosting/install-button.svg)](https://mcp.hosting/install?name=ctxlint&command=npx&args=-y%2C%40yawlabs%2Fctxlint%2Cserve&description=Lint%20AI%20agent%20context%20files%20and%20MCP%20configs%20against%20your%20codebase&source=https%3A%2F%2Fgithub.com%2FYawLabs%2Fctxlint)
15
-
16
- One click adds this to your [mcp.hosting](https://mcp.hosting) account so it syncs to every MCP client you use. Or install manually below.
17
-
18
- ## Why ctxlint?
19
-
20
- Every AI coding tool ships a context file: `CLAUDE.md`, `.cursorrules`, `AGENTS.md`, `.mcp.json`. These files are the single most important interface between you and your agent — they tell it what to build, how to test, where things live.
21
-
22
- But context files rot fast. You rename a file, change a build script, or switch from Jest to Vitest — and your `CLAUDE.md` still says the old thing. Your agent follows those stale instructions faithfully, then fails. You lose 10 minutes debugging what turns out to be a wrong path in line 12 of a markdown file.
23
-
24
- Multiply that across a team with 5 context files, 3 MCP configs, and 2 people who touched the build system last week — and you have a real problem with no existing solution.
25
-
26
- ctxlint is a linter purpose-built for this. It reads your context files, cross-references them against your actual codebase, and catches the drift before your agent does.
27
-
28
- - **Instant startup** — ships as a single self-contained bundle with zero runtime dependencies. `npx` downloads a ~400 KB tarball and starts immediately
29
- - **Catches real problems** — broken paths, wrong commands, stale references, contradictions across files
30
- - **Smart suggestions** — detects git renames and fuzzy-matches to suggest the right path
31
- - **Auto-fix** — `--fix` rewrites broken paths automatically using git history
32
- - **Token-aware** — shows how much context window your files consume and flags redundant content
33
- - **Every AI tool** — supports Claude Code, Cursor, Copilot, Windsurf, Gemini, Cline, Aider, and 9 more
34
- - **Multiple outputs** — text, JSON, and SARIF (GitHub Code Scanning)
35
- - **MCP server** — 7 tools for IDE/agent integration with tool annotations for auto-approval
36
- - **Watch mode** — `--watch` re-lints automatically when context files change
37
-
38
- ## Install
39
-
40
- Run directly (no install needed):
41
-
42
- ```bash
43
- npx @yawlabs/ctxlint
44
- ```
45
-
46
- ### Project install (recommended for teams)
47
-
48
- ```bash
49
- npm install -D @yawlabs/ctxlint
50
- # or
51
- pnpm add -D @yawlabs/ctxlint
52
- ```
53
-
54
- Then add to your `package.json` scripts:
55
-
56
- ```json
57
- {
58
- "scripts": {
59
- "lint:ctx": "ctxlint --strict"
60
- }
61
- }
62
- ```
63
-
64
- ### Global install
65
-
66
- ```bash
67
- npm install -g @yawlabs/ctxlint
68
- ```
69
-
70
- Useful if you want `ctxlint` available in every project without per-project setup.
71
-
72
- ## What It Checks
73
-
74
- | Check | What it finds |
75
- | --------------------- | --------------------------------------------------------------------------------------------- |
76
- | **Broken paths** | File references in context that don't exist in your project |
77
- | **Wrong commands** | Build/test commands that don't match your package.json scripts or Makefile targets |
78
- | **Stale context** | Context files not updated after recent code changes |
79
- | **Token waste** | How much context window your files consume per session |
80
- | **Redundancy** | Content the agent can already infer (e.g. "We use React" when react is in package.json) |
81
- | **Contradictions** | Conflicting directives across context files (e.g. "use Jest" in one, "use Vitest" in another) |
82
- | **Frontmatter** | Invalid or missing YAML frontmatter in Cursor .mdc, Copilot instructions, and Windsurf rules |
83
- | **CI coverage** | Release/deploy workflows in `.github/workflows/` not documented in any context file |
84
- | **CI secrets** | Secrets used in CI workflows (`${{ secrets.X }}`) not mentioned in context files |
85
- | **Missing secrets** | GitHub secrets set on sibling repos but missing from current project |
86
- | **Diverged configs** | Canonical config files (CI, tsconfig, etc.) drifting across sibling projects |
87
- | **Missing workflows** | GitHub Actions workflows present in 2+ siblings but absent here |
88
- | **Stale memory** | Claude Code memory entries referencing paths that no longer exist |
89
- | **Duplicate memory** | Near-duplicate memories across projects (>60% content overlap) |
90
- | **Loop detection** | Agent stuck in loops — repeated commands or cyclic patterns in session history |
91
-
92
- ## Supported Context Files
93
-
94
- | File | Tool |
95
- | ---------------------------------------------------------------------------------------------------- | --------------------------- |
96
- | `CLAUDE.md`, `CLAUDE.local.md`, `.claude/rules/*.md` | Claude Code |
97
- | `AGENTS.md`, `AGENT.md`, `AGENTS.override.md` | AAIF / Multi-agent standard |
98
- | `.cursorrules`, `.cursor/rules/*.md`, `.cursor/rules/*.mdc`, `.cursor/rules/*/RULE.md` | Cursor |
99
- | `.github/copilot-instructions.md`, `.github/instructions/*.md`, `.github/git-commit-instructions.md` | GitHub Copilot |
100
- | `.windsurfrules`, `.windsurf/rules/*.md` | Windsurf |
101
- | `GEMINI.md` | Gemini CLI |
102
- | `.clinerules` | Cline |
103
- | `.aiderules` | Aider |
104
- | `.aide/rules/*.md` | Aide / Codestory |
105
- | `.amazonq/rules/*.md` | Amazon Q Developer |
106
- | `.goose/instructions.md`, `.goosehints` | Goose by Block |
107
- | `.junie/guidelines.md`, `.junie/AGENTS.md` | JetBrains Junie |
108
- | `.aiassistant/rules/*.md` | JetBrains AI Assistant |
109
- | `.continuerules`, `.continue/rules/*.md` | Continue |
110
- | `.rules` | Zed |
111
- | `replit.md` | Replit |
112
-
113
- ## MCP Server Config Linting
114
-
115
- ctxlint also lints MCP server configuration files — the JSON configs that tell AI clients which tools to connect to. These are context interfaces too: they shape what your agent can do.
116
-
117
- ```bash
118
- # Lint context files + MCP configs
119
- npx @yawlabs/ctxlint --mcp
120
-
121
- # Lint only MCP configs
122
- npx @yawlabs/ctxlint --mcp-only
123
-
124
- # Include global/user-level configs (Claude Desktop, Cursor, Windsurf, etc.)
125
- npx @yawlabs/ctxlint --mcp-global
126
- ```
127
-
128
- ### What MCP config files are scanned
129
-
130
- | File | Client |
131
- | ----------------------------- | -------------------------------------- |
132
- | `.mcp.json` | Claude Code (universal project config) |
133
- | `.cursor/mcp.json` | Cursor |
134
- | `.vscode/mcp.json` | VS Code / GitHub Copilot |
135
- | `.amazonq/mcp.json` | Amazon Q Developer |
136
- | `.continue/mcpServers/*.json` | Continue |
137
-
138
- With `--mcp-global`, also scans Claude Desktop, Cursor, Windsurf, and Amazon Q global configs.
139
-
140
- ### What MCP config checks catch
141
-
142
- | Check | What it finds |
143
- | --------------- | -------------------------------------------------------------------------------------- |
144
- | **Schema** | Invalid JSON, wrong root key (`servers` vs `mcpServers`), missing required fields |
145
- | **Security** | Hardcoded API keys and Bearer tokens in git-tracked config files |
146
- | **Commands** | Missing `cmd /c` wrapper for npx on Windows, broken file paths in args |
147
- | **Deprecated** | SSE transport usage (deprecated March 2025, use Streamable HTTP) |
148
- | **Env vars** | Wrong env var syntax for the client (`${VAR}` vs `${env:VAR}` vs `${{ secrets.VAR }}`) |
149
- | **URLs** | Malformed URLs, localhost in project configs, missing path component |
150
- | **Consistency** | Same server configured differently across client configs |
151
- | **Redundancy** | Disabled servers, identical configs at multiple scopes |
152
-
153
- ### Example MCP config output
154
-
155
- ```
156
- MCP Configs
157
- .mcp.json
158
- ✗ mcp-security Server "api": hardcoded Bearer token in a git-tracked file
159
- ✗ mcp-deprecated Server "old-svc": SSE transport is deprecated — use "http"
160
- ✓ mcp-schema
161
- ✓ mcp-commands
162
- .cursor/mcp.json
163
- ✗ mcp-env Server "api": Cursor uses ${env:VAR}, not ${VAR}
164
- ✓ mcp-schema
165
- .vscode/mcp.json
166
- ✗ mcp-schema .vscode/mcp.json must use "servers" as root key, not "mcpServers"
167
-
168
- Cross-file
169
- ⚠ Server "api" is configured differently in .mcp.json and .cursor/mcp.json
170
- ℹ Server "db" is in .mcp.json but missing from .cursor/mcp.json
171
-
172
- Summary: 3 errors, 2 warnings, 1 info
173
- ```
174
-
175
- ### MCP Config Linting Specification
176
-
177
- The full specification for MCP config linting rules, the cross-client config landscape, and a machine-readable rule catalog are published as open specifications:
178
-
179
- - **[`MCP_CONFIG_LINT_SPEC.md`](./MCP_CONFIG_LINT_SPEC.md)** — 43 lint rules across 8 categories, the complete client/format reference, and implementation guidance. Tool-agnostic — any linter can implement it.
180
- - **[`mcp-config-lint-rules.json`](./mcp-config-lint-rules.json)** — Machine-readable rule catalog for programmatic consumption by AI agents, CI systems, and other tools.
181
-
182
- ## mcph Config Linting
183
-
184
- ctxlint also lints `.mcph.json` — the config file read by the [`@yawlabs/mcph`](https://github.com/YawLabs/mcph) CLI, which orchestrates MCP servers via the mcp.hosting registry. Distinct from `.mcp.json` (different schema, different threat model). Applies across the user-global (`~/.mcph.json`), per-project (`.mcph.json`), and machine-local (`.mcph.local.json`) scope cascade.
185
-
186
- ```bash
187
- # Lint context files + .mcph.json
188
- npx @yawlabs/ctxlint --mcph
189
-
190
- # Lint only .mcph.json
191
- npx @yawlabs/ctxlint --mcph-only
192
-
193
- # Include the user-global ~/.mcph.json
194
- npx @yawlabs/ctxlint --mcph-global
195
-
196
- # Treat any token in any .mcph.json as an error (env-var-only posture)
197
- npx @yawlabs/ctxlint --mcph --mcph-strict-env-token
198
- ```
199
-
200
- ### What mcph config checks catch
201
-
202
- | Check | What it finds |
203
- | --------------------------- | ----------------------------------------------------------------------------------------------------------------- |
204
- | **mcph-token-security** | mcp.hosting PAT (`mcp_pat_*`) leaks, malformed tokens, and prefers env-var (`MCPH_TOKEN`) over file-stored tokens |
205
- | **mcph-apibase** | Invalid `apiBase` URLs and plaintext HTTP to public hosts (private hosts like `localhost` / RFC 1918 are exempt) |
206
- | **mcph-schema-conformance** | Unknown / typo'd fields and stale `version` numbers vs the current `mcph.config.v1.json` schema |
207
- | **mcph-lists** | Conflicts (entries in both `servers` allow-list and `blocked` deny-list) and duplicates within either list |
208
- | **mcph-gitignore** | `.mcph.local.json` not covered by `.gitignore` — machine-local overrides exist precisely to stay machine-local |
209
-
210
- ## Session Linting
211
-
212
- ctxlint can audit AI agent session data — history files and memory entries — for cross-project consistency. Session checks compare your current project against sibling repos to catch drift and missing setup.
213
-
214
- ```bash
215
- # Lint context files + session data
216
- npx @yawlabs/ctxlint --session
217
-
218
- # Lint only session data
219
- npx @yawlabs/ctxlint --session-only
220
- ```
221
-
222
- Session checks are **opt-in** because they access files outside the project directory (agent history in your home directory, sibling repos in the parent directory).
223
-
224
- ### What session files are scanned
225
-
226
- | Agent | History | Memory |
227
- | ----------- | ------------------------- | ---------------------------------- |
228
- | Claude Code | `~/.claude/history.jsonl` | `~/.claude/projects/*/memory/*.md` |
229
- | Codex CLI | `~/.codex/history.jsonl` | — |
230
-
231
- ### What session checks catch
232
-
233
- | Check | What it finds |
234
- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
235
- | **Missing secrets** | `gh secret set` ran on 2+ sibling repos but not this one |
236
- | **Diverged configs** | Shared config files (CI workflows, tsconfig, .prettierrc, etc.) with 20-90% line overlap — enough to be related, different enough to be drifting |
237
- | **Missing workflows** | GitHub Actions workflows in 2+ siblings but absent from this project |
238
- | **Stale memory** | Memory entries referencing file paths that no longer exist |
239
- | **Duplicate memory** | Near-duplicate memory entries across projects (>60% overlap) |
240
- | **Loop detection** | Agent stuck in a loop — 3+ consecutive identical commands, or cyclic A,B,A,B patterns |
241
- | **Memory index overflow** | `MEMORY.md` exceeds Claude Code's documented 200-line / 25KB session-load cap, so entries past the cap are invisible to the agent |
242
-
243
- ### Session Linting Specification
244
-
245
- - **[`AGENT_SESSION_LINT_SPEC.md`](./AGENT_SESSION_LINT_SPEC.md)** — 8 lint rules, the agent session data landscape across 8 agents, sibling detection strategy, and implementation guidance.
246
- - **[`agent-session-lint-rules.json`](./agent-session-lint-rules.json)** — Machine-readable rule catalog.
247
-
248
- ## Example Output
249
-
250
- ```
251
- ctxlint v0.9.10
252
-
253
- Scanning /Users/you/my-app...
254
-
255
- Found 2 context files (1,847 tokens total)
256
- CLAUDE.md (1,203 tokens, 42 lines)
257
- AGENTS.md -> CLAUDE.md (symlink)
258
-
259
- CLAUDE.md
260
- ✗ Line 12: src/auth/middleware.ts does not exist
261
- → Did you mean src/middleware/auth.ts? (renamed 14 days ago)
262
- ✗ Line 8: "pnpm test" — script "test" not found in package.json
263
- ⚠ Last updated 47 days ago. src/routes/ has 8 commits since.
264
- ⚠ testing framework conflict: "Vitest" in CLAUDE.md vs "Jest" in AGENTS.md
265
- ℹ Line 3: "Express" is in package.json dependencies — agent can infer this
266
-
267
- Summary: 2 errors, 2 warnings, 1 info
268
- Token usage: 1,203 tokens per agent session
269
- Estimated waste: ~55 tokens (redundant content)
270
- ```
271
-
272
- ## Options
273
-
274
- ```
275
- Usage: ctxlint [options] [path]
276
-
277
- Arguments:
278
- path Project directory to scan (default: ".")
279
-
280
- Options:
281
- --strict Exit code 1 on any warning or error (for CI)
282
- --checks <list> Comma-separated checks to run (see below)
283
- --ignore <list> Comma-separated checks to skip
284
- --fix Auto-fix broken paths using git history and fuzzy matching
285
- --fix-dry-run Preview --fix changes without writing
286
- --yes Skip interactive confirmation prompts (required for --fix in TTY)
287
- --follow-symlinks Allow --fix to write through symlinks (default: skip)
288
- --format <fmt> Output format: text, json, or sarif (default: text)
289
- --tokens Show token breakdown per file
290
- --verbose Show passing checks too
291
- --quiet Suppress all output except errors (exit code only)
292
- --config <path> Path to config file (default: .ctxlintrc in project root)
293
- --depth <n> Max subdirectory depth to scan (default: 2)
294
- --mcp Enable MCP config linting alongside context file checks
295
- --mcp-only Run only MCP config checks, skip context file checks
296
- --mcp-global Also scan user/global MCP config files (implies --mcp)
297
- --mcph Enable .mcph.json (mcp.hosting CLI config) linting
298
- --mcph-only Run only mcph config checks
299
- --mcph-global Also scan ~/.mcph.json (implies --mcph)
300
- --mcph-strict-env-token Upgrade mcph-config/prefer-env-token from warning to error
301
- --session Enable session audit checks (cross-project consistency)
302
- --session-only Run only session checks, skip context and MCP checks
303
- --mcp-server Start the MCP server (alias: `serve` subcommand)
304
- --watch Re-lint on context file changes
305
- -V, --version Output the version number
306
- -h, --help Display help
307
-
308
- Commands:
309
- init Set up a git pre-commit hook
310
- ```
311
-
312
- **Available checks:** `paths`, `commands`, `staleness`, `tokens`, `tier-tokens`, `redundancy`, `contradictions`, `frontmatter`, `ci-coverage`, `ci-secrets`, `mcp-schema`, `mcp-security`, `mcp-commands`, `mcp-deprecated`, `mcp-env`, `mcp-urls`, `mcp-consistency`, `mcp-redundancy`, `mcph-token-security`, `mcph-apibase`, `mcph-schema-conformance`, `mcph-lists`, `mcph-gitignore`, `session-missing-secret`, `session-diverged-file`, `session-missing-workflow`, `session-stale-memory`, `session-duplicate-memory`, `session-loop-detection`, `session-memory-index-overflow`
313
-
314
- Passing any `mcp-*` check name implies `--mcp`. Passing any `mcph-*` check name implies `--mcph`. Passing any `session-*` check name implies `--session`.
315
-
316
- ## Watch Mode
317
-
318
- ```bash
319
- npx @yawlabs/ctxlint --watch
320
- ```
321
-
322
- Re-lints automatically when any context file, MCP config, or `package.json` changes. Useful during development when you're editing context files alongside code.
323
-
324
- ## Use in CI
325
-
326
- ```yaml
327
- - name: Lint context files
328
- run: npx @yawlabs/ctxlint --strict
329
- ```
330
-
331
- ### Exit Codes
332
-
333
- | Code | Meaning |
334
- | ---- | -------------------------------------------------------------------- |
335
- | `0` | Success — no issues, or issues below the strict threshold |
336
- | `1` | Strict mode caught at least one error or warning (`--strict` is set) |
337
- | `2` | Config error, invalid CLI option, or internal failure |
338
-
339
- In non-strict mode ctxlint always exits `0` — it's a reporting tool by default. Pass `--strict` to enforce in CI.
340
-
341
- ### GitHub Action
342
-
343
- ```yaml
344
- - name: Lint context files
345
- uses: yawlabs/ctxlint-action@v1
346
- ```
347
-
348
- Or with options:
349
-
350
- ```yaml
351
- - name: Lint context files
352
- uses: yawlabs/ctxlint-action@v1
353
- with:
354
- args: '--strict --mcp'
355
- ```
356
-
357
- ### SARIF Output (GitHub Code Scanning)
358
-
359
- ```yaml
360
- - name: Lint context files
361
- run: npx @yawlabs/ctxlint --format sarif > ctxlint.sarif
362
-
363
- - name: Upload SARIF
364
- uses: github/codeql-action/upload-sarif@v3
365
- with:
366
- sarif_file: ctxlint.sarif
367
- ```
368
-
369
- ## Auto-fix
370
-
371
- ```bash
372
- npx @yawlabs/ctxlint --fix
373
- ```
374
-
375
- When a broken path was renamed in git or has a close match in the project, `--fix` rewrites the context file automatically.
376
-
377
- ## Pre-commit Hook
378
-
379
- ### Built-in
380
-
381
- ```bash
382
- npx @yawlabs/ctxlint init
383
- ```
384
-
385
- Sets up a git pre-commit hook that runs `ctxlint --strict` before each commit.
386
-
387
- ### pre-commit framework
388
-
389
- Add to your `.pre-commit-config.yaml`:
390
-
391
- ```yaml
392
- repos:
393
- - repo: https://github.com/yawlabs/ctxlint
394
- rev: v0.9.10
395
- hooks:
396
- - id: ctxlint
397
- ```
398
-
399
- ## Config File
400
-
401
- Create a `.ctxlintrc` or `.ctxlintrc.json` in your project root:
402
-
403
- ```json
404
- {
405
- "checks": ["paths", "commands", "tokens", "contradictions", "frontmatter"],
406
- "ignore": ["redundancy"],
407
- "strict": true,
408
- "tokenThresholds": {
409
- "info": 500,
410
- "warning": 2000,
411
- "error": 5000,
412
- "aggregate": 4000,
413
- "tierBreakdown": 1000,
414
- "tierAggregate": 4000
415
- },
416
- "contextFiles": ["CONVENTIONS.md", "docs/ai-rules.md"]
417
- }
418
- ```
419
-
420
- The `contextFiles` array adds custom file patterns to scan alongside the built-in list. Useful for project-specific context files like `CONVENTIONS.md`.
421
-
422
- ### Config Reference
423
-
424
- | Field | Type | Default | Meaning |
425
- | ------------------------------- | ---------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
426
- | `checks` | `string[]` | all checks | Checks to run. Check names include `paths`, `commands`, `tokens`, `tier-tokens`, `redundancy`, `contradictions`, `frontmatter`, `staleness`, `ci-coverage`, `ci-secrets`, plus any `mcp-*` / `session-*`. |
427
- | `ignore` | `string[]` | `[]` | Checks to skip, evaluated after `checks`. |
428
- | `strict` | `boolean` | `false` | Exit non-zero on any warning or error. |
429
- | `tokenThresholds` | `object` | see below | Per-file and cross-file token thresholds. |
430
- | `tokenThresholds.info` | `number` | `1000` | Per-file info threshold for `tokens/info`. |
431
- | `tokenThresholds.warning` | `number` | `3000` | Per-file warning threshold for `tokens/large`. |
432
- | `tokenThresholds.error` | `number` | `8000` | Per-file error threshold for `tokens/excessive`. |
433
- | `tokenThresholds.aggregate` | `number` | `5000` | Cross-file total threshold for `tokens/aggregate`. |
434
- | `tokenThresholds.tierBreakdown` | `number` | `1000` | Always-loaded file threshold for `tier-tokens/section-breakdown`. |
435
- | `tokenThresholds.tierAggregate` | `number` | `4000` | Combined always-loaded threshold for `tier-tokens/aggregate`. |
436
- | `contextFiles` | `string[]` | `[]` | Extra glob patterns to scan alongside the built-in list. |
437
- | `mcp` | `boolean` | `false` | Enable MCP config checks by default (same as `--mcp`). |
438
- | `mcpOnly` | `boolean` | `false` | Run only MCP config checks, skip context-file checks (same as `--mcp-only`). |
439
- | `mcpGlobal` | `boolean` | `false` | Also scan user/global MCP configs (same as `--mcp-global`). |
440
- | `mcph` | `boolean` | `false` | Enable `.mcph.json` (mcp.hosting CLI config) checks (same as `--mcph`). |
441
- | `mcphOnly` | `boolean` | `false` | Run only mcph config checks, skip context-file checks (same as `--mcph-only`). |
442
- | `mcphGlobal` | `boolean` | `false` | Also scan `~/.mcph.json` user-global config (same as `--mcph-global`). |
443
- | `mcphStrictEnvToken` | `boolean` | `false` | Upgrade `mcph-config/prefer-env-token` from warning to error (same as `--mcph-strict-env-token`). |
444
- | `session` | `boolean` | `false` | Enable session audit checks (cross-project consistency); same as `--session`. |
445
- | `sessionOnly` | `boolean` | `false` | Run only session checks, skip context and MCP checks (same as `--session-only`). |
446
-
447
- Config file resolution order: `.ctxlintrc` → `.ctxlintrc.json` in the project root. Use `--config <path>` to point elsewhere. CLI flags override config fields.
448
-
449
- CLI flags override config file settings. Use `--config <path>` to load a config from a custom location.
450
-
451
- ## Use as MCP Server
452
-
453
- ctxlint ships with an MCP server that exposes seven tools (`ctxlint_audit`, `ctxlint_mcp_audit`, `ctxlint_mcph_audit`, `ctxlint_session_audit`, `ctxlint_validate_path`, `ctxlint_token_report`, `ctxlint_fix`). All read-only tools declare annotations so MCP clients can skip confirmation dialogs.
454
-
455
- Launch it with the `serve` subcommand (or the equivalent `--mcp-server` flag, kept for back-compat):
456
-
457
- ```bash
458
- npx -y @yawlabs/ctxlint serve
459
- ```
460
-
461
- ### With Claude Code
462
-
463
- ```bash
464
- claude mcp add ctxlint -- npx -y @yawlabs/ctxlint serve
465
- ```
466
-
467
- ### With `.mcp.json` (Claude Code project config, Cursor, Windsurf)
468
-
469
- Create `.mcp.json` in your project root:
470
-
471
- macOS / Linux / WSL:
472
-
473
- ```json
474
- {
475
- "mcpServers": {
476
- "ctxlint": {
477
- "command": "npx",
478
- "args": ["-y", "@yawlabs/ctxlint", "serve"]
479
- }
480
- }
481
- }
482
- ```
483
-
484
- Windows:
485
-
486
- ```json
487
- {
488
- "mcpServers": {
489
- "ctxlint": {
490
- "command": "cmd",
491
- "args": ["/c", "npx", "-y", "@yawlabs/ctxlint", "serve"]
492
- }
493
- }
494
- }
495
- ```
496
-
497
- > **Tip:** This file is safe to commit — it contains no secrets.
498
-
499
- ### With VS Code / GitHub Copilot
500
-
501
- Add to `.vscode/mcp.json`:
502
-
503
- ```json
504
- {
505
- "servers": {
506
- "ctxlint": {
507
- "command": "npx",
508
- "args": ["-y", "@yawlabs/ctxlint", "serve"]
509
- }
510
- }
511
- }
512
- ```
513
-
514
- ### With Claude Desktop
515
-
516
- Add to your Claude Desktop config (`claude_desktop_config.json`):
517
-
518
- ```json
519
- {
520
- "mcpServers": {
521
- "ctxlint": {
522
- "command": "npx",
523
- "args": ["-y", "@yawlabs/ctxlint", "serve"]
524
- }
525
- }
526
- }
527
- ```
528
-
529
- ## JSON Output
530
-
531
- ```bash
532
- npx @yawlabs/ctxlint --format json
533
- ```
534
-
535
- Returns structured JSON with all file results, issues, and summary — useful for building integrations or dashboards.
536
-
537
- ## Specifications
538
-
539
- ctxlint is the reference implementation of three open specifications for linting AI agent interfaces. These specs are tool-agnostic — any linter, IDE extension, or CI system can implement them.
540
-
541
- | Spec | What it covers |
542
- | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
543
- | **[AI Context File Linting Spec](./CONTEXT_LINT_SPEC.md)** | 19 rules for validating context files (CLAUDE.md, .cursorrules, AGENTS.md, etc.) across 17 clients. Covers file formats, frontmatter schemas, path/command validation, staleness, token budgets, redundancy, and contradictions. |
544
- | **[MCP Config Linting Spec](./MCP_CONFIG_LINT_SPEC.md)** | 43 rules for validating MCP server configs (.mcp.json, .cursor/mcp.json, .vscode/mcp.json, etc.) across 8 clients. Covers schema validation, hardcoded secrets, env var syntax, deprecated transports, and cross-file consistency. |
545
- | **mcph Config Linting** (`mcph-config-lint-rules.json`) | 10 rules for validating `.mcph.json` — the config file read by the `@yawlabs/mcph` CLI. Covers PAT format + leakage, env-var posture, plaintext API endpoints, schema drift, and allow/deny list semantics across the scope cascade. |
546
- | **[Agent Session Linting Spec](./AGENT_SESSION_LINT_SPEC.md)** | 7 rules for auditing agent session data (history, memory) across 8 agents. Covers cross-project secret consistency, config drift, stale memory, and loop detection. |
547
-
548
- All specs include machine-readable rule catalogs for programmatic consumption:
549
-
550
- - [`context-lint-rules.json`](./context-lint-rules.json) — context file rules and 16 supported format definitions
551
- - [`mcp-config-lint-rules.json`](./mcp-config-lint-rules.json) — MCP config rules and 8 client definitions
552
- - [`mcph-config-lint-rules.json`](./mcph-config-lint-rules.json) — mcph CLI config rules (`.mcph.json`)
553
- - [`agent-session-lint-rules.json`](./agent-session-lint-rules.json) — session lint rules and 8 agent data source definitions
554
-
555
- ## Also By Yaw Labs
556
-
557
- - [Yaw](https://yaw.sh) — The AI-native terminal
558
- - [mcp.hosting](https://mcp.hosting) — MCP server proxy platform
559
- - [Spend](https://spend.sh) — AI spend tracking, cost estimation, and provider comparison across 10+ providers
560
- - [Token Limit News](https://tokenlimit.news) — Weekly AI dev tooling newsletter
561
-
562
- ## License
563
-
564
- MIT
1
+ # ctxlint
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@yawlabs/ctxlint)](https://www.npmjs.com/package/@yawlabs/ctxlint)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
+ [![GitHub stars](https://img.shields.io/github/stars/YawLabs/ctxlint)](https://github.com/YawLabs/ctxlint/stargazers)
6
+ [![CI](https://github.com/YawLabs/ctxlint/actions/workflows/ci.yml/badge.svg)](https://github.com/YawLabs/ctxlint/actions/workflows/ci.yml)
7
+ [![Release](https://github.com/YawLabs/ctxlint/actions/workflows/release.yml/badge.svg)](https://github.com/YawLabs/ctxlint/actions/workflows/release.yml)
8
+ [![MCP Compliance](https://raw.githubusercontent.com/YawLabs/ctxlint/main/compliance-badge.svg)](https://github.com/YawLabs/mcp-compliance)
9
+
10
+ **Lint your AI agent context files, MCP server configs, and session data against your actual codebase.** Context linting + MCP config linting + session auditing. 16 AI tools, 8 MCP clients, cross-project consistency, auto-fix. Works as a CLI, CI step, pre-commit hook, or MCP server.
11
+
12
+ Your `CLAUDE.md` is lying to your agent. Your `.mcp.json` has a hardcoded API key. ctxlint catches both.
13
+
14
+ [![Add to Yaw MCP](https://yaw.sh/yaw-mcp-button.svg)](yaw://install?name=ctxlint&command=npx&args=-y%2C%40yawlabs%2Fctxlint%2Cserve&description=Lint%20AI%20agent%20context%20files%20and%20MCP%20configs%20against%20your%20codebase&source=https%3A%2F%2Fgithub.com%2FYawLabs%2Fctxlint)
15
+
16
+ One click adds this to your local Yaw MCP config so it's available in every Yaw Terminal session. Or install manually below.
17
+
18
+ ## Why ctxlint?
19
+
20
+ Every AI coding tool ships a context file: `CLAUDE.md`, `.cursorrules`, `AGENTS.md`, `.mcp.json`. These files are the single most important interface between you and your agent — they tell it what to build, how to test, where things live.
21
+
22
+ But context files rot fast. You rename a file, change a build script, or switch from Jest to Vitest — and your `CLAUDE.md` still says the old thing. Your agent follows those stale instructions faithfully, then fails. You lose 10 minutes debugging what turns out to be a wrong path in line 12 of a markdown file.
23
+
24
+ Multiply that across a team with 5 context files, 3 MCP configs, and 2 people who touched the build system last week — and you have a real problem with no existing solution.
25
+
26
+ ctxlint is a linter purpose-built for this. It reads your context files, cross-references them against your actual codebase, and catches the drift before your agent does.
27
+
28
+ - **Instant startup** — ships as a single self-contained bundle with zero runtime dependencies. `npx` downloads a ~400 KB tarball and starts immediately
29
+ - **Catches real problems** — broken paths, wrong commands, stale references, contradictions across files
30
+ - **Smart suggestions** — detects git renames and fuzzy-matches to suggest the right path
31
+ - **Auto-fix** — `--fix` rewrites broken paths automatically using git history
32
+ - **Token-aware** — shows how much context window your files consume and flags redundant content
33
+ - **Every AI tool** — supports Claude Code, Cursor, Copilot, Windsurf, Gemini, Cline, Aider, and 9 more
34
+ - **Multiple outputs** — text, JSON, and SARIF (GitHub Code Scanning)
35
+ - **MCP server** — 7 tools for IDE/agent integration with tool annotations for auto-approval
36
+ - **Watch mode** — `--watch` re-lints automatically when context files change
37
+
38
+ ## Install
39
+
40
+ Run directly (no install needed):
41
+
42
+ ```bash
43
+ npx -y @yawlabs/ctxlint@latest
44
+ ```
45
+
46
+ ### Project install (recommended for teams)
47
+
48
+ ```bash
49
+ npm install -D @yawlabs/ctxlint
50
+ # or
51
+ pnpm add -D @yawlabs/ctxlint
52
+ ```
53
+
54
+ Then add to your `package.json` scripts:
55
+
56
+ ```json
57
+ {
58
+ "scripts": {
59
+ "lint:ctx": "ctxlint --strict"
60
+ }
61
+ }
62
+ ```
63
+
64
+ ### Global install
65
+
66
+ ```bash
67
+ npm install -g @yawlabs/ctxlint
68
+ ```
69
+
70
+ Useful if you want `ctxlint` available in every project without per-project setup.
71
+
72
+ ## What It Checks
73
+
74
+ | Check | What it finds |
75
+ | --------------------- | --------------------------------------------------------------------------------------------- |
76
+ | **Broken paths** | File references in context that don't exist in your project |
77
+ | **Wrong commands** | Build/test commands that don't match your package.json scripts or Makefile targets |
78
+ | **Stale context** | Context files not updated after recent code changes |
79
+ | **Token waste** | How much context window your files consume per session |
80
+ | **Redundancy** | Content the agent can already infer (e.g. "We use React" when react is in package.json) |
81
+ | **Contradictions** | Conflicting directives across context files (e.g. "use Jest" in one, "use Vitest" in another) |
82
+ | **Frontmatter** | Invalid or missing YAML frontmatter in Cursor .mdc, Copilot instructions, and Windsurf rules |
83
+ | **CI coverage** | Release/deploy workflows in `.github/workflows/` not documented in any context file |
84
+ | **CI secrets** | Secrets used in CI workflows (`${{ secrets.X }}`) not mentioned in context files |
85
+ | **Missing secrets** | GitHub secrets set on sibling repos but missing from current project |
86
+ | **Diverged configs** | Canonical config files (CI, tsconfig, etc.) drifting across sibling projects |
87
+ | **Missing workflows** | GitHub Actions workflows present in 2+ siblings but absent here |
88
+ | **Stale memory** | Claude Code memory entries referencing paths that no longer exist |
89
+ | **Duplicate memory** | Near-duplicate memories across projects (>60% content overlap) |
90
+ | **Loop detection** | Agent stuck in loops — repeated commands or cyclic patterns in session history |
91
+
92
+ ## Supported Context Files
93
+
94
+ | File | Tool |
95
+ | ---------------------------------------------------------------------------------------------------- | --------------------------- |
96
+ | `CLAUDE.md`, `CLAUDE.local.md`, `.claude/rules/*.md` | Claude Code |
97
+ | `AGENTS.md`, `AGENT.md`, `AGENTS.override.md` | AAIF / Multi-agent standard |
98
+ | `.cursorrules`, `.cursor/rules/*.md`, `.cursor/rules/*.mdc`, `.cursor/rules/*/RULE.md` | Cursor |
99
+ | `.github/copilot-instructions.md`, `.github/instructions/*.md`, `.github/git-commit-instructions.md` | GitHub Copilot |
100
+ | `.windsurfrules`, `.windsurf/rules/*.md` | Windsurf |
101
+ | `GEMINI.md` | Gemini CLI |
102
+ | `.clinerules` | Cline |
103
+ | `.aiderules` | Aider |
104
+ | `.aide/rules/*.md` | Aide / Codestory |
105
+ | `.amazonq/rules/*.md` | Amazon Q Developer |
106
+ | `.goose/instructions.md`, `.goosehints` | Goose by Block |
107
+ | `.junie/guidelines.md`, `.junie/AGENTS.md` | JetBrains Junie |
108
+ | `.aiassistant/rules/*.md` | JetBrains AI Assistant |
109
+ | `.continuerules`, `.continue/rules/*.md` | Continue |
110
+ | `.rules` | Zed |
111
+ | `replit.md` | Replit |
112
+
113
+ ## MCP Server Config Linting
114
+
115
+ ctxlint also lints MCP server configuration files — the JSON configs that tell AI clients which tools to connect to. These are context interfaces too: they shape what your agent can do.
116
+
117
+ ```bash
118
+ # Lint context files + MCP configs
119
+ npx @yawlabs/ctxlint@latest --mcp
120
+
121
+ # Lint only MCP configs
122
+ npx @yawlabs/ctxlint@latest --mcp-only
123
+
124
+ # Include global/user-level configs (Claude Desktop, Cursor, Windsurf, etc.)
125
+ npx @yawlabs/ctxlint@latest --mcp-global
126
+ ```
127
+
128
+ ### What MCP config files are scanned
129
+
130
+ | File | Client |
131
+ | ----------------------------- | -------------------------------------- |
132
+ | `.mcp.json` | Claude Code (universal project config) |
133
+ | `.cursor/mcp.json` | Cursor |
134
+ | `.vscode/mcp.json` | VS Code / GitHub Copilot |
135
+ | `.amazonq/mcp.json` | Amazon Q Developer |
136
+ | `.continue/mcpServers/*.json` | Continue |
137
+
138
+ With `--mcp-global`, also scans Claude Desktop, Cursor, Windsurf, and Amazon Q global configs.
139
+
140
+ ### What MCP config checks catch
141
+
142
+ | Check | What it finds |
143
+ | --------------- | -------------------------------------------------------------------------------------- |
144
+ | **Schema** | Invalid JSON, wrong root key (`servers` vs `mcpServers`), missing required fields |
145
+ | **Security** | Hardcoded API keys and Bearer tokens in git-tracked config files |
146
+ | **Commands** | Missing `cmd /c` wrapper for npx on Windows, broken file paths in args |
147
+ | **Deprecated** | SSE transport usage (deprecated March 2025, use Streamable HTTP) |
148
+ | **Env vars** | Wrong env var syntax for the client (`${VAR}` vs `${env:VAR}` vs `${{ secrets.VAR }}`) |
149
+ | **URLs** | Malformed URLs, localhost in project configs, missing path component |
150
+ | **Consistency** | Same server configured differently across client configs |
151
+ | **Redundancy** | Disabled servers, identical configs at multiple scopes |
152
+
153
+ ### Example MCP config output
154
+
155
+ ```
156
+ MCP Configs
157
+ .mcp.json
158
+ ✗ mcp-security Server "api": hardcoded Bearer token in a git-tracked file
159
+ ✗ mcp-deprecated Server "old-svc": SSE transport is deprecated — use "http"
160
+ ✓ mcp-schema
161
+ ✓ mcp-commands
162
+ .cursor/mcp.json
163
+ ✗ mcp-env Server "api": Cursor uses ${env:VAR}, not ${VAR}
164
+ ✓ mcp-schema
165
+ .vscode/mcp.json
166
+ ✗ mcp-schema .vscode/mcp.json must use "servers" as root key, not "mcpServers"
167
+
168
+ Cross-file
169
+ ⚠ Server "api" is configured differently in .mcp.json and .cursor/mcp.json
170
+ ℹ Server "db" is in .mcp.json but missing from .cursor/mcp.json
171
+
172
+ Summary: 3 errors, 2 warnings, 1 info
173
+ ```
174
+
175
+ ### MCP Config Linting Specification
176
+
177
+ The full specification for MCP config linting rules, the cross-client config landscape, and a machine-readable rule catalog are published as open specifications:
178
+
179
+ - **[`MCP_CONFIG_LINT_SPEC.md`](./MCP_CONFIG_LINT_SPEC.md)** — 43 lint rules across 8 categories, the complete client/format reference, and implementation guidance. Tool-agnostic — any linter can implement it.
180
+ - **[`mcp-config-lint-rules.json`](./mcp-config-lint-rules.json)** — Machine-readable rule catalog for programmatic consumption by AI agents, CI systems, and other tools.
181
+
182
+ ## mcph Config Linting
183
+
184
+ ctxlint also lints `.mcph.json` — the config file read by the [`@yawlabs/mcph`](https://github.com/YawLabs/mcph) CLI, which orchestrates MCP servers via the mcp.hosting registry. Distinct from `.mcp.json` (different schema, different threat model). Applies across the user-global (`~/.mcph.json`), per-project (`.mcph.json`), and machine-local (`.mcph.local.json`) scope cascade.
185
+
186
+ ```bash
187
+ # Lint context files + .mcph.json
188
+ npx @yawlabs/ctxlint@latest --mcph
189
+
190
+ # Lint only .mcph.json
191
+ npx @yawlabs/ctxlint@latest --mcph-only
192
+
193
+ # Include the user-global ~/.mcph.json
194
+ npx @yawlabs/ctxlint@latest --mcph-global
195
+
196
+ # Treat any token in any .mcph.json as an error (env-var-only posture)
197
+ npx @yawlabs/ctxlint@latest --mcph --mcph-strict-env-token
198
+ ```
199
+
200
+ ### What mcph config checks catch
201
+
202
+ | Check | What it finds |
203
+ | --------------------------- | ----------------------------------------------------------------------------------------------------------------- |
204
+ | **mcph-token-security** | mcp.hosting PAT (`mcp_pat_*`) leaks, malformed tokens, and prefers env-var (`MCPH_TOKEN`) over file-stored tokens |
205
+ | **mcph-apibase** | Invalid `apiBase` URLs and plaintext HTTP to public hosts (private hosts like `localhost` / RFC 1918 are exempt) |
206
+ | **mcph-schema-conformance** | Unknown / typo'd fields and stale `version` numbers vs the current `mcph.config.v1.json` schema |
207
+ | **mcph-lists** | Conflicts (entries in both `servers` allow-list and `blocked` deny-list) and duplicates within either list |
208
+ | **mcph-gitignore** | `.mcph.local.json` not covered by `.gitignore` — machine-local overrides exist precisely to stay machine-local |
209
+
210
+ ## Session Linting
211
+
212
+ ctxlint can audit AI agent session data — history files and memory entries — for cross-project consistency. Session checks compare your current project against sibling repos to catch drift and missing setup.
213
+
214
+ ```bash
215
+ # Lint context files + session data
216
+ npx @yawlabs/ctxlint@latest --session
217
+
218
+ # Lint only session data
219
+ npx @yawlabs/ctxlint@latest --session-only
220
+ ```
221
+
222
+ Session checks are **opt-in** because they access files outside the project directory (agent history in your home directory, sibling repos in the parent directory).
223
+
224
+ ### What session files are scanned
225
+
226
+ | Agent | History | Memory |
227
+ | ----------- | ------------------------- | ---------------------------------- |
228
+ | Claude Code | `~/.claude/history.jsonl` | `~/.claude/projects/*/memory/*.md` |
229
+ | Codex CLI | `~/.codex/history.jsonl` | — |
230
+
231
+ ### What session checks catch
232
+
233
+ | Check | What it finds |
234
+ | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
235
+ | **Missing secrets** | `gh secret set` ran on 2+ sibling repos but not this one |
236
+ | **Diverged configs** | Shared config files (CI workflows, tsconfig, .prettierrc, etc.) with 20-90% line overlap — enough to be related, different enough to be drifting |
237
+ | **Missing workflows** | GitHub Actions workflows in 2+ siblings but absent from this project |
238
+ | **Stale memory** | Memory entries referencing file paths that no longer exist |
239
+ | **Duplicate memory** | Near-duplicate memory entries across projects (>60% overlap) |
240
+ | **Loop detection** | Agent stuck in a loop — 3+ consecutive identical commands, or cyclic A,B,A,B patterns |
241
+ | **Memory index overflow** | `MEMORY.md` exceeds Claude Code's documented 200-line / 25KB session-load cap, so entries past the cap are invisible to the agent |
242
+
243
+ ### Session Linting Specification
244
+
245
+ - **[`AGENT_SESSION_LINT_SPEC.md`](./AGENT_SESSION_LINT_SPEC.md)** — 8 lint rules, the agent session data landscape across 8 agents, sibling detection strategy, and implementation guidance.
246
+ - **[`agent-session-lint-rules.json`](./agent-session-lint-rules.json)** — Machine-readable rule catalog.
247
+
248
+ ## Example Output
249
+
250
+ ```
251
+ ctxlint v0.9.10
252
+
253
+ Scanning /Users/you/my-app...
254
+
255
+ Found 2 context files (1,847 tokens total)
256
+ CLAUDE.md (1,203 tokens, 42 lines)
257
+ AGENTS.md -> CLAUDE.md (symlink)
258
+
259
+ CLAUDE.md
260
+ ✗ Line 12: src/auth/middleware.ts does not exist
261
+ → Did you mean src/middleware/auth.ts? (renamed 14 days ago)
262
+ ✗ Line 8: "pnpm test" — script "test" not found in package.json
263
+ ⚠ Last updated 47 days ago. src/routes/ has 8 commits since.
264
+ ⚠ testing framework conflict: "Vitest" in CLAUDE.md vs "Jest" in AGENTS.md
265
+ ℹ Line 3: "Express" is in package.json dependencies — agent can infer this
266
+
267
+ Summary: 2 errors, 2 warnings, 1 info
268
+ Token usage: 1,203 tokens per agent session
269
+ Estimated waste: ~55 tokens (redundant content)
270
+ ```
271
+
272
+ ## Options
273
+
274
+ ```
275
+ Usage: ctxlint [options] [path]
276
+
277
+ Arguments:
278
+ path Project directory to scan (default: ".")
279
+
280
+ Options:
281
+ --strict Exit code 1 on any warning or error (for CI)
282
+ --checks <list> Comma-separated checks to run (see below)
283
+ --ignore <list> Comma-separated checks to skip
284
+ --fix Auto-fix broken paths using git history and fuzzy matching
285
+ --fix-dry-run Preview --fix changes without writing
286
+ --yes Skip interactive confirmation prompts (required for --fix in TTY)
287
+ --follow-symlinks Allow --fix to write through symlinks (default: skip)
288
+ --format <fmt> Output format: text, json, or sarif (default: text)
289
+ --tokens Show token breakdown per file
290
+ --verbose Show passing checks too
291
+ --quiet Suppress all output except errors (exit code only)
292
+ --config <path> Path to config file (default: .ctxlintrc in project root)
293
+ --depth <n> Max subdirectory depth to scan (default: 2)
294
+ --mcp Enable MCP config linting alongside context file checks
295
+ --mcp-only Run only MCP config checks, skip context file checks
296
+ --mcp-global Also scan user/global MCP config files (implies --mcp)
297
+ --mcph Enable .mcph.json (mcp.hosting CLI config) linting
298
+ --mcph-only Run only mcph config checks
299
+ --mcph-global Also scan ~/.mcph.json (implies --mcph)
300
+ --mcph-strict-env-token Upgrade mcph-config/prefer-env-token from warning to error
301
+ --session Enable session audit checks (cross-project consistency)
302
+ --session-only Run only session checks, skip context and MCP checks
303
+ --mcp-server Start the MCP server (alias: `serve` subcommand)
304
+ --watch Re-lint on context file changes
305
+ -V, --version Output the version number
306
+ -h, --help Display help
307
+
308
+ Commands:
309
+ init Set up a git pre-commit hook
310
+ ```
311
+
312
+ **Available checks:** `paths`, `commands`, `staleness`, `tokens`, `tier-tokens`, `redundancy`, `contradictions`, `frontmatter`, `ci-coverage`, `ci-secrets`, `mcp-schema`, `mcp-security`, `mcp-commands`, `mcp-deprecated`, `mcp-env`, `mcp-urls`, `mcp-consistency`, `mcp-redundancy`, `mcph-token-security`, `mcph-apibase`, `mcph-schema-conformance`, `mcph-lists`, `mcph-gitignore`, `session-missing-secret`, `session-diverged-file`, `session-missing-workflow`, `session-stale-memory`, `session-duplicate-memory`, `session-loop-detection`, `session-memory-index-overflow`
313
+
314
+ Passing any `mcp-*` check name implies `--mcp`. Passing any `mcph-*` check name implies `--mcph`. Passing any `session-*` check name implies `--session`.
315
+
316
+ ## Watch Mode
317
+
318
+ ```bash
319
+ npx @yawlabs/ctxlint@latest --watch
320
+ ```
321
+
322
+ Re-lints automatically when any context file, MCP config, or `package.json` changes. Useful during development when you're editing context files alongside code.
323
+
324
+ ## Use in CI
325
+
326
+ ```yaml
327
+ - name: Lint context files
328
+ run: npx @yawlabs/ctxlint@latest --strict
329
+ ```
330
+
331
+ ### Exit Codes
332
+
333
+ | Code | Meaning |
334
+ | ---- | -------------------------------------------------------------------- |
335
+ | `0` | Success — no issues, or issues below the strict threshold |
336
+ | `1` | Strict mode caught at least one error or warning (`--strict` is set) |
337
+ | `2` | Config error, invalid CLI option, or internal failure |
338
+
339
+ In non-strict mode ctxlint always exits `0` — it's a reporting tool by default. Pass `--strict` to enforce in CI.
340
+
341
+ ### GitHub Action
342
+
343
+ ```yaml
344
+ - name: Lint context files
345
+ uses: yawlabs/ctxlint-action@v1
346
+ ```
347
+
348
+ Or with options:
349
+
350
+ ```yaml
351
+ - name: Lint context files
352
+ uses: yawlabs/ctxlint-action@v1
353
+ with:
354
+ args: '--strict --mcp'
355
+ ```
356
+
357
+ ### SARIF Output (GitHub Code Scanning)
358
+
359
+ ```yaml
360
+ - name: Lint context files
361
+ run: npx @yawlabs/ctxlint@latest --format sarif > ctxlint.sarif
362
+
363
+ - name: Upload SARIF
364
+ uses: github/codeql-action/upload-sarif@v3
365
+ with:
366
+ sarif_file: ctxlint.sarif
367
+ ```
368
+
369
+ ## Auto-fix
370
+
371
+ ```bash
372
+ npx @yawlabs/ctxlint@latest --fix
373
+ ```
374
+
375
+ When a broken path was renamed in git or has a close match in the project, `--fix` rewrites the context file automatically.
376
+
377
+ ## Pre-commit Hook
378
+
379
+ ### Built-in
380
+
381
+ ```bash
382
+ npx @yawlabs/ctxlint@latest init
383
+ ```
384
+
385
+ Sets up a git pre-commit hook that runs `ctxlint --strict` before each commit.
386
+
387
+ ### pre-commit framework
388
+
389
+ Add to your `.pre-commit-config.yaml`:
390
+
391
+ ```yaml
392
+ repos:
393
+ - repo: https://github.com/yawlabs/ctxlint
394
+ rev: v0.9.10
395
+ hooks:
396
+ - id: ctxlint
397
+ ```
398
+
399
+ ## Config File
400
+
401
+ Create a `.ctxlintrc` or `.ctxlintrc.json` in your project root:
402
+
403
+ ```json
404
+ {
405
+ "checks": ["paths", "commands", "tokens", "contradictions", "frontmatter"],
406
+ "ignore": ["redundancy"],
407
+ "strict": true,
408
+ "tokenThresholds": {
409
+ "info": 500,
410
+ "warning": 2000,
411
+ "error": 5000,
412
+ "aggregate": 4000,
413
+ "tierBreakdown": 1000,
414
+ "tierAggregate": 4000
415
+ },
416
+ "contextFiles": ["CONVENTIONS.md", "docs/ai-rules.md"]
417
+ }
418
+ ```
419
+
420
+ The `contextFiles` array adds custom file patterns to scan alongside the built-in list. Useful for project-specific context files like `CONVENTIONS.md`.
421
+
422
+ ### Config Reference
423
+
424
+ | Field | Type | Default | Meaning |
425
+ | ------------------------------- | ---------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
426
+ | `checks` | `string[]` | all checks | Checks to run. Check names include `paths`, `commands`, `tokens`, `tier-tokens`, `redundancy`, `contradictions`, `frontmatter`, `staleness`, `ci-coverage`, `ci-secrets`, plus any `mcp-*` / `session-*`. |
427
+ | `ignore` | `string[]` | `[]` | Checks to skip, evaluated after `checks`. |
428
+ | `strict` | `boolean` | `false` | Exit non-zero on any warning or error. |
429
+ | `tokenThresholds` | `object` | see below | Per-file and cross-file token thresholds. |
430
+ | `tokenThresholds.info` | `number` | `1000` | Per-file info threshold for `tokens/info`. |
431
+ | `tokenThresholds.warning` | `number` | `3000` | Per-file warning threshold for `tokens/large`. |
432
+ | `tokenThresholds.error` | `number` | `8000` | Per-file error threshold for `tokens/excessive`. |
433
+ | `tokenThresholds.aggregate` | `number` | `5000` | Cross-file total threshold for `tokens/aggregate`. |
434
+ | `tokenThresholds.tierBreakdown` | `number` | `1000` | Always-loaded file threshold for `tier-tokens/section-breakdown`. |
435
+ | `tokenThresholds.tierAggregate` | `number` | `4000` | Combined always-loaded threshold for `tier-tokens/aggregate`. |
436
+ | `contextFiles` | `string[]` | `[]` | Extra glob patterns to scan alongside the built-in list. |
437
+ | `mcp` | `boolean` | `false` | Enable MCP config checks by default (same as `--mcp`). |
438
+ | `mcpOnly` | `boolean` | `false` | Run only MCP config checks, skip context-file checks (same as `--mcp-only`). |
439
+ | `mcpGlobal` | `boolean` | `false` | Also scan user/global MCP configs (same as `--mcp-global`). |
440
+ | `mcph` | `boolean` | `false` | Enable `.mcph.json` (mcp.hosting CLI config) checks (same as `--mcph`). |
441
+ | `mcphOnly` | `boolean` | `false` | Run only mcph config checks, skip context-file checks (same as `--mcph-only`). |
442
+ | `mcphGlobal` | `boolean` | `false` | Also scan `~/.mcph.json` user-global config (same as `--mcph-global`). |
443
+ | `mcphStrictEnvToken` | `boolean` | `false` | Upgrade `mcph-config/prefer-env-token` from warning to error (same as `--mcph-strict-env-token`). |
444
+ | `session` | `boolean` | `false` | Enable session audit checks (cross-project consistency); same as `--session`. |
445
+ | `sessionOnly` | `boolean` | `false` | Run only session checks, skip context and MCP checks (same as `--session-only`). |
446
+
447
+ Config file resolution order: `.ctxlintrc` → `.ctxlintrc.json` in the project root. Use `--config <path>` to point elsewhere. CLI flags override config fields.
448
+
449
+ CLI flags override config file settings. Use `--config <path>` to load a config from a custom location.
450
+
451
+ ## Use as MCP Server
452
+
453
+ ctxlint ships with an MCP server that exposes seven tools (`ctxlint_audit`, `ctxlint_mcp_audit`, `ctxlint_mcph_audit`, `ctxlint_session_audit`, `ctxlint_validate_path`, `ctxlint_token_report`, `ctxlint_fix`). All read-only tools declare annotations so MCP clients can skip confirmation dialogs.
454
+
455
+ Launch it with the `serve` subcommand (or the equivalent `--mcp-server` flag, kept for back-compat):
456
+
457
+ ```bash
458
+ npx -y @yawlabs/ctxlint@latest serve
459
+ ```
460
+
461
+ ### With Claude Code
462
+
463
+ ```bash
464
+ claude mcp add ctxlint -- npx -y @yawlabs/ctxlint@latest serve
465
+ ```
466
+
467
+ ### With `.mcp.json` (Claude Code project config, Cursor, Windsurf)
468
+
469
+ Create `.mcp.json` in your project root:
470
+
471
+ macOS / Linux / WSL:
472
+
473
+ ```json
474
+ {
475
+ "mcpServers": {
476
+ "ctxlint": {
477
+ "command": "npx",
478
+ "args": ["-y", "@yawlabs/ctxlint@latest", "serve"]
479
+ }
480
+ }
481
+ }
482
+ ```
483
+
484
+ Windows:
485
+
486
+ ```json
487
+ {
488
+ "mcpServers": {
489
+ "ctxlint": {
490
+ "command": "cmd",
491
+ "args": ["/c", "npx", "-y", "@yawlabs/ctxlint@latest", "serve"]
492
+ }
493
+ }
494
+ }
495
+ ```
496
+
497
+ > **Tip:** This file is safe to commit — it contains no secrets.
498
+
499
+ ### With VS Code / GitHub Copilot
500
+
501
+ Add to `.vscode/mcp.json`:
502
+
503
+ ```json
504
+ {
505
+ "servers": {
506
+ "ctxlint": {
507
+ "command": "npx",
508
+ "args": ["-y", "@yawlabs/ctxlint@latest", "serve"]
509
+ }
510
+ }
511
+ }
512
+ ```
513
+
514
+ ### With Claude Desktop
515
+
516
+ Add to your Claude Desktop config (`claude_desktop_config.json`):
517
+
518
+ ```json
519
+ {
520
+ "mcpServers": {
521
+ "ctxlint": {
522
+ "command": "npx",
523
+ "args": ["-y", "@yawlabs/ctxlint@latest", "serve"]
524
+ }
525
+ }
526
+ }
527
+ ```
528
+
529
+ ## JSON Output
530
+
531
+ ```bash
532
+ npx @yawlabs/ctxlint@latest --format json
533
+ ```
534
+
535
+ Returns structured JSON with all file results, issues, and summary — useful for building integrations or dashboards.
536
+
537
+ ## Specifications
538
+
539
+ ctxlint is the reference implementation of three open specifications for linting AI agent interfaces. These specs are tool-agnostic — any linter, IDE extension, or CI system can implement them.
540
+
541
+ | Spec | What it covers |
542
+ | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
543
+ | **[AI Context File Linting Spec](./CONTEXT_LINT_SPEC.md)** | 19 rules for validating context files (CLAUDE.md, .cursorrules, AGENTS.md, etc.) across 17 clients. Covers file formats, frontmatter schemas, path/command validation, staleness, token budgets, redundancy, and contradictions. |
544
+ | **[MCP Config Linting Spec](./MCP_CONFIG_LINT_SPEC.md)** | 43 rules for validating MCP server configs (.mcp.json, .cursor/mcp.json, .vscode/mcp.json, etc.) across 8 clients. Covers schema validation, hardcoded secrets, env var syntax, deprecated transports, and cross-file consistency. |
545
+ | **mcph Config Linting** (`mcph-config-lint-rules.json`) | 10 rules for validating `.mcph.json` — the config file read by the `@yawlabs/mcph` CLI. Covers PAT format + leakage, env-var posture, plaintext API endpoints, schema drift, and allow/deny list semantics across the scope cascade. |
546
+ | **[Agent Session Linting Spec](./AGENT_SESSION_LINT_SPEC.md)** | 7 rules for auditing agent session data (history, memory) across 8 agents. Covers cross-project secret consistency, config drift, stale memory, and loop detection. |
547
+
548
+ All specs include machine-readable rule catalogs for programmatic consumption:
549
+
550
+ - [`context-lint-rules.json`](./context-lint-rules.json) — context file rules and 16 supported format definitions
551
+ - [`mcp-config-lint-rules.json`](./mcp-config-lint-rules.json) — MCP config rules and 8 client definitions
552
+ - [`mcph-config-lint-rules.json`](./mcph-config-lint-rules.json) — mcph CLI config rules (`.mcph.json`)
553
+ - [`agent-session-lint-rules.json`](./agent-session-lint-rules.json) — session lint rules and 8 agent data source definitions
554
+
555
+ ## Also By Yaw Labs
556
+
557
+ - [Yaw](https://yaw.sh) — The AI-native terminal
558
+ - [mcp.hosting](https://mcp.hosting) — MCP server proxy platform
559
+ - [Spend](https://spend.sh) — AI spend tracking, cost estimation, and provider comparison across 10+ providers
560
+ - [Token Limit News](https://tokenlimit.news) — Weekly AI dev tooling newsletter
561
+
562
+ ## License
563
+
564
+ MIT