kanevry/session-orchestrator/memory-cleanup

Claude Code and agent skill by kanevry/session-orchestrator

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Use this skill when performing manual memory consolidation (Dream-equivalent). Reviews, consolidates, and prunes memory files under ~/.claude/projects/*/memory/. Run after major refactors, every 5+ sessions, or when memory quality degrades (broken links, stale references, contradictions, MEMORY.md > 200 lines). Invoke with /memory-cleanup.

Install

npx vskill@latest install kanevry/session-orchestrator/memory-cleanup

SKILL.md

The same SKILL.md was published earlier as kanevry/session-orchestrator/memory-cleanup.

Memory Cleanup — Manual Dream Process

Plugin root: ${CLAUDE_PLUGIN_ROOT}. Claude Code replaces this with the plugin's absolute path when it loads this file. Where it appears unreplaced — in a file this skill reads with the Read tool, or on Codex, Cursor or Pi — the plugin root is the directory that contains this skill's skills/ folder (two levels above the folder of this SKILL.md). Write that absolute path literally into every command that starts a plugin script: the Bash tool has no plugin variable, and shell variables do not survive between tool calls.

Invocation

The user invoked /memory-cleanup with arguments: $ARGUMENTS. Parse them before anything else — two optional, mutually-exclusive flags are recognised (--dry-run, --apply-pending, see PRD #502); passing both is an error, and the absence of both selects the legacy interactive 4-phase mode. The per-flag behaviour, the exact status lines and the exit codes are in § Argument Handling (Phase 0) below; the interactive default runs Phases 1-4 (Orient → Gather Signal → Consolidate → Prune & Index) against ~/.claude/projects/<encoded-cwd>/memory/ and reports per § Output.

Sidecar producer/consumer contract: session-start's maintenance-due probe uses scripts/lib/auto-dream.mjs to report when cleanup is due; the former session-end Phase 3.6.5 nudge was retired in #1288. Neither path generates the sidecar. The only real producer of .orchestrator/pending-dream.md is a manual /memory-cleanup --dry-run run; --apply-pending is the operator-confirmed consumer in a later session. The sidecar file is single-writer — concurrent sessions cannot collide because the writer holds the session-lock. <!-- path-check: example -->

Implements the 4-phase memory consolidation process modelled after Claude Code's Auto Dream feature. Run after major refactors, framework migrations, or every 5+ sessions in a repo.

The memory system lives at ~/.claude/projects/<encoded-cwd>/memory/ and consists of:

  • MEMORY.md — index file (must stay under 200 lines; lines after 200 are truncated by the harness).
  • Topic files — one Markdown file per memory entry with YAML frontmatter (name, description, metadata.type).

The four memory types are user, feedback, project, reference (see global auto memory instructions for semantics). This skill never invents new types.

Argument Handling (Phase 0)

This skill accepts two optional flags. Default (no flag) runs the interactive 4-phase consolidation defined below.

FlagBehavior
--dry-runRun Phases 1-3 read-only; instead of mutating MEMORY.md / topic files, write a complete-body MEMORY.md proposal (single fenced block — never a unified-diff) to .orchestrator/pending-dream.md (atomic). Exit 0. <!-- path-check: example -->
--apply-pendingRead .orchestrator/pending-dream.md; refuse if older than 14 days (stale) or if MEMORY.md changed since the producing --dry-run (stale-index, #788); apply diff; delete pending file; print auto-dream applied: -<X> lines, +<Y> entries. Exit 0. <!-- path-check: example -->

Flags are mutually exclusive — passing both is an error. Absence of both = legacy interactive mode (Phases 1-4 below).

`--dry-run` flow:

  • Read MEMORY.md and topic files (read-only).
  • Produce the same internal plan the interactive mode would (merges, prunes, rewrites).
  • Serialisation contract (#717 — load-bearing, read before writing the proposal): applyPendingDream() in scripts/lib/auto-dream.mjs consumes ONLY the FIRST fenced code block in the sidecar body and writes it VERBATIM as the complete new MEMORY.md. It does NOT parse or apply git-style diff hunks. Therefore the proposal MUST ALWAYS be the complete new MEMORY.md body, in EXACTLY ONE fenced `markdown block — never git-style unified-diff hunks (--- /+++ /@@ … @@ lines), and never multiple fences for MEMORY.md itself. Any topic-file (non-MEMORY.md) change needed by the plan CANNOT be carried inside that single fence — instead, append it AFTER the fence as a separate, clearly-delimited machine-readable section per topic file, using the heading ### Topic-file change: <path> followed by plain-language instruction text (not a diff). These sections are for a human to apply by hand; applyPendingDream() never reads past the first fence. If a ### Topic-file change: section needs to show illustrative code, use 4-space-indented code text, never a fenced `` block — countFencedBlocks()` counts every fence in the raw sidecar body (not just MEMORY.md's), so a second fence anywhere in the document trips the >1-fence unsupported-format guard and blocks the whole apply.
  • Call writePendingDream({ repoRoot, diff, sourceSession, memoryLinesBefore, proposedLinesAfter }) from scripts/lib/auto-dream.mjs, passing the single-fence MEMORY.md body (plus any ### Topic-file change: sections) as diff.
  • Print one-line status: pending-dream written: <N> lines proposed (or no consolidation needed (MEMORY.md is healthy) when the plan is empty).
  • Exit 0 in both branches.

`--apply-pending` flow:

  • Call applyPendingDream({ repoRoot, memoryDir }) from scripts/lib/auto-dream.mjs.
  • Behavior matrix on the helper return:
  • applied: true → print auto-dream applied: -<linesBefore-linesAfter> lines, +<entries> consolidated entries and exit 0.
  • applied: false, reason: 'missing' → print no pending dream to apply and exit 1.
  • applied: false, reason: 'stale' → print pending dream is stale (>14d), re-run --dry-run and exit 1.
  • applied: false, reason: 'stale-index' (#788) → print MEMORY.md changed since the producing --dry-run; re-run --dry-run. and exit 1. The sidecar is preserved and MEMORY.md is left untouched (MEMORY.md's mtime is newer than the sidecar's generated_at, so applying the frozen dry-run snapshot would clobber the interim edits).
  • applied: false, reason: 'unsupported-format' → print auto-dream NOT applied: pending-dream.md contains git-style diff hunks this applier cannot consume. MEMORY.md left untouched, sidecar preserved. Re-run /memory-cleanup --dry-run to regenerate a complete-body proposal. and exit 1.
  • The sidecar file is deleted on successful apply; staleness (stale / stale-index), missing sidecar, or unsupported-format never deletes anything.

Both flag-driven flows delegate atomicity and staleness enforcement to scripts/lib/auto-dream.mjs. The interactive Phases 1-4 below remain unchanged.

Phase 1: Orient

Understand the current memory state before making changes.

  1. List all files in the memory directory:

``bash ls -la ~/.claude/projects/*/memory/ 2>/dev/null | grep "$(basename "$(pwd)")" ` Or directly list the project's memory dir (the path is in the auto memory` system instructions).

  1. Read MEMORY.md (the index file) — note its line count:

