Automatically monitors MEMORY.md size and warns Claude to compact it when it exceeds a configurable line threshold.
Claude Code's auto-memory system uses MEMORY.md as an index loaded into every conversation — but only the first 200 lines are read. When detailed project notes are written inline instead of in dedicated topic files, the index silently overflows and memories become invisible.
/plugin add sharooncs/claude-memory-compactor
Copy the skill folder to your Claude Code skills directory:
cp -r . ~/.claude/skills/memory-compactorThen run the installer:
bash ~/.claude/skills/memory-compactor/scripts/install.shWith a custom threshold (default is 30 lines):
bash ~/.claude/skills/memory-compactor/scripts/install.sh ~/.claude/settings.json 50- A PostToolUse hook fires after every
WriteorEditoperation - The hook extracts the file path from the tool payload
- If the path is inside a
memory/directory, it locatesMEMORY.mdand counts lines - When the line count exceeds the threshold, it injects a warning into Claude's context
- Claude then compacts MEMORY.md by moving inline content to dedicated topic files
| Parameter | Default | Description |
|---|---|---|
settings_file |
~/.claude/settings.json |
Path to your Claude Code settings |
threshold |
30 |
Max lines in MEMORY.md before warning triggers |
Pass both as positional arguments to install.sh:
bash scripts/install.sh <settings_file> <threshold>Remove the Write|Edit entry containing MEMORY.md from the PostToolUse array in your settings.json, or use /hooks in Claude Code to review and disable it.