/agent-almanac:prune-agent-memoryfrom agent-almanac
Audits, classifies, and selectively forgets stored memories. Covers enumeration by type/age/access frequency, staleness detection, fidelity checks, a decision tree for withdrawal, tombstoned deaccession, counter-memory inoculation, and preemptive filtering.
Ships in agent-almanac. 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.
Audit, classify, and selectively forget stored memories. Memory is infrastructure. Forgetting is policy. This skill defines the policy.
Where manage-memory focuses on organizing and growing memory (what to keep, how to structure it), this skill focuses on the inverse: what to discard, how to detect decay, and how to ensure that forgetting is deliberate rather than accidental. The two skills are complementary and should be used together during periodic maintenance.
~/.claude/projects/<project-path>/memory/)Read all memory files and classify each entry by four dimensions.
# Inventory the memory directory
ls -la <memory-dir>/
wc -l <memory-dir>/*.md
# Count total entries (approximate by counting top-level bullets and headers)
grep -c "^- \|^## " <memory-dir>/MEMORY.md
for f in <memory-dir>/*.md; do echo "$f: $(grep -c '^- \|^## ' "$f") entries"; done
Classify each memory entry into one of six types — Project, Decision, Pattern, Reference, Feedback, or Ephemeral (default retention rules and examples in policy-reference.md). The wc -l above is inventory, not a cap check: the index has a dual load cap (see Validation).
Also note age (mtime records last write) and an explicitly labeled access-frequency estimate. No read counter exists anywhere in this system — never call an estimate circulation data and never let it carry a withdrawal alone without staleness (Step 2) or fidelity (Step 3) evidence.
Expected: A complete inventory with every memory entry classified by type, with ages and explicitly labeled access-frequency estimates. Ephemeral entries are already flagged for immediate removal.
On failure: If memory files are too large or unstructured to classify entry-by-entry, work at the section level. Classify entire sections rather than individual bullets. The goal is coverage, not granularity.
Compare memory claims against current project state across five patterns: 1. Count drift, 2. Path drift, 3. State drift (closed issues/merged PRs still marked open), 4. Decision reversal, and 5. Tool/version drift. Run the spot-check grep commands in policy-reference.md and mark each stale entry with its pattern and current correct value.
Expected: A list of stale entries with specific evidence of what changed. Each stale entry has a recommended action: update (if the correct value is known), verify (if uncertain), or prune (if the entire entry is obsolete).
On failure: If you cannot verify a claim because it references external state (APIs, third-party docs, deployment status), mark it as unverifiable rather than assuming it is correct. Unverifiable entries are candidates for pruning if they are not actively useful.
Test whether memories still produce accurate, actionable context using external anchors (an agent cannot self-verify its own compressed summaries):
CLAUDE.md / registries.Spot-check commands live in policy-reference.md.
Expected: Each memory entry now has a fidelity assessment: high (verified accurate and useful), medium (probably accurate, occasionally useful), low (unverified or rarely useful), or failed (verified inaccurate or contradictory).
On failure: If fidelity checks are inconclusive for many entries, focus on the entries with the highest potential impact. A wrong memory about project architecture is more dangerous than a wrong memory about a debugging trick. Prioritize checking skeleton-level facts over flesh-level details.
Gate — snapshot before the first withdrawal. A memory directory is almost never under version control, so an overwrite or a delete has no git checkout behind it and is simply unrecoverable. Content-hash every file to a store outside the memory directory before touching anything, and record the manifest path in the pruning log (Step 7). If this gate has not run, no withdrawal in this pass is legitimate.
# Pre-prune snapshot. <snapshot-dir> must be outside <memory-dir>, so that a
# later prune of the memory directory cannot reach the only copy of the content.
mkdir -p <snapshot-dir> && cp -a <memory-dir>/. <snapshot-dir>/
( cd <snapshot-dir> && find . -name '*.md' -type f -print0 | sort -z \
| xargs -0 sha256sum > MANIFEST.sha256 )
wc -l < <snapshot-dir>/MANIFEST.sha256 # verify later: sha256sum -c MANIFEST.sha256
Apply the 7-tier pruning decision tree in order (1. Ephemeral → 2. Failed fidelity → 3. Duplicates → 4. Stale update-or-withdraw → 5. Low fidelity, requiring Step 3 evidence → 6. Medium-fidelity closed work → 7. Freely searchable references — full tree and tombstone rationale in policy-reference.md).
Withdraw, not delete:
<memory-dir>/deaccessioned/<original-name>.md with a tombstone header (deaccessioned_at, reason, superseded_by, register_id) — worked template in references/EXAMPLES.md.MEMORY.md.register_id.Before applying any withdrawal, check whether the entry warrants counter-memory inoculation (Step 5); a withdraw + inoculate outcome produces a SUPERSEDED file in <memory-dir>, a tombstone under deaccessioned/ (excluded from Step 9's top-level orphan scan), and one linked register row.
Expected: A clear list of entries to withdraw, entries to update, and entries to keep — each with a documented reason, each withdrawal carrying a tombstone and a register row. The keep/withdraw ratio depends on memory health; a well-maintained memory might prune 5-10%, a neglected one might prune 30-50%.
On failure: If the decision tree produces ambiguous results for many entries, apply a tighter filter: "Would I write this entry today, knowing what I know now?" If not, it is a withdrawal candidate. Err toward pruning — it is easier to re-learn a fact than to work around a wrong memory, and with tombstones a wrong withdrawal costs one lookup in the register.
Withdrawal alone fails when the conditions that generated an abandoned strategy persist — the system re-derives the same conclusion, and a tombstone outside retrieval does not block it.
Place each SUPERSEDED record as its own file in <memory-dir> (e.g., superseded_strategy_X.md) and add an index line in MEMORY.md in the same edit — an unlinked counter-memory is never retrieved and blocks nothing. Record its path alongside the tombstone path in the Step 7 register. Full SUPERSEDED template, when-NOT-to-inoculate rules, and hygiene guidelines: policy-reference.md.
Expected: For every Step 4 withdrawal candidate involving abandoned strategies or dangerous patterns, a corresponding SUPERSEDED counter-memory file is created before the original entry is withdrawn. One register row records the withdrawal, its tombstone, and its inoculation. Active memory remains lean while the regeneration paths are blocked.
On failure: If unsure whether an entry warrants inoculation, default to inoculate. A redundant SUPERSEDED record costs little; a regenerated bad pattern costs much more. If the SUPERSEDED list grows large enough to be noise itself, that is a signal to investigate the upstream conditions producing repeated abandonments — the fix is at the input layer, not the memory layer.
Define "what NOT to save" rules and flag any existing entries matching prohibited patterns: session-specific task state, intermediate reasoning, debug output/stack traces, brittle exact command sequences, emotional/tonal notes, duplicates of CLAUDE.md, and unverified single observations (full table in policy-reference.md).
Document these rules in MEMORY.md or retention-policy.md. Note that nothing here is enforced at write time — this skill runs out-of-band, so every guarantee in this file is verified when the skill last ran, not an invariant.
Expected: A set of preemptive filter rules documented in the memory directory. Any existing entries matching these patterns are flagged for withdrawal.
On failure: If documenting filter rules feels premature (memory is small, pollution is minimal), skip the documentation but still apply the filters to catch any existing violations. The rules can be formalized later when the memory directory is more mature.
Log every withdrawal so the forgetting itself is reviewable. Create or update <memory-dir>/pruning-log.md (or append to MEMORY.md). Each audit records the entries audited, withdrawn and updated, the Step 4 snapshot manifest path, the staleness patterns found and the fidelity failures — then the accession/deaccession register, one row per withdrawal:
| register_id | Entry (summary) | Type | Reason | Tombstone | superseded_by |
Full log template and a worked register: references/EXAMPLES.md.
Keep the prose parts of the pruning log concise — they exist for accountability, not archaeology, and can be summarized once old ("2025: 3 audits, 47 total entries withdrawn, mostly count drift and ephemeral leakage"). Never summarize away a register row: the row is the only path from the log to the tombstone, and collapsing it strands the body it points at.
Expected: A timestamped pruning log entry documenting what was withdrawn and why, with one register row per withdrawal resolving to a tombstone that exists on disk. The log is stored in the memory directory alongside the memories themselves.
On failure: If creating a separate log file feels excessive (only 1-2 entries withdrawn), append the register rows to MEMORY.md instead — as plain markdown, not an HTML comment, which is stripped before the index reaches the reader. Any record is better than silent deletion.
Make irreplaceable entries immune from pruning (architecture decisions, user identity preferences, timestamped security audit results, rename/migration records — criteria table in policy-reference.md).
protected list in pruning-log.md and check it before Step 4 withdrawals. Never rely on <!-- PROTECTED --> HTML comments in MEMORY.md (comments are stripped before load).Expected: Protected entries survive all prune passes. The pruning log records any protection additions or removals.
On failure: If the protected set grows too large (>30% of total entries), review the criteria — protection is for irreplaceable context, not for "important" entries. Important but reconstructible facts should remain subject to normal pruning.
After withdrawal, remaining memories may be fragmented — cross-references point to withdrawn entries, topic files lose coherence, and MEMORY.md may have gaps. Re-synthesis restores structural integrity. A write succeeding tells you nothing about whether the memory will ever be read again: verify reachability, not write success — and verify it every session, because the operation that breaks reachability (compaction) is the same operation the caps make mandatory.
Re-synthesis checklist:
MEMORY.md and withdraw the topic file.MEMORY.md coherence: read top-to-bottom to confirm it tells a coherent project story.Reachability scan — run after every withdrawal pass, before declaring the pass finished:
# Reachability: the index is the only file loaded automatically, so a topic file
# that nothing links to is not deprioritized — it is invisible.
DIR=<memory-dir>
python3 - "$DIR" <<'PY'
import os, re, sys
d = sys.argv[1]
text = open(os.path.join(d, 'MEMORY.md'), 'rb').read().decode('utf-8', 'replace')
# HTML comments are stripped before the index reaches the model, and the
# stripped content is excluded from the load limits: a note left in one is
# invisible to the reader, and buys nothing by being cheap.
text = re.sub(r'<!--.*?-->', '', text, flags=re.S)
EXAMPLES = {'file.md', 'example.md', 'topic-name.md'} # format-documentation targets
linked = {os.path.basename(m) for m in re.findall(r'\]\(([^)#\s]+\.md)', text)} - EXAMPLES
on_disk = {f for f in os.listdir(d) if f.endswith('.md') and f != 'MEMORY.md'}
orphans, dangling = sorted(on_disk - linked), sorted(linked - on_disk)
size = lambda names: sum(os.path.getsize(os.path.join(d, n)) for n in names)
tot = size(on_disk) or 1
print(f"topic files {len(on_disk)}; linked {len(linked & on_disk)}")
print(f"ORPHANS {len(orphans)} = {len(orphans)/max(len(on_disk),1):.1%} of files, {size(orphans)/tot:.1%} of bytes")
print(f"DANGLING {len(dangling)} (linked, absent on disk)")
for n in orphans: print(f" orphan {n}")
for n in dangling: print(f" dangling {n}")
PY
Redirect or remove every dangling link; re-link or withdraw every orphan (the scan honors four standing rules — example-target exclusion, exact-link reachability, HTML-comment stripping, and dual file/byte denominators — detailed in policy-reference.md). deaccessioned/ tombstones live in a subdirectory and never report as orphans.
Expected: Post-pruning memory is structurally sound — zero dangling links, zero unintended orphans, no redundant fragments, no incoherent topic files. Cold entries are classified for future pruning decisions.
On failure: If re-synthesis reveals that pruning was too aggressive (critical context was lost), find the register row in the pruning log and restore the body from its tombstone under deaccessioned/. This is why the audit trail carries content and not just a summary. If a register row has no tombstone behind it, fall back to the Step 4 snapshot manifest — and treat the missing tombstone as the finding, because it means a withdrawal in this pass was really a deletion.
When stored facts become silently wrong because reality changed (counts, paths, versions, or tool output contradictions), repair in-place where ground truth is determinable: 1. Identify drift against current ground truth → 2. Update in-place with [corrected YYYY-MM-DD] (or flag unverifiable for withdrawal) → 3. Trace gradual vs. discrete causes (scanning sibling entries after renames/migrations) → 4. Prevent recurrence by referencing authoritative sources instead of fast-moving numbers. Full triggers and steps in policy-reference.md.
Expected: Drifted memories are corrected in-place where possible, preserving context. Entries that cannot be corrected are flagged for pruning. Prevention rules reduce future drift.
On failure: If drift is widespread (>20% of entries), the memory may need a full rebuild rather than incremental correction. In that case, snapshot the current memory directory with Step 4's gate, start fresh, and selectively re-import entries that pass verification — the snapshot is what makes "start fresh" reversible.
deaccessioned/ carrying the full original body, and every tombstone resolves from a register row by register_idmax(size / 25000, lines / 200) < 0.80), reported as both numbersmtime will not settle it because it records writes.manage-memory — the complementary skill for organizing and growing memory; use together for complete memory maintenanceverify-memory-integrity — the non-mutating pass that measures both caps and reachability without changing anything; run it before this skill so the withdrawal decisions rest on numbers rather than impressions, and again after, to confirm the pass left the store reachablemeditate — clearing and grounding that may reveal which memories are creating noiserest — sometimes the best memory maintenance is not doing memory maintenanceassess-context — evaluating reasoning context health, which memory quality directly affectsWhat SKILL.md sets; muted values are Claude Code's defaults
Generated from the plugin's indexed repository (pjt222/agent-almanac) — no native marketplace selected
npx claudepluginhub p/pjt222-agent-almanac377 skills in this plugin
/adapt-architectureExecute structural metamorphosis using strangler fig migration, chrysalis phases, and interface preservation. Covers transformation planning, parallel running, progressive cutover, rollback design, and post-metamorphosis stabilization for system architecture evolution. Use when assess-form has classified the system as READY for transformation, when migrating from monolith to microservices, when replacing a core subsystem while dependents continue operating, or when any architectural change must be gradual rather than big-bang.
/adapticMaster skill composing the 5-step synoptic cycle for panoramic synthesis across multiple domains. Orchestrates meditate, expand-awareness, observe, awareness, integrate-gestalt, and express-insight into a coherent process that produces unified understanding rather than sequential compromise. Use when a problem genuinely spans 3+ domains and the interactions between domains matter more than depth in any one, when sequential analysis feels like compromise rather than integration, or before major architectural decisions affecting multiple stakeholders.
/add-puzzle-typeScaffold a new puzzle type across all 10+ pipeline integration points in jigsawR. Creates the core puzzle module, wires it into the unified pipeline (generation, positioning, rendering, adjacency), adds ggpuzzle geom/stat layers, updates DESCRIPTION and config.yml, extends the Shiny app, and creates a comprehensive test suite. Use when adding a completely new puzzle type to the package or following the 10-point integration checklist to ensure nothing is missed end-to-end.
Other plugins' skills for the same job