MCPInstall

memory-optimize

Optimizes Claude Code memory files in 4 interactive steps: removes duplicates, migrates rules to CLAUDE.md/rules files, compresses remaining entries, validates with cleanup. Typical reduction: 30-50% on token count.

Installs
1.5K
Last 24h
—
Trending rank
—
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/kochetkov-ma/claude-brewcode --skill memory-optimize
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads memory-optimize automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

Plugin: kochetkov-ma/claude-brewcode

Memory Optimizer

Optimizes Claude Code auto-memory files in 4 interactive steps: removes duplicates, migrates rules to proper config files, compresses remaining entries, validates the result. Typical reduction: 30–50% token count in memory files.

Auto-memory stores context across sessions in ~/.claude/projects/**/memory/MEMORY.md. Enable: CLAUDE_CODE_DISABLE_AUTO_MEMORY=0 · Disable: CLAUDE_CODE_DISABLE_AUTO_MEMORY=1

Benefits: faster context loading · no duplicate rules · cleaner instructions · lower API cost

Usage:

/memory-optimize          # no args — starts 4-step interactive workflow

Skill text is written for LLM consumption and optimized for token efficiency.


Memory Optimizer

Optimizes Claude Code memory files through 4 interactive steps.

No context: fork — must run in main conversation to spawn agents.

Phase 0: Load Context

  1. Glob all memory files: ~/.claude/projects/**/memory/*.md
  2. Read ~/.claude/CLAUDE.md and project CLAUDE.md (if exists)
  3. Glob .claude/rules/*.md — read all project rules
  4. Read ~/.claude/rules/*.md — read all global rules

Build context map:

memory_files: [paths]
claude_md_sections: [sections]
rules_files: [paths with content]

Step 1: Analysis — Remove Duplicates (Interactive)

Goal: Find memory entries that duplicate content already in CLAUDE.md or rules.

  1. Spawn Explore agent to cross-reference all loaded files
  2. Identify entries where:
    • Same rule already in CLAUDE.md
    • Same pattern already in a rules file
    • Contradicts CLAUDE.md (CLAUDE.md wins)
  3. Show analysis:
    Found X duplicate/redundant entries (Y% of memory):
    | Entry | Memory File | Already In | Action |
    |-------|-------------|------------|--------|
    | "Search via Bash grep" | MEMORY.md:5 | rules/code-search.md | DELETE |
    ...
    
  4. AskUserQuestion: "Delete X duplicate entries (Y% of memory)? This is safe — content exists elsewhere."
    • Options: "Yes, delete all" / "Review each" / "Skip this step"
  5. Apply deletion using Edit tool if approved

Step 2: Migration — Move to Rules/CLAUDE.md (Interactive)

Goal: Identify remaining memory entries better suited to persistent config files.

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 → KEEP in memory
  1. Show categorization:
    X entries suitable for migration:
    | Entry | Current Location | Target | Reduction |
    |-------|-----------------|--------|-----------|
    | "Always use BD_PLUGIN_ROOT" | MEMORY.md:12 | .claude/rules/brewdoc.md | 15 tokens |
    ...
    Total: X entries → ~Y tokens saved
    
  2. AskUserQuestion: "Migrate X entries to rules/CLAUDE.md?"
    • Options: "Yes, migrate all" / "Review each" / "Skip this step"
  3. If approved:
    • Create/append to target rule files via Edit
    • Remove migrated entries from memory via Edit
    • If target file doesn't exist, create it

Step 3: Compression (Interactive)

Goal: Compress remaining entries using LLM-efficient formatting.

Compression techniques:

  • Prose → table row
  • Multiple related entries → single table
  • Verbose description → imperative one-liner
  • List of examples → pattern + one example
  1. Show compression preview:
    Compression opportunities found:
    | Before | After | Savings |
    |--------|-------|---------|
    | "When you need to... always use..." | "Use X for Y" | 8 tokens |
    ...
    Total: ~Y% token reduction (~Z tokens)
    
    Show 2-3 specific before/after samples.
  2. AskUserQuestion: "Compress remaining memory? (~Y% reduction)"
    • Options: "Yes, compress all" / "Skip compression"
  3. Apply compression via Edit (bottom-up order to preserve line numbers)

Step 4: Validation (Automatic)

Goal: Verify final state and clean orphaned references.

  1. Spawn reviewer agent to verify:
    • No broken file path references in memory files
    • No contradictions between memory and CLAUDE.md
    • Memory files are well-formed markdown
  2. Clean broken references (Edit tool)
  3. Check for orphaned memory files (files in ~/.claude/projects/**/memory/ with no MEMORY.md reference)
  4. Report orphaned files and ask to delete