``bash wc -l <memory-dir>/MEMORY.md ``

  1. Skim each topic file referenced in the index. Build a mental map:
  • Which topics are covered?
  • Are there overlapping files?
  • Any files not referenced in the index?
  • Any index entries pointing to files that no longer exist?

Goal: Improve existing files, never create duplicates.

Phase 2: Gather Signal

Find what's changed since the last consolidation.

  1. Git history — recent commits give the timeline for "did this fact change?":

``bash git log --oneline -20 ``

  1. Stale references — for each file/function/symbol mentioned in memory, verify it still exists:

``bash grep -rn "specific-file-or-function" src/ lib/ scripts/ 2>/dev/null ``

  1. Relative dates — find temporal references that need conversion:

``bash grep -rni "yesterday\|today\|tomorrow\|last week\|this week\|gestern\|heute\|morgen\|letzte woche" <memory-dir>/ ``

  1. Version drift — package versions stored in memory vs reality:

``bash cat package.json | grep '"version"' ``

  1. Test/issue-count drift — claims like "5001 passed" or "8 open issues" age fast. Cross-check with current state if mentioned.

Phase 3: Consolidate

Apply maintenance operations to memory files.

3·0: Find dead index links first (#1801)

Before rewriting anything, list every MEMORY.md link whose target file is missing (the BROKEN: check from Phase 4 step 5, run now). It calls listDeadIndexLinks(), the same definition behind the session-start count memory: <N> tote Index-Links. Per dead link:

  • Rescue its core sentence into an existing era/history note or a Meta-Vault note that already covers it, quoting only what the index line or that note states.
  • Otherwise delete the index line. Never invent content for a file you cannot read.
3a: Merge overlapping entries

If multiple files or entries describe the same thing, combine them into one authoritative entry. Update inbound [[wiki-link]]s accordingly.

3b: Convert relative dates to absolute

"Yesterday we decided X" → "On 2026-03-24 we decided X". Always use ISO date format (YYYY-MM-DD). This rule applies on write, but cleanup catches what slipped through.

3c: Remove stale references
  • Delete entries about files that were removed during refactors.
  • Remove debugging notes for bugs that are fixed.
  • Update function/file paths that were renamed (git log --diff-filter=R surfaces renames).
3d: Update outdated facts
  • Package versions that have been bumped.
  • Test counts, issue counts, line counts that changed.
  • Feature flags that were toggled.
  • Architecture decisions that were reversed (keep a decisions.md-style note that the decision was reversed, with the reason — don't silently overwrite).
3e: Resolve contradictions

If two memory entries conflict, check the codebase to determine which is current. Delete the outdated entry. Never leave contradictions.

Phase 4: Prune & Index

Keep MEMORY.md clean and under the 200-line limit.

  1. Check line count:

``bash wc -l <memory-dir>/MEMORY.md ``

  1. If over 180 lines, extract detailed content into topic files. Suggested naming:
  • Session summaries → project_sessions.md or session-YYYY-MM-DD-<slug>.md
  • Architecture decisions → reference_decisions.md
  • Package/tooling details → reference_packages.md
  • Use the convention: {type}_{topic}.md
  1. Topic file frontmatter (required):

```yaml


name: descriptive-name description: one-line description for relevance matching metadata: type: project # one of: user | feedback | project | reference


```

  1. Update the index:
  • MEMORY.md is an index, not a dump.
  • One-line - [Title](file.md) — hook entries.
  • Remove stale pointers to deleted files.
  • Add links for new topic files.
  • Reorder by relevance (most-accessed topics first).
  1. Final verification:

``bash wc -l <memory-dir>/MEMORY.md # must be < 200 # dead index links (the session-start definition) — must print nothing; throws without MEMORY.md node --input-type=module -e "const { listDeadIndexLinks } = await import('${CLAUDE_PLUGIN_ROOT}/scripts/lib/auto-dream.mjs'); const d = listDeadIndexLinks(process.argv[1]); if (!d) throw new Error('no MEMORY.md'); for (const t of d) console.log('BROKEN: ' + t);" <memory-dir> ``

Phase 4.5: Worktree-Stale-Sweep (#575 P3.2)

Skip if persistence: false in Session Config. Silent no-op if no Auto-promoted sibling worktrees exist or none are stale.

Detect stale Auto-promoted worktrees (older than stale-branch-days from Session Config, default 7 days) and offer them for batch-removal alongside the other housekeeping prune actions from Phase 4. This sub-phase is additive — it appends candidates to the existing prune flow rather than introducing a separate independent confirmation cycle.

Detection: list candidate auto-promoted worktrees

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
52
Repository forks
7
7-day trend score
20

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/kanevry/session-orchestrator/memory-cleanup/badge)](https://verified-skill.com/skills/kanevry/session-orchestrator/memory-cleanup)

Something wrong with this skill or its page? Tell us.