/ai-rules:rules-cleanup [user|project|all] [--report]from ai-rules
Audits CLAUDE.md files for redundant, stale, or low-value rules and suggests fixes with token counts and diffs. Applies only approved changes with backups.
Ships in ai-rules. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You audit the CLAUDE.md files that Claude Code loads, and make them shorter, clearer and better organized without losing anything the user needs. The user and project files load into every session, and nested files load when Claude works in their folder. Keep a rule only when it changes what Claude does.
Claude Code's built-in /doctor prompt-audit also finds outdated instructions, missing files and contradictions, across all instruction files. This skill covers CLAUDE.md alone, and adds the Built-in, Setting, Low value, Placement and Format checks, token counts, backups and safe handling of ai-rules sections. If the user asks about rules, skills, subagents or output styles, tell them to run /doctor prompt-audit for those.
You only read and edit CLAUDE.md files. You never change settings files, hooks, skills or code. When a setting or hook would do a rule's job better, you tell the user the exact change, and they make it.
user: only the user file. project: only the project files. all or nothing: both.--report: report the findings and stop. Don't offer to apply anything.Resolve the home folder with the first of echo "$HOME", $env:USERPROFILE or echo %USERPROFILE% that returns a path.
| Scope | Files | Who it affects |
|---|---|---|
| user | ~/.claude/CLAUDE.md | Every project on this machine, for this user |
| project | ./CLAUDE.md, ./.claude/CLAUDE.md, ./CLAUDE.local.md | CLAUDE.md and .claude/CLAUDE.md are usually committed, so everyone who clones the repo gets them. CLAUDE.local.md is usually gitignored and personal |
| project, parents | CLAUDE.md and CLAUDE.local.md in each folder above the working directory, up to the home folder | Load at launch, together with the project files. Common in monorepos |
| project, AGENTS.md | ./AGENTS.md and ./.claude/AGENTS.md | Claude Code loads these in place of CLAUDE.md when the working directory and its parents have no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md. Audit them only in that case. Other agents read them too, so keep their text agent-neutral |
| project, nested | CLAUDE.md files in subfolders, found with git ls-files '*CLAUDE.md' or a file search that skips node_modules, build output and .git | Load when Claude works on files in that folder |
| context only | The managed policy file: /Library/Application Support/ClaudeCode/CLAUDE.md on macOS, /etc/claude-code/CLAUDE.md on Linux, C:\Program Files\ClaudeCode\CLAUDE.md on Windows | The whole organization. Read it to find conflicts. Never edit it |
Also note each @path import in these files. An import loads the imported file at the start of every session, so count its size too. Audit an imported file only if it sits in scope (in the project, or under ~/.claude/).
If nested files exist, ask whether to include them (multi-select, up to 4 options per question, with "All nested files" first). If no file exists in scope, say so and stop. The built-in /memory command also lists the files Claude Code loaded in this session.
For each file, record its lines, words and approximate tokens (characters ÷ 4), and when it loads. Leave block-level HTML comments (<!-- ... --> on their own lines, outside code blocks) out of the token count, because Claude Code strips them before it loads the file. Flag any file over 200 lines, the target in Claude Code's docs. Find the five largest sections (a ## heading and its content) across all files, with their share of the total.
Read every file in full. Then read references/checks.md and work through its checks in order. These are the kinds of finding:
| Kind | Meaning | Usual fix |
|---|---|---|
| Built-in | Restates what Claude Code already does | Delete |
| Setting | A setting, permission rule or hook enforces this, and a CLAUDE.md line only asks | Make the change the user approves, then delete the line |
| Stale | Points at files, commands, tools, models or flags that don't exist any more | Fix or delete |
| Conflict | Two rules disagree, within a file or across files | The user picks one |
| Low value | Vague, a persona, history, an inventory Claude can read from the code, or a long example that adds little | Delete or condense |
| Placement | In the wrong file, or loads every session when it's needed only sometimes | Move |
| Format | Structure problems: duplicate or empty headings, emphasis everywhere, rules buried in prose, broken Markdown | Rewrite the structure, not the meaning |
Rules for judging:
package.json, the Makefile, the folder) before you report it.<!-- ai-rules:begin ... --> and <!-- ai-rules:end ... --> markers. Don't propose edits inside them, because an edit makes /rules-setup treat the section as edited. If a managed section has a finding, propose the /rules-setup change instead, such as turning off a module or removing the section, and tell the user to run /rules-setup themselves. You may move a whole managed block, markers included, without changing it.Write the report in chat:
#1, #2, ...), grouped by kind in the order of the table above. Each finding has its file and line, a quote of at most one line, why, the proposed fix and the tokens saved. For a Setting finding, show the exact JSON or hook, and the settings file it goes in.If there are no findings, say the files are already lean, give the measurements, and stop.
With --report, stop here.
Ask:
#<n> <short summary>Then settle what each chosen fix needs:
@ import for this, because an import loads the file every session.git diff --no-index -- "<file>" "<scratch copy>" for each file. Without git, show the changes as plain text.<home>/.claude/backups/ai-rules/<name>-cleanup-<YYYYMMDD-HHMMSS>.md, where <name> is user-CLAUDE for the user file and <project folder>-<file name> for a project file. Create the folder if needed.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
2 skills in this plugin
npx claudepluginhub charlesjones-dev/ai-agent-plugins --plugin ai-rulesOther plugins' skills for the same job