Agent skill

Memory Defrag

by basicmachines-co in basicmachines-co/basic-memory

Defragment and reorganize agent memory files: split bloated files, merge duplicates, remove stale information, and restructure the memory hierarchy.

AGPL-3.0Auto-check passedAgent Workflows

Install Memory Defrag

skills CLI
$ npx skills add basicmachines-co/basic-memory --skill memory-defrag -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install basicmachines-co/basic-memory memory-defrag --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/basicmachines-co/basic-memory.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/memory-defrag .claude/skills/memory-defrag && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
memory-defrag
GitHub stars
4.1k
Used in
1 other repo
Token cost
~896 tokens
SKILL.md length
339 words
Files
1
Skills in repo
49
Repo updated
First seen
Licence
AGPL-3.0

At a glance

Defragment and reorganize agent memory files: split bloated files, merge duplicates, remove stale information, and restructure the memory hierarchy.

  • Works in 5 steps: Audit Current State → Identify Problems → Plan Changes → …
  • Memory files have grown unwieldy
  • SKILL.md covers When to Run, Process and Guidelines
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Memory Defrag is an agent skill from basicmachines-co/basic-memory. Defragment and reorganize agent memory files: split bloated files, merge duplicates, remove stale information, and restructure the memory hierarchy. Use when memory files have grown unwieldy, contain redundancies, or need reorganization. Run periodically (weekly) or on demand.

Its SKILL.md is about 900 tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Agent Workflows, covering Agent memory. The repository describes itself as: AI conversations that actually remember. Never re-explain your project to your AI again. Join our Discord: https://discord.gg/tyvKNccgqN. The licence is AGPL-3.0.

When your agent uses it

  • Memory files have grown unwieldy
  • Contain redundancies
  • Need reorganization

Example prompts

  • “/memory-defrag”

Workflow steps

5 steps, taken from the step headings in SKILL.md.

  1. Audit Current State
  2. Identify Problems
  3. Plan Changes
  4. Execute
  5. Verify & Log

What it can do on your machine

Read from SKILL.md and the folder at commit 6982cfc. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are markdown).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Memory Defrag loads about 896 tokens when it runs. Until then it costs about 73 tokens; SKILL.md has 339 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~73
When it runs · the whole SKILL.md, loaded when a task matches
~896

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from basicmachines-co/basic-memory at commit 6982cfc, republished under its AGPL-3.0 licence (© basicmachines-co). 339 words, ~896 tokens.

Download SKILL.mdSave it as .claude/skills/memory-defrag/SKILL.md (or your agent's skills folder).
name
memory-defrag
description
Defragment and reorganize agent memory files: split bloated files, merge duplicates, remove stale information, and restructure the memory hierarchy. Use when memory files have grown unwieldy, contain redundancies, or need reorganization. Run periodically (weekly) or on demand.

Memory Defrag

Reorganize memory files for clarity, efficiency, and relevance. Like filesystem defragmentation but for knowledge.

When to Run

  • Periodic: Weekly or biweekly via cron (recommended)
  • On demand: User asks to clean up, reorganize, or defrag memory
  • Threshold: When MEMORY.md exceeds ~500 lines or daily notes accumulate without consolidation

Process

1. Audit Current State

Inventory all memory files:

MEMORY.md           — long-term memory
memory/             — daily notes, tasks, topical files
memory/tasks/       — active and completed tasks

For each file, note: line count, last modified, topic coverage, staleness.

2. Identify Problems

Look for these common issues:

ProblemSignalFix
Bloated file>300 lines, covers many topicsSplit into focused files
Duplicate infoSame fact in multiple placesConsolidate to one location
Stale entriesReferences to completed work, old dates, resolved issuesRemove or archive
Orphan filesFiles in memory/ never referenced or updatedReview, merge, or remove
InconsistenciesContradictory information across filesResolve to ground truth
Poor organizationRelated info scattered across filesRestructure by topic
3. Plan Changes

Before making edits, write a brief plan:

markdown
## Defrag Plan
- [ ] Split MEMORY.md "Key People" section → memory/people.md
- [ ] Remove completed tasks past the retention window from memory/tasks/
- [ ] Merge memory/bm-marketing-ideas.md into memory/competitive/
- [ ] Update stale project status entries in MEMORY.md
4. Execute

Apply changes one at a time:

  • Split: Extract sections from large files into focused topical files
  • Merge: Combine related small files into coherent documents
  • Prune: Remove information that is no longer relevant or accurate
  • Restructure: Move files to appropriate directories, rename for clarity
  • Update: Fix outdated facts, dates, statuses
5. Verify & Log

After changes:

  • Verify no information was lost (compare before/after)
  • Update any cross-references between files
  • Log what was done in today's daily note:
markdown
## Memory Defrag (HH:MM)
- Files reviewed: N
- Split: [list]
- Merged: [list]
- Pruned: [list]
- Net result: X files, Y total lines (was Z lines)

Guidelines

  • Preserve raw daily notes. Don't delete or modify memory/YYYY-MM-DD.md files — they're the audit trail.
  • Target 15-25 focused files. Too few means bloated files; too many means fragmentation. Aim for the sweet spot.
  • File names should be scannable. Use descriptive names: people.md, project-status.md, competitive-landscape.md — not notes-2.md.
  • Don't over-organize. One level of directories is usually enough. memory/tasks/ and memory/competitive/ are fine; memory/work/projects/active/basic-memory/notes/ is not.
  • Completed tasks: Tasks with status: done older than 14 days can be removed. Their insights should already be in MEMORY.md via reflection.
  • Ask before destructive changes. If uncertain whether information is still relevant, keep it with a (review needed) tag rather than deleting.

© basicmachines-co, AGPL-3.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/memory-defrag of basicmachines-co/basic-memory.

Open the folder on GitHubat commit 6982cfc

Used in 1 other repository

We found 1 copy of this SKILL.md (exact, near-identical or edited) in other folders, from 1 other GitHub owner. This page covers the copy in basicmachines-co/basic-memory, which our catalogue first saw on October 7, 2026.

Compare with similar skills

Memory Defrag next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Memory Defrag compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Memory Defrag this skillbasicmachines-co/basic-memory4.1k1 repos~896Automated safety check: PassAGPL-3.0
Project Timeline Reportthedotmack/claude-mem97k1 repos~3.1kAutomated safety check: PassApache-2.0
Neat-Freak Knowledge CloseoutKKKKhazix/khazix-skills21k—~1.9kAutomated safety check: PassMIT
Beads Task Memorygastownhall/beads28k—~1.2kAutomated safety check: PassMIT
MemPalace Memory SearchMemPalace/mempalace59k—~1.4kAutomated safety check: PassMIT
Reflect on Session Learningscursor/plugins10k5 repos~1.2kAutomated safety check: PassNone

Similar skills

  • Project Timeline Report

    thedotmack/claude-mem

    Writes a narrative Journey Into report on a project's whole development history, built from the timeline that claude-mem has recorded.

    97k GitHub starsUsed in 1 repo~3.1k tokens
    Agent WorkflowsAuto-check passed
  • Neat-Freak Knowledge Closeout

    KKKKhazix/khazix-skills

    Brings project docs, agent rule files, authorized memory and leftover workspace files back in line with what the code and runtime actually do at the end of a work session.

    21k GitHub stars~1.9k tokensUpdated 6 days ago
    Agent WorkflowsAuto-check passed
  • Beads Task Memory

    gastownhall/beads

    Tracks multi-session work with dependencies in the bd issue tracker so the agent can find ready tasks and recover its context after conversation compaction.

    28k GitHub stars~1.2k tokensUpdated today
    Agent WorkflowsAuto-check passed
  • MemPalace Memory Search

    MemPalace/mempalace

    Mines project files and conversation exports into a local, searchable memory palace and recalls past work by semantic search through the mempalace CLI.

    59k GitHub stars~1.4k tokensUpdated today
    Agent WorkflowsAuto-check passed
  • Official

    Starts three parallel reviewer subagents over the current conversation transcript, then turns their findings into concrete edits to existing skills.

    10k GitHub starsUsed in 5 repos~1.2k tokens
    Agent WorkflowsAuto-check passed
  • Compound Learning Writer

    EveryInc/compound-engineering-plugin

    Records one solved and verified problem as a durable learning in the repository, but only when the reasoning is not already clear from the final code, tests or docs.

    25k GitHub stars~2k tokensUpdated today
    Agent WorkflowsAuto-check passed

More from basicmachines-co/basic-memory

All 49 skills in this repo
  • cmux Settings Editor

    basicmachines-co/basic-memory

    Views, sets, unsets and validates cmux settings in ~/.config/cmux/cmux.json with a helper script that checks keys against the schema.

    4.1k GitHub starsUsed in 1 repo~1.3k tokens
    Auto-check passed
  • cmux Window and Pane Control

    basicmachines-co/basic-memory

    End-user control of cmux topology and routing (windows, workspaces, panes/surfaces, focus, moves, reorder, identify, trigger flash). Use when automation needs…

    4.1k GitHub starsUsed in 2 repos~842 tokens
    Auto-check passed
  • Cmux Markdown Viewer Panel

    basicmachines-co/basic-memory

    Opens markdown files in a formatted cmux panel beside the terminal that re-renders on every change, handy for plans and task lists.

    4.1k GitHub starsUsed in 2 repos~527 tokens
    Auto-check passed
  • cmux Workspace Scoping

    basicmachines-co/basic-memory

    Keeps agent actions scoped to the cmux workspace and terminal that invoked it, and lays out pane and surface commands that avoid disrupting the user's own focus.

    4.1k GitHub starsUsed in 2 repos~1.7k tokens
    Auto-check passed
  • Basic Memory Repo Images

    basicmachines-co/basic-memory

    Produces PR, changelog and two-week retro images for the Basic Memory repository from evidence in PR bodies, saved to fixed paths under docs/assets/infographics.

    4.1k GitHub stars~2.7k tokensUpdated today
    Auto-check passed
  • Logfire Instrumentation

    basicmachines-co/basic-memory

    Adds Pydantic Logfire tracing, logging and metrics to Python, JavaScript or TypeScript and Rust projects, with the correct setup order and library extras.

    4.1k GitHub stars~2.3k tokensUpdated today
    Auto-check passed

Categories

Questions about Memory Defrag

What does Memory Defrag do?

Defragment and reorganize agent memory files: split bloated files, merge duplicates, remove stale information, and restructure the memory hierarchy. Memory Defrag is an agent skill from basicmachines-co/basic-memory. Defragment and reorganize agent memory files: split bloated files, merge duplicates, remove stale information, and restructure the memory hierarchy.

When should I use Memory Defrag?

Memory Defrag fits situations like: memory files have grown unwieldy; contain redundancies; need reorganization.

How do I install Memory Defrag in Claude Code?

Run `npx skills add basicmachines-co/basic-memory --skill memory-defrag -a claude-code`. Or copy the skill folder (skills/memory-defrag in basicmachines-co/basic-memory) into .claude/skills/memory-defrag in your project. Claude Code loads it when a task matches its description.

How do I install Memory Defrag in Codex?

Run `npx skills add basicmachines-co/basic-memory --skill memory-defrag -a codex`. Or copy the skill folder (skills/memory-defrag in basicmachines-co/basic-memory) into .agents/skills/memory-defrag in your project. Codex loads it when a task matches its description.

Can I use Memory Defrag in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add basicmachines-co/basic-memory --skill memory-defrag -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/memory-defrag, .gemini/skills/memory-defrag, .github/skills/memory-defrag and .opencode/skills/memory-defrag in your project.

What does Memory Defrag need to run?

SKILL.md names no scripts, command-line tools or credentials: Memory Defrag is instructions for the agent only.

Does Memory Defrag access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Memory Defrag safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Memory Defrag use?

Memory Defrag is published under the AGPL-3.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Memory Defrag use?

About 896 tokens (SKILL.md is roughly 3.6k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Memory Defrag?

Skills that share tags, products or a category with Memory Defrag: Project Timeline Report (thedotmack/claude-mem, 97k stars), Neat-Freak Knowledge Closeout (KKKKhazix/khazix-skills, 21k stars), Beads Task Memory (gastownhall/beads, 28k stars) and MemPalace Memory Search (MemPalace/mempalace, 59k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Memory Defrag?

basicmachines-co (a GitHub organization) maintains it in basicmachines-co/basic-memory, which has 4,107 GitHub stars. The repository holds 49 skills in this directory. The repository was last updated on October 7, 2026.

Source: basicmachines-co/basic-memory on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.