feat(cml): context-window-scaled CLAUDE.md char budget (mirrors CC 40.0k warning)

Add a char-based CML finding that mirrors Claude Code's own startup warning
("Large CLAUDE.md will impact performance (X chars > 40.0k)"). CC 2.1.169 scales
that threshold with the model's context window, so the finding anchors on the
conservative 200k window (we cannot observe the user's window; the anchor fires
earliest) and discloses the relaxed ~200,000-char figure at 1M context. MEDIUM
severity (token cost, not an adherence cliff — consistent with the v5.2.0 reframe).

Keyed on chars, not lines, so it is complementary to the existing 200/500-line
checks (which stay untouched): a file can be long by lines yet under budget (short
lines, e.g. large-cascade at 37k chars / 1024 lines), or short by lines yet over it.

Extract the shared 200k/1M context-window constants to scanners/lib/context-window.mjs
(single source of truth; skill-listing-budget.mjs now imports + re-exports them).

40.0k figure and context-window scaling verified against the CC changelog (2.1.169,
2026-06-08) and the live startup-warning text. +6 tests, new fixture large-claude-chars
(48,531 chars / 100 lines). Suite 918/918, self-audit PASS configGrade A 97.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ter3E2JSi1Khgmuf2kady8
This commit is contained in:
Kjell Tore Guttormsen 2026-06-19 13:34:40 +02:00
commit b0bf8c5817
7 changed files with 253 additions and 8 deletions

View file

@ -129,6 +129,64 @@ describe('CML scanner — large cascade (>500 lines): reframed, not absolute-adh
});
});
describe('CML scanner — char budget mirrors CC startup warning (CC 2.1.169)', () => {
// large-claude-chars/CLAUDE.md is 48,531 chars across 100 lines: it crosses
// Claude Code's ~40.0k-char startup-warning threshold while staying under the
// 200-line count, so it isolates the char-budget check from the line check.
let result;
beforeEach(async () => {
resetCounter();
const discovery = await discoverConfigFiles(resolve(FIXTURES, 'large-claude-chars'));
result = await scan(resolve(FIXTURES, 'large-claude-chars'), discovery);
});
const charFinding = (r) =>
r.findings.find((f) => /performance-warning threshold/i.test(f.title || ''));
it('flags a CLAUDE.md over ~40k chars', () => {
assert.ok(charFinding(result), 'expected a char-budget finding for a >40k-char CLAUDE.md');
});
it('the char-budget finding is MEDIUM (token cost, not an adherence cliff)', () => {
assert.strictEqual(charFinding(result)?.severity, 'medium');
});
it('anchors on CC\'s 40.0k figure and discloses context-window scaling', () => {
const f = charFinding(result);
const text = `${f?.description || ''} ${f?.evidence || ''}`;
assert.match(text, /40\.0k/, 'should mirror CC\'s 40.0k startup-warning figure');
assert.match(text, /context window|scales|1,000,000/i, 'should disclose context-window scaling');
// Lock the scaling arithmetic: 40.0k anchor x (1M / 200k) = 200,000 chars @ 1M.
assert.match(text, /200,000/, 'should disclose the ~200,000-char relaxed threshold at 1M context');
});
it('does NOT fire the line-count findings (chars high, lines under 200)', () => {
const lineFinding = result.findings.find((f) => /exceeds (recommended 200|500)/.test(f.title || ''));
assert.ok(!lineFinding, `char fixture should not trip a line finding: ${lineFinding?.title || ''}`);
});
it('the char-budget finding ID matches CA-CML-NNN', () => {
assert.match(charFinding(result)?.id || '', /^CA-CML-\d{3}$/);
});
});
describe('CML scanner — large-by-lines but under the char budget (no false char finding)', () => {
// large-cascade/CLAUDE.md is 1024 lines but only 37,393 chars (short lines):
// under CC's 40.0k char threshold, so the char-budget finding must NOT fire —
// proving the check keys on chars, not raw size or line count.
let result;
beforeEach(async () => {
resetCounter();
const discovery = await discoverConfigFiles(resolve(FIXTURES, 'large-cascade'));
result = await scan(resolve(FIXTURES, 'large-cascade'), discovery);
});
it('does not emit a char-budget finding under 40k chars', () => {
const f = result.findings.find((x) => /performance-warning threshold/i.test(x.title || ''));
assert.ok(!f, 'a 37k-char file (under 40.0k) must not trip the char-budget finding');
});
});
describe('CML scanner — empty project', () => {
let result;
beforeEach(async () => {