Final Report:

## Memory Optimization Complete

### Summary
| Metric | Before | After | Saved |
|--------|--------|-------|-------|
| Total entries | X | Y | Z |
| Duplicate entries | X | 0 | — |
| Migrated entries | — | — | X |
| Token estimate | ~X | ~Y | ~Z (~P%) |

### Changes Made
- Step 1: Deleted X duplicate entries
- Step 2: Migrated X entries to rules/CLAUDE.md
- Step 3: Compressed X entries (Y% reduction)
- Step 4: Fixed X broken references, removed X orphaned files

### Final Memory Structure
{directory listing of ~/.claude/projects/.../memory/}

---

**Part of brewdoc:** [brewcode](https://github.com/kochetkov-ma/claude-brewcode) — docs tools: memory optimization, Claude installation docs, Markdown to PDF.
Install: `claude plugin marketplace add https://github.com/kochetkov-ma/claude-brewcode && claude plugin install brewdoc@claude-brewcode`

FAQ

What does the memory-optimize skill do?

Optimizes Claude Code memory files in 4 interactive steps: removes duplicates, migrates rules to CLAUDE.md/rules files, compresses remaining entries, validates with cleanup. Typical reduction: 30-50% on token count.

How do I install memory-optimize?

Run npx skills add https://github.com/kochetkov-ma/claude-brewcode --skill memory-optimize in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/memory-optimize/ (personal) or .claude/skills/memory-optimize/ (project).

Which AI agents can use memory-optimize?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is memory-optimize safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains memory-optimize?

It is published by kochetkov-ma in kochetkov-ma/claude-brewcode. It has 1,490 recorded installs.

More from kochetkov-ma/claude-brewcode

View all →

text-optimizer

kochetkov-ma/claude-brewcode

Optimizes text, prompts, and documentation for LLM token efficiency. Applies 52 research-backed rules across 8 categories: Claude behavior, token efficiency, structure, deduplication, reference integrity, perception, LLM comprehension, and aggressive lossy (deep only). Use when optimizing prompts, reducing tokens, compressing verbose docs, or improving LLM instruction quality.

AI & Agents2.1K installs

brewpage-publish

kochetkov-ma/claude-brewcode

Publish content to brewpage.app — text, markdown, JSON, file, or multi-file site. Asks namespace and password, returns public URL. Triggers: publish, share link, upload to brewpage, host page, brewpage, publish site, upload site, upload directory, deploy site, сделай публичную ссылку, опубликуй.

DevOps & Cloud597 installs

Popular other skills

View category →

hyperframes-cli

heygen-com/hyperframes

The HyperFrames CLI by job - scaffold, check, look at frames, edit the timeline, preview, render locally or in the cloud, publish, project history - plus reading its JSON and recovering from build or render failures.

1.3M installs

triage

mattpocock/skills

Move issues and external PRs through a state machine of triage roles, categorise, verify, grill if needed, and write agent-ready briefs.

1M installs

ask-matt

mattpocock/skills

Ask which skill or flow fits your situation. A router over the skills in this repo.

778.4K installs

to-questionnaire

mattpocock/skills

Turn a decision you can't fully answer into a questionnaire for someone else to fill in.

508.9K installs

wait-what

mattpocock/skills

Stop. That last message did not land: re-pitch it.

459.7K installs

loop-me

mattpocock/skills

Grill me about specs for the workflows I want to build, within this workspace.

447.9K installs