kit/plugins/memory-tools/skills/agentic-memory-management/SKILL.md
Audits and optimizes CLAUDE.md project memory files. Checks adherence to Claude Code best practices and produces actionable fixes. Use when the user asks to audit, optimize, or diagnose a CLAUDE.md.
npx skillsauth add shawn-sandy/agentics agentic-memory-managementInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Audit and optimize a CLAUDE.md / project memory file against Claude Code best practices.
Optimization principle — Keep only rules that would change Claude's behavior versus its built-in defaults; cut everything else. Tighten the rules that survive so each load-bearing instruction reads crisply: verb-first, one idea per bullet, no hedging. This principle governs both the audit (what to flag) and the rewrite (what to keep or cut in Step 5).
Freedom level: Rigid — Execute all seven steps in the order listed. Do not skip, combine, or reorder them. Plan-mode pre-check — If the system indicates plan mode is active when reaching Step 5, defer all write-related prompts and actions (Steps 5–6, including rule-file creation and CLAUDE.md overwrites) until the user exits plan mode. Read-only steps (1–4) may proceed in plan mode. Operational rules — Audit only the file specified. Do not scan the entire project unless asked. Steps 5 and 6 are opt-in — do not rewrite the file without explicit confirmation. Memory load order: project rules → project memory → user memory →
CLAUDE.local.md. Combined instruction count across all loaded files is what matters. Use@path/to/fileimport syntax to reference external docs without embedding their full content.
Does not cover SKILL.md files, slash commands, or general markdown.
Determine which CLAUDE.md to audit using this priority order:
CLAUDE.md in the current working directory (primary project location).claude/CLAUDE.md in the current working directory (alternate, checked if primary absent)~/.claude/CLAUDE.md (global user-level)If both CLAUDE.md and .claude/CLAUDE.md exist, audit CLAUDE.md (root takes priority) and note that the alternate location was skipped.
Tell the user which file will be audited before continuing. If none of the four locations has a file and no argument was given, stop and ask the user to provide a path.
If a path was given but the file does not exist, stop and report the error clearly.
Read the target file in full (Read), then collect these metrics:
**Always**, **Never**). Acknowledge a ±30–50 variance in your estimate.## heading presentGrep -nE on the target file with the pattern sk-|ghp_|AKIA|xoxb-|-----BEGIN|[A-Z_]+=[[:alnum:]_]{20,}. Report each match with its line number and a masked value (never print full secret text). Masking rule: if token length ≥ 8, show first 4 + *** + last 4 (e.g. sk-a***b3x4); if length 4–7, show first 2 + *** + last 2; if length < 4, show ****. If no matches, report "No secrets found."@path/to/file references in the file. List each one found. Determine the import root: if the audited file is inside the workspace (current working directory), use the workspace root; if it is outside (e.g., ~/.claude/CLAUDE.md), use the audited file's own directory as the root. Resolve each import relative to the audited file's directory, then reject any path that is absolute, contains .. traversal, or resolves outside the import root; for rejected paths report "import <path> rejected: outside project root" and skip Read. For each allowed imported file, attempt to Read it and report its line count — do not follow imports found inside those files (strictly one level deep). If the imported file exceeds 500 lines, skip counting it but include a warning: "import <path> has N lines — exceeds 500-line cap, not counted." Sum the counts of all imports under the cap and report as "effective lines (incl. imports): N (approximate, one level deep)." Note that imported content counts toward effective instruction load but is not visible in the raw line count.Report all five metrics before proceeding to Step 3.
Score each dimension 0, 1, or 2. Maximum score: 12.
Full dimension definitions, scoring tables, and example audit output are in
references/audit-steps.md. Load that file before scoring.
Output a structured report in this format:
## CLAUDE.md Audit Report
**File:** [path audited]
**Lines:** [n] | **Estimated instructions:** [n ± 30–50]
### Scores
| Dimension | Score | Max |
|------------------------|-------|-----|
| Instruction Budget | [n] | 2 |
| Section Quality | [n] | 2 |
| 80% Rule Compliance | [n] | 2 |
| Progressive Disclosure | [n] | 2 |
| Safety & Hygiene | [n] | 2 |
| Structure | [n] | 2 |
| **Total** | **[n]** | **12** |
**Grade:** [see scale below]
Grade scale:
| Total | Grade | |-------|--------------| | 10–12 | Optimized | | 7–9 | Functional | | 4–6 | Needs work | | 0–3 | Rewrite |
After the table:
When Progressive Disclosure scores 0 or 1, include as a Top 3 item: "Consider invoking the sibling
memory-tools:path-rules-advisorskill to break path-specific content into.claude/rules/files — it is purpose-built for this workflow. You can also use Step 5's inline rule-file generation as a fallback."
When Safety & Hygiene scores below 2 due to default-restating rules, name them explicitly in the per-dimension finding: quote one or two examples from the file and label them "default-restating" so the user can recognise the pattern and apply the same cut test to the rest.
Use AskUserQuestion to ask: "Would you like me to generate an optimized version of this file in the chat?" (Yes / No)
If the user says yes, generate the optimized content in a code block in the chat (do not write to disk yet). Apply these transformations:
[REDACTED - move to .env]).claude/rules/ files below, not embedded in the CLAUDE.md outputOffer to generate .claude/rules/ files:
For each section removed as an 80%-rule violation or path-specific content:
paths: frontmatter:---
paths:
- "<glob>"
---
# <Descriptive Title>
- Rule bullet 1
- Rule bullet 2
- Rule bullet 3
.claude/rules/ exists. If not, use AskUserQuestion to ask: "The .claude/rules/ directory does not exist. Should I create it?" (Yes / No)AskUserQuestion to ask: "Should I write this to .claude/rules/<name>.md?" (Yes / No) Wait for explicit confirmation before writing each file.Path-rules delegation: If Progressive Disclosure scored ≤ 1, recommend invoking
memory-tools:path-rules-advisorinstead of manually creating rule files here. Keep the inline flow above as a fallback if the user prefers to stay in this skill.
After the CLAUDE.md code block, show a separate callout:
To make this skill always available in your project, add the following to your CLAUDE.md
(replace <plugin-dir> with the path passed to --plugin-dir when loading this plugin):
@<plugin-dir>/skills/agentic-memory-management/SKILL.md
If the user says no, stop here.
Use AskUserQuestion to ask: "Should I write this to disk? Commit or back up your current CLAUDE.md first — this will overwrite it." (Yes / No)
If the user says yes, use AskUserQuestion again with: "Final confirmation: overwrite <audited file path> with the optimized version now?" (Yes / No)
Write only the file that was audited in Step 1, and only after both confirmations are affirmative.
Verification gate — before writing, re-check the audited file's own frontmatter. If it opens with
---and that block is unterminated or contains a line that is not a YAML key/value, do not overwrite it: REPORT rather than write, naming the file and the offending line.
Run immediately after the Step 6 write. Show the resulting diff, then assert the file still parses and still has a body.
TARGET=<substitute the path written in Step 6 — not a literal>
if git ls-files --error-unmatch "$TARGET" >/dev/null 2>&1; then
git --no-pager diff -- "$TARGET"
else
git --no-pager diff --no-index -- /dev/null "$TARGET" || true
fi
python3 - "$TARGET" <<'EOF'
import sys
path = sys.argv[1]
text = open(path, encoding='utf-8').read()
body = text
if text.startswith('---\n'):
end = text.find('\n---', 3)
if end == -1:
sys.exit(f"MALFORMED: {path} opens a frontmatter block that is never closed")
for n, line in enumerate(text[4:end].splitlines(), 2):
# Indented lines are nested values or block-scalar continuations, which
# carry no colon of their own. Only top-level keys are checked.
if not line.strip() or line[:1] in (' ', '\t'):
continue
s = line.strip()
if not s.startswith(('#', '- ')) and ':' not in s:
sys.exit(f"MALFORMED: {path} line {n}: expected a YAML key/value, got {s!r}")
body = text[end + 4:]
if not body.strip():
sys.exit(f"EMPTY: {path} has no body content")
print(f"OK: {path} parses, {len(body.strip().splitlines())} body lines")
EOF
If the command exits non-zero, STOP. Report the failure with the file path and the printed
reason, tell the user to restore from their backup (git checkout -- <path> where the file is
tracked), and do not attempt a second write.
development
Checks whether the branch's PR is ready and merges it when green. Runs the readiness gate, lint, and an approval prompt. Use when the user asks "merge?" or if a PR is ready to merge.
development
Implements a plan file that already exists. Walks its steps, ticks the spec, re-renders, and runs the completion gates. Use when asked to implement an existing plan.
development
Converts an HTML artifact or Markdown file into a draft post for a static site. Scopes CSS to keep interactive blocks alive and escapes prose for MDX. Use when asked to turn an artifact into a post.
development
Writes lifecycle status into a plan's frontmatter, one file or a directory. Inspects codebase and git history for accurate dates. Use when asked to check or update plan status.