Skip to content

feat: add instruction-file-size check - #34

Draft
fcbwilliams wants to merge 2 commits into
mainfrom
feat/instruction-file-size
Draft

fcbwilliams wants to merge 2 commits into
mainfrom
feat/instruction-file-size

Conversation

@fcbwilliams

Copy link
Copy Markdown
Member

What

A new file-tree check, instruction-file-size. It fails when an agent instruction file (CLAUDE.md and AGENTS.md by default), together with the files it pulls in through @path imports, holds more than maxCharacters characters. The default is 40,000, the size at which Claude Code warns that a large CLAUDE.md will hurt performance.

  • Reads the git index, as instruction-symlinks does, so a pre-commit run judges what the commit will hold.
  • Follows imports transitively, each file counted once, so a cycle ends. Only exact tracked files inside the directory the checks run in are followed. A package name (@scope/name), a handle, a directory, a pattern, a home-directory path or an untracked path after an @ is ignored. Fenced code blocks and inline code spans are skipped.
  • Measures instruction files that share a target once. When CLAUDE.md and AGENTS.md both link to README.md, as instruction-symlinks asks, the README is measured once and the violation is reported there, naming both.
  • Code: instruction-file-size/too-large. The message names the file, its size (and each import's), the limit, and suggests moving detail into docs/ with a pointer.
  • Options: files, directories (globs, as instruction-symlinks takes), maxCharacters and followImports.

Why

An instruction file is loaded into every agent session. Past a certain size it crowds out the work and gets skimmed. The limit and the import model are Claude Code's. The check is stricter than Claude Code's own per-file warning, because it sums a file with what it imports, which is what the session actually loads. The README says that other agents (Codex, for one) read their files differently, so files and maxCharacters can be set per agent. This comes from an assessment of which repository conventions a conformance tool should enforce, in which a maximum instruction-file size was the first rule asked for.

Not done here

The check is not switched on in test/self-conformance.integration.test.ts. This repository's README.md is about 82,000 characters, and CLAUDE.md and AGENTS.md link to it, so it would fail at the default. Whether to split the README or leave the check off here is your call.

Known limits are in the README: escaped spaces and #fragments in import paths, multi-line code spans, and ancestor instruction files that are loaded together.

Tests

src/checks/instruction-file-size.integration.test.ts uses git fixtures. It covers: clean, too large, shared symlink targets, transitive imports with a cycle, followImports: false, ignored @ text, directories and patterns and .., an import that is itself a link, nested fences, staged-over-working-tree content, globbed directories, and a run outside git. There are also schema cases in config.unit.test.ts. pnpm lint:check, pnpm typecheck and pnpm test pass locally.

🤖 Generated with Claude Code

fcbwilliams and others added 2 commits October 28, 2026 16:32
Agent instruction files (CLAUDE.md, AGENTS.md and what they pull in with
@path imports) are loaded into the agent's context in every session, so a
file that grows past Claude Code's own warning size (40,000 characters)
costs every session that loads it. The check reads the git index, so it
judges what a commit will hold, follows imports transitively (each file
once, so a cycle ends), and measures instruction files that link to the
same file once, at that file. The message names the file, its size, the
limit, and suggests moving detail into docs/ with a pointer.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…own does

Imports and link targets were looked up as git pathspecs, so a directory
or a pattern after an @ counted whichever file it matched first, and @..
failed the whole run. Lookups are now exact (--literal-pathspecs, the
listed path must equal the one asked for), and a path that leaves the
directory the checks run in is ignored. A fence closes only on a run of
the same character at least as long. The README says the import model
and default are Claude Code's, that the check sums a file with its
imports, and that other agents read their files differently.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant