@yawlabs/ctxlint 0.18.4 → 0.18.6

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