Get the FREE Ultimate OpenClaw Setup Guide →

rules-auditor

npx machina-cli add skill seanGSISG/claude-depot/rules-auditor --openclaw
Files (1)
SKILL.md
5.5 KB

Overview

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.md files → 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):

  1. Extract quoted identifiers and code-fenced terms from the rule
  2. Search the codebase for their existence using grep or Grep tool
  3. Flag rules that reference patterns no longer present in matching files

Step 4: Convention Drift Detection

For rules describing code conventions or patterns:

  1. Identify the convention described (e.g., "all services use a configure() method")
  2. Sample files matching the rule's scope
  3. Check if the described pattern appears in a majority of matching files
  4. 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:

ScoreCriteria
freshAll globs match files, referenced files exist, described patterns verified in code
needs-reviewFile not modified in 60+ days, or described patterns appear in <50% of matching files, or minor drift detected
staleDead 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

TopicReference FileKey Contents
What makes effective rules and CLAUDE.mdreferences/quality-patterns.mdRoot CLAUDE.md guidelines, scoped rules best practices, progressive disclosure tiers, emphasis patterns
Common mistakes to avoidreferences/anti-patterns.mdKitchen sink files, volatile imports, negative-only constraints, linter duplication, redundancy
Detecting drift and stalenessreferences/staleness-detection.mdDead globs, referenced file drift, API pattern drift, version pinning, convention drift, scoring
CI integration with GitHub Actionsreferences/github-workflow-guide.mdWorkflow 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

  1. Step 1: Discover all memory files (.claude/rules/*.md, CLAUDE.md, CLAUDE.local.md)
  2. Step 2: Run the audit checks (dead glob detection, referenced file verification, code-pattern verification, drift and freshness scoring)
  3. 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

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers