Skip to main content
skill CX Codex

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.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add basicmachines-co/basic-memory-skills --skill memory-defrag -a claude-code
Open on GitHub

What 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.md into 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.md is over 500 lines — split it by topic
  • clean memory/tasks/ of done tasks 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-code

2Manually: put the files in place

~/.claude/skills/memory-defrag/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/memory-defrag/

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.

From the same set4

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor