@yawlabs/ctxlint 0.13.2 → 0.14.0
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/.pre-commit-hooks.yaml +1 -1
- package/README.md +528 -568
- package/dist/index.js +4317 -4827
- package/package.json +1 -2
- package/schemas/ctxlint-catalog.schema.json +2 -2
- package/mcph-config-lint-rules.json +0 -151
package/README.md
CHANGED
|
@@ -1,568 +1,528 @@
|
|
|
1
|
-
# ctxlint
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@yawlabs/ctxlint)
|
|
4
|
-
[](https://opensource.org/licenses/MIT)
|
|
5
|
-
[](https://github.com/YawLabs/ctxlint/stargazers)
|
|
6
|
-
[](https://github.com/YawLabs/ctxlint/actions/workflows/ci.yml)
|
|
7
|
-
[](https://github.com/YawLabs/ctxlint/actions/workflows/release.yml)
|
|
8
|
-
[](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
|
-
[](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** —
|
|
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
|
-
| **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` |
|
|
86
|
-
| **Missing secrets** | GitHub secrets set on sibling repos but missing from current project
|
|
87
|
-
| **Diverged configs** | Canonical config files (CI, tsconfig, etc.) drifting across sibling projects
|
|
88
|
-
| **Missing workflows** | GitHub Actions workflows present in 2+ siblings but absent here
|
|
89
|
-
| **Stale memory** | Claude Code memory entries referencing paths that no longer exist
|
|
90
|
-
| **Duplicate memory** | Near-duplicate memories across projects (>60% content overlap)
|
|
91
|
-
| **Loop detection** | Agent stuck in loops — repeated commands or cyclic patterns in session history
|
|
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
|
-
##
|
|
184
|
-
|
|
185
|
-
ctxlint
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
|
207
|
-
|
|
|
208
|
-
| **
|
|
209
|
-
| **
|
|
210
|
-
| **
|
|
211
|
-
| **
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
```
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
### With
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
```
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
```
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
}
|
|
530
|
-
```
|
|
531
|
-
|
|
532
|
-
## JSON Output
|
|
533
|
-
|
|
534
|
-
```bash
|
|
535
|
-
npx @yawlabs/ctxlint@latest --format json
|
|
536
|
-
```
|
|
537
|
-
|
|
538
|
-
Returns structured JSON with all file results, issues, and summary — useful for building integrations or dashboards.
|
|
539
|
-
|
|
540
|
-
## Specifications
|
|
541
|
-
|
|
542
|
-
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.
|
|
543
|
-
|
|
544
|
-
| Spec | What it covers |
|
|
545
|
-
| -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
546
|
-
| **[AI Context File Linting Spec](./CONTEXT_LINT_SPEC.md)** | 28 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. |
|
|
547
|
-
| **[MCP Config Linting Spec](./MCP_CONFIG_LINT_SPEC.md)** | 27 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. |
|
|
548
|
-
| **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. |
|
|
549
|
-
| **[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. |
|
|
550
|
-
| **[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) |
|
|
551
|
-
|
|
552
|
-
All specs include machine-readable rule catalogs for programmatic consumption:
|
|
553
|
-
|
|
554
|
-
- [`context-lint-rules.json`](./context-lint-rules.json) — context file rules and 16 supported format definitions
|
|
555
|
-
- [`mcp-config-lint-rules.json`](./mcp-config-lint-rules.json) — MCP config rules and 8 client definitions
|
|
556
|
-
- [`mcph-config-lint-rules.json`](./mcph-config-lint-rules.json) — mcph CLI config rules (`.mcph.json`)
|
|
557
|
-
- [`agent-session-lint-rules.json`](./agent-session-lint-rules.json) — session lint rules and 8 agent data source definitions
|
|
558
|
-
- [`agent-skill-lint-rules.json`](./agent-skill-lint-rules.json) — agent-skill lint rules (`~/.claude/skills`, `~/.claude/agents`)
|
|
559
|
-
|
|
560
|
-
## Also By Yaw Labs
|
|
561
|
-
|
|
562
|
-
- [Yaw](https://yaw.sh) — The AI-native terminal
|
|
563
|
-
- [Spend](https://spend.sh) — AI spend tracking, cost estimation, and provider comparison across 10+ providers
|
|
564
|
-
- [Token Limit News](https://tokenlimit.news) — Weekly AI dev tooling newsletter
|
|
565
|
-
|
|
566
|
-
## License
|
|
567
|
-
|
|
568
|
-
MIT
|
|
1
|
+
# ctxlint
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@yawlabs/ctxlint)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://github.com/YawLabs/ctxlint/stargazers)
|
|
6
|
+
[](https://github.com/YawLabs/ctxlint/actions/workflows/ci.yml)
|
|
7
|
+
[](https://github.com/YawLabs/ctxlint/actions/workflows/release.yml)
|
|
8
|
+
[](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
|
+
[](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** — 6 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
|
+
| **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` |
|
|
86
|
+
| **Missing secrets** | GitHub secrets set on sibling repos but missing from current project |
|
|
87
|
+
| **Diverged configs** | Canonical config files (CI, tsconfig, etc.) drifting across sibling projects |
|
|
88
|
+
| **Missing workflows** | GitHub Actions workflows present in 2+ siblings but absent here |
|
|
89
|
+
| **Stale memory** | Claude Code memory entries referencing paths that no longer exist |
|
|
90
|
+
| **Duplicate memory** | Near-duplicate memories across projects (>60% content overlap) |
|
|
91
|
+
| **Loop detection** | Agent stuck in loops — repeated commands or cyclic patterns in session history |
|
|
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)** — 8 lint rules, 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
|
+
--mcp-server Start the MCP server (alias: `serve` subcommand)
|
|
273
|
+
--watch Re-lint on context file changes
|
|
274
|
+
-V, --version Output the version number
|
|
275
|
+
-h, --help Display help
|
|
276
|
+
|
|
277
|
+
Commands:
|
|
278
|
+
init Set up a git pre-commit hook
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
**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`, `session-missing-secret`, `session-diverged-file`, `session-missing-workflow`, `session-stale-memory`, `session-duplicate-memory`, `session-loop-detection`, `session-memory-index-overflow`
|
|
282
|
+
|
|
283
|
+
Passing any `mcp-*` check name implies `--mcp`. Passing any `session-*` check name implies `--session`.
|
|
284
|
+
|
|
285
|
+
## Watch Mode
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
npx @yawlabs/ctxlint@latest --watch
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Re-lints automatically when any context file, MCP config, or `package.json` changes. Useful during development when you're editing context files alongside code.
|
|
292
|
+
|
|
293
|
+
## Use in CI
|
|
294
|
+
|
|
295
|
+
```yaml
|
|
296
|
+
- name: Lint context files
|
|
297
|
+
run: npx @yawlabs/ctxlint@latest --strict
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### Exit Codes
|
|
301
|
+
|
|
302
|
+
| Code | Meaning |
|
|
303
|
+
| ---- | -------------------------------------------------------------------- |
|
|
304
|
+
| `0` | Success — no issues, or issues below the strict threshold |
|
|
305
|
+
| `1` | Strict mode caught at least one error or warning (`--strict` is set) |
|
|
306
|
+
| `2` | Config error, invalid CLI option, or internal failure |
|
|
307
|
+
|
|
308
|
+
In non-strict mode ctxlint always exits `0` — it's a reporting tool by default. Pass `--strict` to enforce in CI.
|
|
309
|
+
|
|
310
|
+
### GitHub Action
|
|
311
|
+
|
|
312
|
+
```yaml
|
|
313
|
+
- name: Lint context files
|
|
314
|
+
uses: yawlabs/ctxlint-action@v1
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
Or with options:
|
|
318
|
+
|
|
319
|
+
```yaml
|
|
320
|
+
- name: Lint context files
|
|
321
|
+
uses: yawlabs/ctxlint-action@v1
|
|
322
|
+
with:
|
|
323
|
+
args: '--strict --mcp'
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### SARIF Output (GitHub Code Scanning)
|
|
327
|
+
|
|
328
|
+
```yaml
|
|
329
|
+
- name: Lint context files
|
|
330
|
+
run: npx @yawlabs/ctxlint@latest --format sarif > ctxlint.sarif
|
|
331
|
+
|
|
332
|
+
- name: Upload SARIF
|
|
333
|
+
uses: github/codeql-action/upload-sarif@v3
|
|
334
|
+
with:
|
|
335
|
+
sarif_file: ctxlint.sarif
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
## Auto-fix
|
|
339
|
+
|
|
340
|
+
```bash
|
|
341
|
+
npx @yawlabs/ctxlint@latest --fix
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
When a broken path was renamed in git or has a close match in the project, `--fix` rewrites the context file automatically.
|
|
345
|
+
|
|
346
|
+
## Pre-commit Hook
|
|
347
|
+
|
|
348
|
+
### Built-in
|
|
349
|
+
|
|
350
|
+
```bash
|
|
351
|
+
npx @yawlabs/ctxlint@latest init
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
Sets up a git pre-commit hook that runs `ctxlint --strict` before each commit.
|
|
355
|
+
|
|
356
|
+
### pre-commit framework
|
|
357
|
+
|
|
358
|
+
Add to your `.pre-commit-config.yaml`:
|
|
359
|
+
|
|
360
|
+
```yaml
|
|
361
|
+
repos:
|
|
362
|
+
- repo: https://github.com/yawlabs/ctxlint
|
|
363
|
+
rev: v0.9.10
|
|
364
|
+
hooks:
|
|
365
|
+
- id: ctxlint
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
## Config File
|
|
369
|
+
|
|
370
|
+
Create a `.ctxlintrc` or `.ctxlintrc.json` in your project root:
|
|
371
|
+
|
|
372
|
+
```json
|
|
373
|
+
{
|
|
374
|
+
"checks": ["paths", "commands", "tokens", "contradictions", "frontmatter"],
|
|
375
|
+
"ignore": ["redundancy"],
|
|
376
|
+
"strict": true,
|
|
377
|
+
"tokenThresholds": {
|
|
378
|
+
"info": 500,
|
|
379
|
+
"warning": 2000,
|
|
380
|
+
"error": 5000,
|
|
381
|
+
"aggregate": 4000,
|
|
382
|
+
"tierBreakdown": 1000,
|
|
383
|
+
"tierAggregate": 4000
|
|
384
|
+
},
|
|
385
|
+
"contextFiles": ["CONVENTIONS.md", "docs/ai-rules.md"]
|
|
386
|
+
}
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
The `contextFiles` array adds custom file patterns to scan alongside the built-in list. Useful for project-specific context files like `CONVENTIONS.md`.
|
|
390
|
+
|
|
391
|
+
### Config Reference
|
|
392
|
+
|
|
393
|
+
| Field | Type | Default | Meaning |
|
|
394
|
+
| ------------------------------- | ---------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
395
|
+
| `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-*`. |
|
|
396
|
+
| `ignore` | `string[]` | `[]` | Checks to skip, evaluated after `checks`. |
|
|
397
|
+
| `strict` | `boolean` | `false` | Exit non-zero on any warning or error. |
|
|
398
|
+
| `tokenThresholds` | `object` | see below | Per-file and cross-file token thresholds. |
|
|
399
|
+
| `tokenThresholds.info` | `number` | `1000` | Per-file info threshold for `tokens/info`. |
|
|
400
|
+
| `tokenThresholds.warning` | `number` | `3000` | Per-file warning threshold for `tokens/large`. |
|
|
401
|
+
| `tokenThresholds.error` | `number` | `8000` | Per-file error threshold for `tokens/excessive`. |
|
|
402
|
+
| `tokenThresholds.aggregate` | `number` | `5000` | Cross-file total threshold for `tokens/aggregate`. |
|
|
403
|
+
| `tokenThresholds.tierBreakdown` | `number` | `1000` | Always-loaded file threshold for `tier-tokens/section-breakdown`. |
|
|
404
|
+
| `tokenThresholds.tierAggregate` | `number` | `4000` | Combined always-loaded threshold for `tier-tokens/aggregate`. |
|
|
405
|
+
| `contextFiles` | `string[]` | `[]` | Extra glob patterns to scan alongside the built-in list. |
|
|
406
|
+
| `mcp` | `boolean` | `false` | Enable MCP config checks by default (same as `--mcp`). |
|
|
407
|
+
| `mcpOnly` | `boolean` | `false` | Run only MCP config checks, skip context-file checks (same as `--mcp-only`). |
|
|
408
|
+
| `mcpGlobal` | `boolean` | `false` | Also scan user/global MCP configs (same as `--mcp-global`). |
|
|
409
|
+
| `session` | `boolean` | `false` | Enable session audit checks (cross-project consistency); same as `--session`. |
|
|
410
|
+
| `sessionOnly` | `boolean` | `false` | Run only session checks, skip context and MCP checks (same as `--session-only`). |
|
|
411
|
+
|
|
412
|
+
Config file resolution order: `.ctxlintrc` → `.ctxlintrc.json` in the project root. Use `--config <path>` to point elsewhere. CLI flags override config fields.
|
|
413
|
+
|
|
414
|
+
CLI flags override config file settings. Use `--config <path>` to load a config from a custom location.
|
|
415
|
+
|
|
416
|
+
## Use as MCP Server
|
|
417
|
+
|
|
418
|
+
ctxlint ships with an MCP server that exposes six tools (`ctxlint_audit`, `ctxlint_mcp_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.
|
|
419
|
+
|
|
420
|
+
Launch it with the `serve` subcommand (or the equivalent `--mcp-server` flag, kept for back-compat):
|
|
421
|
+
|
|
422
|
+
```bash
|
|
423
|
+
npx -y @yawlabs/ctxlint@latest serve
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
### With Claude Code
|
|
427
|
+
|
|
428
|
+
```bash
|
|
429
|
+
claude mcp add ctxlint -- npx -y @yawlabs/ctxlint@latest serve
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
### With `.mcp.json` (Claude Code project config, Cursor, Windsurf)
|
|
433
|
+
|
|
434
|
+
Create `.mcp.json` in your project root:
|
|
435
|
+
|
|
436
|
+
macOS / Linux / WSL:
|
|
437
|
+
|
|
438
|
+
```json
|
|
439
|
+
{
|
|
440
|
+
"mcpServers": {
|
|
441
|
+
"ctxlint": {
|
|
442
|
+
"command": "npx",
|
|
443
|
+
"args": ["-y", "@yawlabs/ctxlint@latest", "serve"]
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
Windows:
|
|
450
|
+
|
|
451
|
+
```json
|
|
452
|
+
{
|
|
453
|
+
"mcpServers": {
|
|
454
|
+
"ctxlint": {
|
|
455
|
+
"command": "cmd",
|
|
456
|
+
"args": ["/c", "npx", "-y", "@yawlabs/ctxlint@latest", "serve"]
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
> **Tip:** This file is safe to commit — it contains no secrets.
|
|
463
|
+
|
|
464
|
+
### With VS Code / GitHub Copilot
|
|
465
|
+
|
|
466
|
+
Add to `.vscode/mcp.json`:
|
|
467
|
+
|
|
468
|
+
```json
|
|
469
|
+
{
|
|
470
|
+
"servers": {
|
|
471
|
+
"ctxlint": {
|
|
472
|
+
"command": "npx",
|
|
473
|
+
"args": ["-y", "@yawlabs/ctxlint@latest", "serve"]
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
### With Claude Desktop
|
|
480
|
+
|
|
481
|
+
Add to your Claude Desktop config (`claude_desktop_config.json`):
|
|
482
|
+
|
|
483
|
+
```json
|
|
484
|
+
{
|
|
485
|
+
"mcpServers": {
|
|
486
|
+
"ctxlint": {
|
|
487
|
+
"command": "npx",
|
|
488
|
+
"args": ["-y", "@yawlabs/ctxlint@latest", "serve"]
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
## JSON Output
|
|
495
|
+
|
|
496
|
+
```bash
|
|
497
|
+
npx @yawlabs/ctxlint@latest --format json
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
Returns structured JSON with all file results, issues, and summary — useful for building integrations or dashboards.
|
|
501
|
+
|
|
502
|
+
## Specifications
|
|
503
|
+
|
|
504
|
+
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.
|
|
505
|
+
|
|
506
|
+
| Spec | What it covers |
|
|
507
|
+
| -------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
508
|
+
| **[AI Context File Linting Spec](./CONTEXT_LINT_SPEC.md)** | 28 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. |
|
|
509
|
+
| **[MCP Config Linting Spec](./MCP_CONFIG_LINT_SPEC.md)** | 27 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. |
|
|
510
|
+
| **[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. |
|
|
511
|
+
| **[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) |
|
|
512
|
+
|
|
513
|
+
All specs include machine-readable rule catalogs for programmatic consumption:
|
|
514
|
+
|
|
515
|
+
- [`context-lint-rules.json`](./context-lint-rules.json) — context file rules and 16 supported format definitions
|
|
516
|
+
- [`mcp-config-lint-rules.json`](./mcp-config-lint-rules.json) — MCP config rules and 8 client definitions
|
|
517
|
+
- [`agent-session-lint-rules.json`](./agent-session-lint-rules.json) — session lint rules and 8 agent data source definitions
|
|
518
|
+
- [`agent-skill-lint-rules.json`](./agent-skill-lint-rules.json) — agent-skill lint rules (`~/.claude/skills`, `~/.claude/agents`)
|
|
519
|
+
|
|
520
|
+
## Also By Yaw Labs
|
|
521
|
+
|
|
522
|
+
- [Yaw](https://yaw.sh) — The AI-native terminal
|
|
523
|
+
- [Spend](https://spend.sh) — AI spend tracking, cost estimation, and provider comparison across 10+ providers
|
|
524
|
+
- [Token Limit News](https://tokenlimit.news) — Weekly AI dev tooling newsletter
|
|
525
|
+
|
|
526
|
+
## License
|
|
527
|
+
|
|
528
|
+
MIT
|