trs

trs audit-docs: find bloat in CLAUDE.md / AGENTS.md / rules files

Agent instruction files (CLAUDE.md, AGENTS.md, .cursor/rules/*.mdc, .windsurfrules) get loaded into every agent session, every turn, every project open, every conversation start. Bloat in these files is the single most expensive kind of bloat because it multiplies across every interaction.

trs audit-docs is a static analyzer that finds:

Quick reference

trs audit-docs                  # audit current directory
trs audit-docs path/to/docs     # audit a specific folder

The output groups findings by file with line numbers and a short one-line description. Nothing is modified. This is a read-only report.

What it scans

By default, these paths in the current directory (if they exist):

File walker respects .gitignore. Max 2000 files walked, depth cap of 8, so running it on a mega-repo is bounded.

Duplicate detection (SimHash)

Text blocks are split on double-newlines, tokenized into 3-word shingles, FNV-1a hashed into 64-bit SimHashes. Two blocks with Hamming distance ≤ 6 are considered near-duplicates (≥ 90% overlap).

Blocks must be:

Otherwise the detector would flag every similar heading (## Install vs ## Installation) as duplicates and drown the report in noise.

Dead @imports

Scans @path/to/file.md references inside Claude Code / Gemini CLI rules files. An import is flagged as dead if:

Update stamps

Lines like Updated: 2026-11-04, Last updated November 2026, As of 2026-11 or Today is ... outside code fences. The agent’s prompt cache is keyed on the exact prefix of what it loads, so rewriting a stamp invalidates the cached prefix from that line on, every time the file is touched. Git already records when a file changed; keep the stamp out of the file. A date that is never rewritten (the date of a decision, a verification date) is not flagged: it costs nothing.

Embedded bloat

Fenced code blocks, JSON blobs, SQL queries, and HTML tables inside rules files. These inflate the per-session load without adding instructional value. They’re content that should live in source files, docs, or test fixtures.

For code fences, we cross-reference declared symbols against the project’s actual source tree:

Symbol matching uses a blocklist of generic names (data, result, page, value, json, …) to avoid matching on project-agnostic identifiers.

Language support for symbol extraction

TypeScript, JavaScript, Python, Rust, Go, Swift. Other languages get duplicate / dead-ref analysis only, no symbol cross-reference.

Integration with trs doctor

trs doctor reports the total token budget of agent-docs in the current directory and hints at audit-docs when any file exceeds ~5k tokens. That hint is why you’re probably reading this page.

Philosophy

audit-docs is a user tool, not an agent tool. The agent maintainer runs it periodically. Typical cadence: after adding a new rules file, after several rounds of edits, before cutting a release of a product that ships rules. Not every session, not every commit.

Output format example

docs/CLAUDE.md (4 findings):

  L12-L45  ~  near-duplicate with docs/AGENTS.md:L8-L41
  L78-L92  ~  embedded SQL query (25 lines, 680 tokens)
              → move to docs/queries/user-lookup.sql and link
  L103-L120 ~  embedded code fence, symbol `handleLogin` already
              defined in src/auth/handlers.rs:44
              → REMOVE, replace with link
  L138     ~  dead @import: @./removed-rules.md
              → file does not exist; remove the line

total: 4 findings

See also