
Memory Optimize
- 1.4k installs
- 29 repo stars
- Updated August 2, 2026
- kochetkov-ma/claude-brewcode
memory-optimize is an agent skill that 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
About
memory-optimize is an agent skill from kochetkov-ma/claude-brewcode that 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% . > Plugin: [kochetkov-ma/claude-brewcode](https://github.com/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 fil Developers invoke memory-optimize during build/integrations work for ai & agent building tasks. The skill documents triggers, prerequisites, and step-by-step workflows grounded in SKILL.md. Compatible with Claude Code, Cursor, and Codex agent runtimes that load marketplace skills. Review the Security Audits panel on this listing before installing in production environments.
- Plugin: [kochetkov-ma/claude-brewcode](https://github.com/kochetkov-ma/claude-brewcode)
- 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
Memory Optimize by the numbers
- 1,423 all-time installs (skills.sh)
- +9 installs in the week ending Aug 5, 2026 (Skillselion tracking)
- Ranked #830 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Security screen: HIGH risk (skills.sh audit)
- Data as of Aug 5, 2026 (Skillselion catalog sync)
memory-optimize capabilities & compatibility
- Capabilities
- plugin: [kochetkov ma/claude brewcode](https://g · typical reduction: **30–50%** token count in mem · auto memory stores context across sessions in `~ · enable: `claude_code_disable_auto_memory=0` · di · benefits:** faster context loading · no duplicat
- Use cases
- orchestration
What memory-optimize says it does
> Plugin: [kochetkov-ma/claude-brewcode](https://github.com/kochetkov-ma/claude-brewcode)
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.
npx skills add https://github.com/kochetkov-ma/claude-brewcode --skill memory-optimizeAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 1.4k |
|---|---|
| repo stars | ★ 29 |
| Security audit | 2 / 3 scanners passed |
| Last updated | August 2, 2026 |
| Repository | kochetkov-ma/claude-brewcode ↗ |
What it does
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%
Who is it for?
Developers working on ai & agent building during build tasks.
Skip if: Tasks outside AI & Agent Building scope described in SKILL.md.
When should I use this skill?
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%
What you get
Completed ai & agent building workflow aligned with SKILL.md steps.
- Compressed memory file rewrite
By the numbers
- Targets 30-50% token reduction on agent memory files
Files
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 |
|-------|-------------|------------|--------|
| "Use grepai first" | MEMORY.md:5 | rules/grepai-first.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 saved2. 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, auto-sync, Claude installation docs, Markdown to PDF.
Install: `claude plugin marketplace add https://github.com/kochetkov-ma/claude-brewcode && claude plugin install brewdoc@claude-brewcode`MIT License
Copyright (c) 2025-2026 Maxim Kochetkov (kochetkov-ma)
https://github.com/kochetkov-ma/claude-brewcode
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Memory Optimizer
Optimize Claude Code memory files through a 4-step interactive workflow: remove duplicates, migrate rules to proper config files, compress remaining entries, and validate the result. Typical savings: 30-50% on token count in memory files, meaning faster context loading and lower API cost.
Quick Start
1. Install:
npx skills add kochetkov-ma/claude-brewcode2. Use via slash command:
/memory-optimizeOr via natural language prompt:
Optimize my Claude memory files
Clean up memory duplicatesThe skill scans all memory files under ~/.claude/projects/, cross-references them against your CLAUDE.md and rules files, then walks you through each optimization step with approval prompts before making changes.
Why Use This
- Token savings -- 30-50% fewer tokens in memory context means lower cost and more room for actual work
- Interactive -- approve each step, skip steps you don't want; nothing changes without your confirmation
- Safe -- shows before/after preview before making changes; content is only deleted when it provably exists elsewhere
- Smart migration -- moves rules to proper config files (CLAUDE.md,
.claude/rules/,~/.claude/rules/) so they load reliably instead of depending on memory
What It Does
Step 1: Remove Duplicates
Finds memory entries that already exist in CLAUDE.md or rules files. Shows a table of what is redundant, asks for approval before deleting.
Example:
Found 4 duplicate/redundant entries (35% of memory):
| Entry | Memory File | Already In | Action |
|-------|-------------|------------|--------|
| "Use grepai first" | MEMORY.md:5 | rules/grepai-first.md | DELETE |
| "Constructor injection" | MEMORY.md:12 | CLAUDE.md:## DI | DELETE |
| "No System.out" | MEMORY.md:18 | rules/best-practice.md:7 | DELETE |
| "Edit bottom-up" | MEMORY.md:23 | rules/avoid.md:8 | DELETE |Options: "Yes, delete all" / "Review each" / "Skip this step"
Step 2: Migrate to Rules/CLAUDE.md
Identifies remaining entries that belong in persistent config files rather than memory. Uses a decision tree to categorize each entry:
- Global rule (all projects) -->
~/.claude/rules/ - Project rule (this project) -->
.claude/rules/ - Architectural decision --> project
CLAUDE.md - Reusable fact/pattern --> keep in memory
- Session context --> delete (ephemeral)
Shows a migration plan with target files and token savings, asks for approval before moving anything.
Step 3: Compress
Converts remaining entries to token-efficient formats: prose to table rows, multiple entries to a single table, verbose descriptions to imperative one-liners.
Before:
## Plugin Development (2026-01-15)
When developing plugins, remember to update BOTH plugin.json and marketplace.json
files on version bump, otherwise autocomplete will break because versions won't match.After:
## Plugin Dev
| Rule | Why |
|------|-----|
| Update BOTH plugin.json + marketplace.json on version bump | Autocomplete breaks on mismatch |Shows 2-3 specific before/after samples with token savings, asks for approval.
Step 4: Validate (Automatic)
Runs automatically after the previous steps. Checks for:
- Broken file path references in memory files
- Contradictions between memory and CLAUDE.md
- Malformed markdown
- Orphaned memory files (files with no MEMORY.md reference)
Reports any issues found and offers to fix them.
Where Information Goes
| Content Type | Goes In | Format |
|---|---|---|
| Rule applies to all projects | ~/.claude/rules/*.md | Table |
| Rule applies to this project | .claude/rules/*.md | Table |
| Architectural decision | CLAUDE.md | Section |
| Reusable fact/pattern | MEMORY.md | Section by topic |
| Session context | DELETE | -- |
Part of Brewdoc
This skill is extracted from brewdoc -- a documentation tools plugin for Claude Code with memory optimization, auto-sync, Claude installation docs, and Markdown to PDF.
claude plugin marketplace add https://github.com/kochetkov-ma/claude-brewcode
claude plugin install brewdoc@claude-brewcodeLicense
MIT
Memory Guide
Decision Tree: Where Does This Information Belong?
Is this information?
├── A rule/constraint (should always apply)
│ ├── Applies to ALL projects → ~/.claude/rules/{topic}.md
│ └── Applies to THIS project only → .claude/rules/{topic}.md
├── An architectural decision (project-specific)
│ └── → project CLAUDE.md (## Architecture or ## Decisions section)
├── A reusable pattern/fact (sessions may forget)
│ └── → MEMORY.md (or topic file linked from MEMORY.md)
└── Session-specific context (current task state)
└── → DO NOT save (ephemeral, delete if found)File Location Map
| Content Type | Location | Format |
|---|---|---|
| Global rules | ~/.claude/rules/*.md | Table: # \ |
| Project rules | .claude/rules/*.md | Same format |
| Global instructions | ~/.claude/CLAUDE.md | Sections + tables |
| Project instructions | CLAUDE.md or .claude/CLAUDE.md | Sections |
| Cross-session memory | ~/.claude/projects/{hash}/memory/MEMORY.md | Sections by topic |
| Topic memory | ~/.claude/projects/{hash}/memory/{topic}.md | Linked from MEMORY.md |
Compression Patterns
| Pattern | Before | After | Savings |
|---|---|---|---|
| Prose → imperative | "When you need to update files, you should always use Edit tool..." | "Use Edit (not Write) for existing files" | ~70% |
| List → table row | "Avoid: X. Instead: Y. Because: Z" | `\ | X \ |
| Multiple facts → table | 3 separate entries about the same topic | 1 table row per entry | ~30% |
| Verbose → concise | "It is important to note that..." | Remove filler | ~20% |
Duplicate Detection
An entry IS a duplicate if: 1. Same rule appears in CLAUDE.md (exact or paraphrase) 2. Same pattern in a rules file 3. References a pattern that's been generalized in CLAUDE.md
An entry is NOT a duplicate if: 1. More specific than the CLAUDE.md version (add detail, not replace) 2. Context-specific exception to a general rule 3. Recent discovery not yet in CLAUDE.md
Compression Examples
Before:
## Plugin Development (2026-01-15)
When developing Claude Code plugins, you should always remember to update BOTH plugin.json and marketplace.json files when bumping the version number, otherwise autocomplete functionality will break because the versions won't match.After:
## Plugin Dev
| Rule | Why |
|------|-----|
| Update BOTH plugin.json + marketplace.json on version bump | Autocomplete breaks on mismatch |Bottom-Up Editing
Always apply edits in descending line number order: 1. Sort all changes by line number (descending) 2. Apply from last line to first 3. This preserves line numbers for subsequent edits
Related skills
FAQ
What does memory-optimize 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%
When should I use memory-optimize?
During build integrations work for ai & agent building.
Is memory-optimize safe to install?
Review the Security Audits panel on this listing before production use.