agentleFS
EJRyan89EJRyan89/coding-agent-skills/skills/curate-agent-memory/SKILL.md

curate-agent-memory

Skill2 starsChanged 18 days agoMITView on GitHub

Audit and clean up Claude Code auto-memory for a project: find stale, duplicated, or misplaced memories, move durable rules to their proper home, and apply only the changes the user approves. Use it when asked to review, tidy, or prune a project's memories.

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Memory directory: use --memory-dir when given.

    line 17
  2. Very specific:

    Ask which groups to apply with a multi-select AskUserQuestion, one option per non-empty group.

    line 68
  3. Very specific:

    Only then delete or rewrite the memories those changes cover.

    line 73
  4. Very specific:

    When any memory changed or the "Rebuild index" group was approved, rebuild MEMORY.md last instead of editing it by hand:

    line 81
  5. Distinctive:

    Do not commit, push, or open pull requests.

    line 88

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Curate agent memory

Memory is for facts about the user and their work that nothing else records. Rules that belong to a repository, a skill, or the user's global instructions drift out of sync when they live only in memory. This skill finds those, proposes where each belongs, and changes nothing without approval.

Step 1: Resolve the memory directory

Everything later deletes or rewrites files, so the target must be the store Claude Code actually uses.

  • Repository: the argument, else the current Git repository root. Worktrees of one repository share a single store.
  • Memory directory: use --memory-dir when given. Otherwise resolve it. The command below resolves it for the current repository; when the user named another repository, add --repo "<repository>":

    {{PYTHON}} -B "${CLAUDE_SKILL_DIR}/scripts/memory_audit.py" resolve

    It prints REPO <root>, the repository to use from here on; then MEMORY_DIR <path>, SOURCE <where it came from>, EXISTS yes or EXISTS no, and REFUSED <reason> when the later steps would refuse that directory, or NO_MEMORY_DIR when no usable directory resolves; a CANDIDATE <dir> line for each other memory directory it found when no usable one resolved; and a NOTE line for each caveat, such as the --settings launch flag it cannot see. FAILED not inside a Git repository means you must pass --repo; a FAILED line naming CLAUDE_CONFIG_DIR, USERPROFILE, or HOME as not an absolute path means the user must set that variable as the line says; any other FAILED <reason> means git could not read the repository, or a settings file it names could not be read. Either way, show it and stop.

  • On NO_MEMORY_DIR, EXISTS no, or REFUSED, show the reason and notes, list the CANDIDATE lines, and ask the user to choose or supply --memory-dir. Never guess.
  • Show the user the resolved directory and its source, and get explicit confirmation before continuing.

Step 2: Run the mechanical audit

{{PYTHON}} -B "${CLAUDE_SKILL_DIR}/scripts/memory_audit.py" audit --memory-dir "<memory dir>" --repo "<repository>"

It prints REPORT <path>, a new JSON file in the system temporary directory; read that file. FAILED <reason> means it wrote no report; show the reason, which may name a variable to set, as in Step 1. A FAILED <memory dir> ... line means the later steps would refuse the directory too, so go back to Step 1 before changing anything. Its overlaps (up to three passages in the repository's or the user's guidance per memory, with overlaps_omitted counting any more it left out) are candidates only; the script cannot tell whether a passage states the same rule. Each cited path gives "exists": true or false for a path that is there or is not; "exists": null with an "unreadable" reason means the path could not be examined, which is no evidence that it is gone: report it as unreadable, and never take the memory for obsolete on it.

Step 3: Verify and classify every memory

Read every memory file in full, in one turn as parallel calls, and every overlapping passage in context. Memories are point-in-time notes, so check any claim about code, paths, or configuration by searching the current files with Grep before relying on it.

Assign each memory exactly one outcome, with a one-line reason and evidence (file:line for anything that exists elsewhere):

