memory-defrag · basicmachines-co — Claude Code skill: defragment agent memory files
Splits bloated memory files, merges duplicates, drops stale entries. Run it on a schedule or when things get messy.
npx skills add basicmachines-co/basic-memory-skills --skill memory-defrag -a claude-codeWhat memory-defrag does
The skill walks your agent's memory files and tidies them. It starts with an inventory: MEMORY.md, the memory/ directory with daily notes and tasks, and memory/tasks/ underneath. For each file it notes line count, last modified date, and topic coverage.
Then it looks for the usual rot: a file past 300 lines covering half a dozen topics, the same fact sitting in three places, references to finished work, contradictions between files, nested directories like memory/memory/memory/. Each problem maps to an action — split, merge, prune, restructure. Before touching anything the skill writes a short plan, then applies changes one at a time and checks that nothing was lost.
Raw daily notes memory/YYYY-MM-DD.md stay untouched, because they are the audit trail. Tasks marked done older than 14 days can go. When relevance is unclear, the skill advises keeping the entry with a (review needed) tag instead of deleting it. A reasonable target is 15–25 topical files: fewer and files bloat, more and everything fragments. The catch: it works against your own memory layout, so on an unusual directory structure you will be editing the plan by hand.
What it helps with
- split
MEMORY.mdinto focused topical files - merge the same fact repeated across notes
- prune references to finished work and old dates
- resolve contradictions between memory files
- delete nested
memory/memory/directories
Example prompts for the agent
- defrag my agent memory and show me the plan first
MEMORY.mdis over 500 lines — split it by topic- clean
memory/tasks/ofdonetasks older than 14 days
How to install memory-defrag
1Skills CLI (Vercel)
npx skills add basicmachines-co/basic-memory-skills --skill memory-defrag -a claude-code2Manually: put the files in place
~/.claude/skills/memory-defrag/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/memory-defrag/
1Skills CLI (Vercel)
npx skills add basicmachines-co/basic-memory-skills --skill memory-defrag -a codex2Manually: put the files in place
.agents/skills/memory-defrag/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add basicmachines-co/basic-memory-skills --skill memory-defrag -a cursor2Manually: put the files in place
.cursor/skills/memory-defrag/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install basicmachines-co/basic-memory-skills memory-defrag2Manually: put the files in place
.github/skills/memory-defrag/SKILL.md1Skills CLI (Vercel)
npx skills add basicmachines-co/basic-memory-skills --skill memory-defrag -a gemini-cli2Platform CLI
gemini skills install https://github.com/basicmachines-co/basic-memory-skills --path memory-defragManually: put the files in place
.devin/skills/memory-defrag/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add basicmachines-co/basic-memory-skills --skill memory-defrag -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about memory-defrag
How do I install memory-defrag in Claude?
Run npx skills add basicmachines-co/basic-memory-skills --skill memory-defrag -a claude-code. The skill lands at ~/.claude/skills/memory-defrag/SKILL.md.
What does memory-defrag do?
It audits your memory files, flags bloated files, duplicates, stale entries and contradictions, then splits, merges and prunes them according to a plan it writes first.
How often should I run a memory defrag?
The skill recommends weekly or biweekly via cron. Another trigger is MEMORY.md passing 500 lines, or daily notes piling up without consolidation.
Similar skills
All skills for Agent setup: memory, context, orchestration →memory-defrag by other authors comes first.