memory — clean up memory files
Caution
Memory files accumulate silently. Entries duplicate rules already in CLAUDE.md, verbose prose inflates every session load, and contradictions pile up unnoticed. Claude reads the full memory on every startup — deadweight entries cost real tokens every time.
Tip
One command, four interactive steps. Each step shows exactly what it proposes and waits for your approval. Nothing is deleted without confirmation. Run it anytime memory feels noisy.
Quick reference
| Field | Value |
|---|---|
| Command | /brewdoc:memory |
| Arguments | none — runs a 4-step interactive workflow |
| Model | opus |
| Tools | Read, Write, Edit, Glob, Grep, Bash, Task, AskUserQuestion |
When to use
- Memory files have grown over weeks and feel cluttered
- Claude auto-selects wrong rules because of conflicting memory entries
- You added new
.claude/rules/files and want to remove redundant memory entries - Session startup feels slow and you want to reduce context load
- You want to move project-specific constraints from memory into proper rules files
Examples
# Run the full 4-step interactive flow
/brewdoc:memory
The skill auto-detects your memory directory, loads all related files, then walks through each step.
# Natural language also works
"optimize my memory"
"clean up claude memory files"
"brewdoc:memory"
After Step 4, the skill prints a summary report:
## Memory Optimization Complete
| Metric | Before | After | Saved |
|----------------|--------|-------|------------|
| Total entries | 42 | 18 | 24 |
| Duplicates | 11 | 0 | — |
| Migrated | — | — | 8 |
| Estimated tokens | ~1 800 | ~620 | ~1 180 (~65%) |
Flow
- Load context
The skill reads your memory directory (from
autoMemoryDirectoryin.claude/settings.json, or the legacy~/.claude/projects/<hash>/memory/path), then loads~/.claude/CLAUDE.md, projectCLAUDE.md, and all rules files — both global and project-level. This full context map drives all four analysis steps. - Step 1 — Remove duplicates
An
Exploreagent cross-references every memory entry against CLAUDE.md and.claude/rules/*.md. Entries that already exist in rules, or that contradict CLAUDE.md (CLAUDE.md wins), are shown in a table. You choose: “Delete all”, “Review each”, or “Skip”. - Step 2 — Migrate to rules / CLAUDE.md
Remaining entries are categorised by target: global rules go to
~/.claude/rules/, project rules to.claude/rules/, architectural decisions to project CLAUDE.md, cross-session facts stay in memory. A table with estimated token savings is shown before any migration is applied. - Step 3 — Compress
What remains is compressed for LLM efficiency: prose becomes table rows, related entries merge, verbose descriptions shrink to imperative one-liners, example lists reduce to a pattern plus one example. A before/after preview with estimated savings is shown. You confirm or skip.
- Step 4 — Validate and clean up
A
revieweragent checks the final state: broken file references, conflicts with CLAUDE.md, malformed markdown. Broken references are fixed automatically. Orphaned memory files — files in the memory directory not referenced fromMEMORY.md— are detected and proposed for deletion.
Internals
Memory directory detection
The skill resolves $MEMORY_DIR in this order:
- Read
.claude/settings.json→ extractautoMemoryDirectory - If set:
<git-root>/<autoMemoryDirectory> - If not set: glob
~/.claude/projects/**/memory/*.md(legacy path)
Context map built before Step 1
| Source | What is loaded |
|---|---|
| Memory directory | All *.md files |
| Global instructions | ~/.claude/CLAUDE.md |
| Project instructions | CLAUDE.md (if present) |
| Global rules | ~/.claude/rules/*.md |
| Project rules | .claude/rules/*.md |
Migration decision tree (per entry)
- Applies to all projects + is a rule/constraint →
~/.claude/rules/ - Applies to this project only + is a rule →
.claude/rules/ - Is an architectural decision → project
CLAUDE.md - Is a fact/pattern reusable across sessions → stays in memory
Compression techniques
- Prose → table row
- Multiple related entries → single table
- Verbose description → imperative one-liner
- List of examples → pattern + one example
Edits are applied bottom-up (descending line number order) to preserve line numbers during multi-edit operations.
No context: fork — the skill must run in the main conversation to spawn Explore and reviewer agents.
Auto-sync
Keep docs in sync automatically — the other core brewdoc skill.
My-claude
Generate Claude Code installation docs for your project.
GitHub source
Source code and full SKILL.md for the memory optimizer.
Brewdoc overview
All brewdoc skills in one place.
Updating plugins
/brewtools:plugin-update to check and update the brewcode plugin suite in one command.
See the FAQ for details.