From agent-context-audit
Audit CLAUDE.md and AGENTS.md files against research-backed best practices. Scores instruction budget usage, detects anti-patterns, checks for staleness, and generates concrete fix proposals. Treats CLAUDE.md and AGENTS.md equally. Use when user asks to audit, check, review, or optimize context files. Also use when user mentions "instruction budget" or "context file quality".
npx claudepluginhub bengous/claude-code-plugins --plugin agent-context-auditThis skill is limited to using the following tools:
<context>
Applies Acme Corporation brand guidelines including colors, fonts, layouts, and messaging to generated PowerPoint, Excel, and PDF documents.
Builds DCF models with sensitivity analysis, Monte Carlo simulations, and scenario planning for investment valuation and risk assessment.
Calculates profitability (ROE, margins), liquidity (current ratio), leverage, efficiency, and valuation (P/E, EV/EBITDA) ratios from financial statements in CSV, JSON, text, or Excel for investment analysis.
Share bugs, ideas, or general feedback.
This skill audits context files and produces concrete fix proposals — not just scores, but exact changes with rationale, budget impact estimates, and confidence levels.
The workflow separates deterministic checks (file existence, import traversal, symlink detection — high confidence) from heuristic judgment (instruction counting, generic advice detection, rewrite proposals — medium confidence). This distinction is labeled in the output.
- Never auto-commit changes — always require explicit user approval - Never delete content without presenting it to the user first - Label every finding with its confidence source (deterministic vs heuristic) - Use approximate counts (`~N`) for heuristic measurements, not false precision - Treat CLAUDE.md and AGENTS.md identically — same methodology, same budget - Do not flag Claude Code native references as stale (slash commands, skills, ${CLAUDE_PLUGIN_ROOT}, Task/Agent calls) - Read reference files (default-behaviors.md, anti-patterns.md) before running heuristic checksType: Deterministic
# Repo context files
find . -name "CLAUDE.md" -o -name "AGENTS.md" -o -name ".claude.local.md" 2>/dev/null | grep -v node_modules | grep -v .git/
# Rules files
ls .claude/rules/*.md 2>/dev/null
# Global context
ls ~/.claude/CLAUDE.md 2>/dev/null
| Type | Location | Always-on? |
|---|---|---|
| Root | ./CLAUDE.md or ./AGENTS.md | Yes |
| Rules (path-scoped) | .claude/rules/*.md with paths: frontmatter | Only when matching files accessed |
| Rules (always-on) | .claude/rules/*.md without paths: frontmatter | Yes |
| Subdirectory | packages/*/CLAUDE.md etc. | Only when files in that dir accessed |
| Global | ~/.claude/CLAUDE.md | Yes (all projects) |
| Local override | .claude.local.md | Yes (but gitignored) |
Check rules files for paths: in YAML frontmatter to classify as scoped vs always-on.
# Check if any context files are symlinks
readlink -f ./CLAUDE.md 2>/dev/null
readlink -f ./AGENTS.md 2>/dev/null
If both CLAUDE.md and AGENTS.md exist:
md5sum ./CLAUDE.md ./AGENTS.md 2>/dev/null
For each context file, scan for @path/to/file import patterns:
@-prefixed references that look like file pathstest -e)Present inventory to user:
## File Inventory
| # | File | Type | Always-on? | Imported by | Lines |
|---|------|------|-----------|-------------|-------|
| 1 | ./CLAUDE.md | Root | Yes | — | 52 |
| 2 | .claude/rules/01-behavioral.md | Rules (always-on) | Yes | — | 18 |
| 3 | .claude/rules/skills/skill-patterns.md | Rules (scoped) | No (paths: **/skills/**) | — | 40 |
| ...
Type: Heuristic (LLM judgment)
Read each always-on file and count directives.
A "directive" is a discrete behavioral instruction the model must track:
For imported files via @file, count their directives and attribute to the importing file's budget.
Directive counting is inherently approximate. Flag ambiguous items:
These are heuristic guidelines from research, not hard limits:
| File Type | Comfortable | Elevated | High pressure |
|---|---|---|---|
| Root context file | <80 directives | 80-120 | >120 |
| Root + all @imports | <100 | 100-130 | >130 |
| Rules file (path-scoped) | <30 | 30-50 | >50 |
| Rules file (always-on) | <20 | 20-40 | >40 |
| Subdirectory context file | <40 | 40-60 | >60 |
| Total always-on surface | <100 | 100-150 | >150 |
The "total always-on surface" is the critical metric — everything Claude loads at session start: root file + @imports + always-on rules + global CLAUDE.md.
Type: Deterministic (mechanical verification)
These are factual checks. Run them with high confidence.
Extract paths from backtick-wrapped content and prose. For each path:
# Check tracked files
git ls-files --error-unmatch "path/to/file" 2>/dev/null
# Check untracked files
test -e "path/to/file"
Skip these (valid at runtime, not verifiable now):
${CLAUDE_PLUGIN_ROOT} or other variable interpolation~/.claude/ paths (user-specific)Extract commands from code blocks and inline backticks.
For package manager commands (npm run X, bun run X, pnpm run X, yarn X):
# Verify script exists in nearest package.json
cat package.json | grep -q '"X"' 2>/dev/null
For npx/bunx commands: verify package in dependencies.
Do NOT flag as stale:
/command-name) — Claude Code nativeSkill(skill: "name")) — Claude Code native${CLAUDE_PLUGIN_ROOT}/... — plugin-relative, resolved at runtimeTask(...) / Agent(...) calls — Claude Code tool syntaxgit commands — always availablels, cat, find, test, etc.) — always available$VARIABLE, ${VAR})# Check for linter/formatter configs
ls biome.json biome.jsonc 2>/dev/null
ls .eslintrc* eslint.config.* 2>/dev/null
ls .prettierrc* prettier.config.* 2>/dev/null
ls .editorconfig 2>/dev/null
ls deno.json deno.jsonc 2>/dev/null
ls ruff.toml 2>/dev/null
grep -l "tool.ruff\|tool.black" pyproject.toml 2>/dev/null
Record which tools are configured — pass to Phase 4 for overlap detection.
.claude/rules/ exist? How many files? How many have paths: frontmatter?@file imports?# Multiple package.json files
find . -name "package.json" -not -path "*/node_modules/*" | wc -l
# Workspace directories
ls -d packages/ apps/ 2>/dev/null
Type: Heuristic (LLM judgment, informed by Phase 3 results)
Before running these checks, read both reference files:
references/default-behaviors.mdreferences/anti-patterns.mdUsing linter configs detected in Phase 3c, cross-reference with context file content.
For each style directive in the context file, check if it overlaps with a detected linter's domain (see anti-patterns.md for keyword patterns).
Proposal: REMOVE — "Already enforced by [tool] via [config]"
Compare directives against default-behaviors.md. Apply two tests:
A directive that matches a default behavior AND has no project-specific tokens is generic advice.
Proposal: REMOVE — "Fails deletion test: Claude already does this by default"
Scan for:
@file imports of files >50 lines — propose converting to "see X" referenceProposal: REWRITE with concise version, or convert embed to reference
Scan for directives that reference specific areas of the codebase:
src/api/, packages/ui/)Estimate scope: what fraction of files does this directive affect?
Proposal: MOVE to .claude/rules/[name].md with paths: frontmatter
Scan for negative keywords (never, don't, avoid, must not) without accompanying positive alternatives (instead, prefer, use, rather) in the same or immediately following line.
Proposal: REWRITE with positive framing and alternative
Type: Mixed (deterministic inventory + heuristic assessment)
Using Phase 3d results:
.claude/rules/ or subdirectory files exist:
→ Recommend progressive disclosure structure@file imports exist:
→ Show budget breakdown: root content vs imported contentCheck for high-value sections (from research on what matters most):
| Section | Value | Why |
|---|---|---|
| Commands (build/test/lint) | HIGH | Most impactful — saves agent from discovering commands |
| Testing approach | HIGH | Prevents wrong test framework/patterns |
| Gotchas/Warnings | HIGH | Prevents repeating debugging sessions |
| Architecture/Structure | MEDIUM | Helps navigation but agent can often infer |
| Code style | LOW (if linter exists) | Linter handles this |
Flag missing HIGH-value sections as suggestions (not issues).
Consolidate all findings from Phases 2-5 into concrete proposals.
Every proposal uses one of four action types:
REMOVE: Lines X-Y
Content: "[exact content]"
Reason: [why — specific anti-pattern or check result]
Budget impact: Recovers ~N directive slots
Confidence: HIGH/MEDIUM
Source: [Phase 3a/3b/4.1/4.2/etc.]
MOVE: Lines X-Y → [target path]
Content: "[section or directive]"
Reason: [applies to <20% of codebase / only relevant in specific context]
Suggested target file:
---
paths: [glob pattern]
---
[moved content]
Budget impact: Recovers ~N directive slots from always-on surface
Confidence: MEDIUM
Source: [Phase 4.4]
REWRITE: Line X
Before: "[current version]"
After: "[proposed version]"
Reason: [verbose → concise / adds missing alternative / converts embed to reference]
Budget impact: [token savings / improved adherence]
Confidence: MEDIUM
Source: [Phase 4.3/4.5]
FLAG: Line X
Content: "[content]"
Issue: [stale path, broken command, ambiguous scope]
Suggestion: [what to investigate or decide]
Confidence: HIGH/MEDIUM
Source: [Phase 3a/3b/5]
Order proposals by impact:
## Context Audit: [file path]
### Always-On Budget
Root directives: ~X (confidence: HIGH/MEDIUM)
Via @imports: ~X (N files)
Always-on rules: ~X (N files)
Global CLAUDE.md: ~X
────────────────────────────
Total always-on: ~X / ~100 recommended [Comfortable / Elevated / High pressure]
File size: X lines
### Health Checks
| Check | Type | Result | Details |
|----------------------|---------------|--------|---------|
| Instruction budget | Heuristic | ... | ~X directives |
| Stale references | Deterministic | ... | N broken paths, M broken commands |
| Linter overlap | Mixed | ... | N style rules overlap with [tool] |
| Verbosity | Heuristic | ... | Density: 0.XX (target >0.3) |
| Progressive disc. | Deterministic | ... | N rules files, M path-scoped |
| Negative w/o alt | Heuristic | ... | N dead-end negatives |
| Generic advice | Heuristic | ... | N directives fail deletion test |
### Quick Wins (top 3 by budget impact)
1. [proposal summary] (~N slots recovered)
2. [proposal summary] (~N slots recovered)
3. [proposal summary] (~N slots recovered)
Projected after quick wins: ~X / ~100
Every proposal with complete detail, grouped by action type. Show confidence level and source phase for each.
Consolidated execution order:
### Action Plan (N proposals)
#### Phase 1: Remove (HIGH confidence first)
1. [stale reference removals — deterministic]
2. [linter overlap removals — high confidence]
3. [generic advice removals — medium confidence]
#### Phase 2: Move to progressive disclosure
4. [non-universal instructions → path-scoped rules]
#### Phase 3: Rewrite
5. [verbose → concise]
6. [negative → positive with alternative]
#### Phase 4: Manual Review
7. [FLAG items needing human judgment]
### Projected Budget After All Changes
Total always-on: ~X / ~100 recommended [new status]
Present the action plan and ask user which proposals to apply:
Options:
For each approved proposal:
After applying, show updated summary:
Applied: N proposals
Skipped: M proposals
New always-on budget: ~X / ~100 recommended
Consider committing these changes and running /context-audit again to verify.