rules-auditor
npx machina-cli add skill seanGSISG/claude-depot/rules-auditor --openclawOverview
This skill audits and improves Claude Code memory files — .claude/rules/*.md, CLAUDE.md, and CLAUDE.local.md. It detects staleness (dead globs, references to deleted files, outdated conventions), quality issues (bloat, contradictions, redundancy), and provides actionable recommendations.
Use this skill when asked to:
- Audit or review rules quality and freshness
- Find stale or broken rules
- Improve progressive disclosure setup
- Check if CLAUDE.md files are up to date
- Optimize Claude Code context loading
Discovery Workflow
Before auditing, discover all memory files in the project:
1. Find all rules files
find .claude/rules -name "*.md" -type f 2>/dev/null | sort
2. Find all CLAUDE.md files
find . -name "CLAUDE.md" -o -name "CLAUDE.local.md" | grep -v node_modules | grep -v .git | sort
3. Parse scoping from each rule
For each rule file, extract the paths: frontmatter to determine scope:
# Extract paths from YAML frontmatter
sed -n '/^---$/,/^---$/p' "$rule_file" | grep -A 50 '^paths:' | grep '^ *- ' | sed 's/^ *- *//'
- Global rules: No
paths:frontmatter — loaded on every session - Scoped rules: Have
paths:with glob patterns — loaded only when Claude reads matching files
4. Build the inventory
Classify each file:
- Rule files with
paths:→ scoped rules (note the globs) - Rule files without
paths:→ global rules - Root
CLAUDE.md→ always loaded (ancestor of cwd) - Nested
CLAUDE.mdfiles → loaded lazily when Claude reads files in that subtree
Audit Workflow
For each discovered memory file, perform these checks:
Step 1: Dead Glob Detection (scoped rules only)
For each glob pattern in paths:, verify files actually match:
# Test if a glob matches any files
shopt -s globstar nullglob
files=( $glob_pattern )
if [ ${#files[@]} -eq 0 ]; then
echo "STALE: glob '$glob_pattern' matches no files"
fi
Common causes: directories renamed, file extensions changed, code moved to a different location.
Step 2: Referenced File Verification
Extract file paths mentioned in rule content and verify they exist:
# Find file references in rule content (paths like src/foo/bar.ts, ./config/x.json)
grep -oE '`[a-zA-Z0-9_./-]+\.[a-zA-Z]{1,5}`' "$rule_file" | tr -d '`' | while read -r ref; do
[ ! -e "$ref" ] && echo "BROKEN REF: $ref in $rule_file"
done
Step 3: Code Pattern Verification
For key identifiers mentioned in rules (function names, class names, type names, command names):
- Extract quoted identifiers and code-fenced terms from the rule
- Search the codebase for their existence using
greporGreptool - Flag rules that reference patterns no longer present in matching files
Step 4: Convention Drift Detection
For rules describing code conventions or patterns:
- Identify the convention described (e.g., "all services use a
configure()method") - Sample files matching the rule's scope
- Check if the described pattern appears in a majority of matching files
- Flag if <50% of files follow the described convention
Step 5: Structural Verification (nested CLAUDE.md)
For nested CLAUDE.md files, verify:
- The directory structure they describe still exists
- Commands they reference (build, test, lint) still work
- Technology/framework references match actual dependencies
Step 6: Freshness Scoring
Assign each file a score:
| Score | Criteria |
|---|---|
| fresh | All globs match files, referenced files exist, described patterns verified in code |
| needs-review | File not modified in 60+ days, or described patterns appear in <50% of matching files, or minor drift detected |
| stale | Dead globs, references to deleted files, instructions contradicted by current code |
Step 7: Report Generation
Produce a structured report with:
- Summary table of all files with their freshness score
- Specific findings per file (what's broken, what drifted)
- Actionable recommendations (update glob, remove reference, rewrite section)
- Priority ranking (stale items first)
Reference Navigation
| Topic | Reference File | Key Contents |
|---|---|---|
| What makes effective rules and CLAUDE.md | references/quality-patterns.md | Root CLAUDE.md guidelines, scoped rules best practices, progressive disclosure tiers, emphasis patterns |
| Common mistakes to avoid | references/anti-patterns.md | Kitchen sink files, volatile imports, negative-only constraints, linter duplication, redundancy |
| Detecting drift and staleness | references/staleness-detection.md | Dead globs, referenced file drift, API pattern drift, version pinning, convention drift, scoring |
| CI integration with GitHub Actions | references/github-workflow-guide.md | Workflow architecture, setup instructions, cost optimization, claude-code-action configuration |
CI Integration
For automated freshness checks on every PR, see references/github-workflow-guide.md. The workflow uses claude-code-action to review affected rules when code changes and posts findings as PR comments.
To install the CI workflow automatically, use the /install-rules-audit command.
Source
git clone https://github.com/seanGSISG/claude-depot/blob/main/plugins/rules-auditor/skills/rules-auditor/SKILL.mdView on GitHub Overview
This skill audits and improves Claude Code memory files — .claude/rules/*.md, CLAUDE.md, and CLAUDE.local.md — to detect staleness, quality issues, and drift. It offers actionable recommendations to fix dead globs, broken references, and outdated conventions, and to optimize context loading.
How This Skill Works
The skill first discovers memory files in the project, including rule files and CLAUDE.md variants. It then runs checks for dead globs, verified file references, code-pattern legitimacy, and convention drift, followed by structural validation of nested CLAUDE.md files. Finally, it assigns a freshness score and outputs prioritized improvements to modernize rules and improve Claude Code context loading.
When to Use It
- Audit or review rules quality and freshness
- Find stale or broken rules
- Improve progressive disclosure setup
- Check CLAUDE.md files are up to date
- Optimize Claude Code context loading
Quick Start
- Step 1: Discover all memory files (.claude/rules/*.md, CLAUDE.md, CLAUDE.local.md)
- Step 2: Run the audit checks (dead glob detection, referenced file verification, code-pattern verification, drift and freshness scoring)
- Step 3: Apply actionable improvements and re-run validation
Best Practices
- Regularly run discovery to inventory .claude/rules and CLAUDE.md
- Validate dead globs and ensure each glob matches actual files
- Verify all referenced file paths exist and update broken references
- Check for rule content drift, bloat, and contradictions
- Document changes with rationale, especially for context-loading optimizations
Example Use Cases
- Audit a refactor to remove stale glob patterns and dead references
- Fix CLAUDE.md after file renames to restore accurate loading order
- Prune bloated rule files to reduce memory usage during Claude Code runs
- Re-scope rules with updated paths to limit context to relevant files
- Validate nested CLAUDE.md in subfolders to ensure structural integrity