OutcomeWhen
KeepA personal preference, identity detail, or fact about the user's work that nothing else records.
Delete: obsoleteIt describes something that no longer exists or no longer applies.
Delete: already coveredIts destination already states the same rule. Cite the passage; similar wording is not enough.
MergeIt overlaps other memories; name the survivor and show the merged text.
Move to global instructionsA rule the user wants in every repository.
Move to repository guidanceA convention for everyone working in this repository (CLAUDE.md, coding guidelines, contributor docs).
Move to a skillA rule about how a specific skill must behave; the destination is a file skill-source prints (below).
Record as a review findingA correction to an automated reviewer's findings rather than a preference. Use flag-review-finding when it is available.

For a move to a skill, find the file to edit. Add --repo "<repository>" as in Step 1, or pass --file "<path>" in place of the name to check a source file the user names:

{{PYTHON}} -B "${CLAUDE_SKILL_DIR}/scripts/memory_audit.py" skill-source "<skill>"

It prints SKILL_FILE <path> for each source of the skill: the checkout the deployer installed it from, and a project skill in the repository. Never edit a deployed copy under a skills directory: the deployer then stops updating that skill, and the next audit never sees the rule. A NOTE line names a file it passed over. When it ends with FAILED <reason>, show the reason; the outcome is Keep unless the user names a source file that --file accepts.

A memory whose rule is not yet at its destination is never simply deleted. Its outcome is the move, and the memory is deleted only after the destination change is applied. If the user declines the move, keep the memory. Record nothing about deferrals; the next run checks again.

Fix mechanical problems from Step 2 as part of the relevant outcome: repair or remove broken links, and bring an index that is over or near its load limit back under it by merging or moving entries. Memories missing from the index, entries whose file is gone, and duplicate entries form one "Rebuild index" group rather than per-memory outcomes. Show each unreadable entry with its reason; it is the user's to resolve.

Step 4: Get approval by group

Present the proposal grouped by outcome, headed by the memory directory it applies to, one line per memory: file, outcome, reason, evidence. For every move, show the exact text that would be added and where.

Ask which groups to apply with a multi-select AskUserQuestion, one option per non-empty group. Offer to review a group item by item when the user wants to exclude individual memories. Apply nothing that was not approved.

Step 5: Apply the approved changes

  • Change destination files first with Edit, reading each before changing it and keeping its existing style and structure. Never replace a whole existing file.
  • Only then delete or rewrite the memories those changes cover. When rewriting one, keep its frontmatter name and description accurate: the index is built from them. Delete approved memories by file name, never with another command:

    {{PYTHON}} -B "${CLAUDE_SKILL_DIR}/scripts/memory_audit.py" delete --memory-dir "<memory dir>" "<file>.md" ...

    It prints DELETED <file> for each file it deletes. A lone FAILED <memory dir> ... line, here or from reindex, means the directory holds no MEMORY.md or lies inside a skills directory, so it changed nothing; show it and go back to Step 1. FAILED <file>: <reason> lines with no DELETED line mean it refused those names and deleted nothing; show the reasons and fix the list. A FAILED line after DELETED lines means the deletion stopped part way: the DELETED files are gone and the rest remain, so show the reason and rerun with the remaining files.

  • For review findings, invoke flag-review-finding through the Skill tool with the memory's substance; delete the memory the same way once the finding is recorded.
  • When any memory changed or the "Rebuild index" group was approved, rebuild MEMORY.md last instead of editing it by hand:

    {{PYTHON}} -B "${CLAUDE_SKILL_DIR}/scripts/memory_audit.py" reindex --memory-dir "<memory dir>" --write

    It writes the index from the memory files and prints WROTE <path>, or UNCHANGED; WOULD_WRITE <path> means --write was left off, so run it again as shown. It first prints one INDEX_LINE <file> per entry of the index, in its order, which needs no report; report its DROPPED, ADDED, and UNREADABLE lines; an UNREADABLE entry is the user's to resolve. OVER_LIMIT (it still writes the index) or NEAR_LIMIT means the index still needs merging or moving entries. A last FAILED <reason> means it could not read a memory or write the index; show the reason.

  • Do not commit, push, or open pull requests; report which repository files changed so the user can review them, and that a change to a skill's source reaches the deployed skill at its next deployment.

Step 6: Re-audit and report

Rerun Step 2. Report what changed per outcome, any destination files edited, and anything the audit still flags. Everything left should be a memory you deliberately kept.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.