Memory Hygiene — Pruning, Deduplication, and Keeping Your Agent's Memory Clean
Your agent has been running for three weeks. It’s stored hundreds of memories. And now recall is returning five slightly different versions of “user prefers dark mode” instead of the one thing that matters. Sound familiar?
Memory accumulation is the dirty secret of persistent agent memory. Every memoclaw store call adds another entry, and without periodic cleanup, your agent drowns in its own noise. Low-importance memories crowd out the good stuff. Duplicate entries waste your recall budget. Stale facts stick around long after they stopped being true.
This guide covers practical memory hygiene, from quick audits to automated cleanup pipelines. Everything here uses the MemoClaw CLI.
Know what you’re working with
Before you start deleting things, get a picture of what’s actually in there.
memoclaw stats
This gives you total memory count, namespace breakdown, and usage info. If you’re running multiple agents or projects on the same wallet, filter by namespace:
memoclaw stats --namespace my-project
For a more detailed look, list your recent memories sorted by creation date:
memoclaw list --sort-by created --reverse --limit 50
Pay attention to the importance scores. If most of your memories sit at 0.5 (the default), that’s a red flag. It means your agent isn’t differentiating between “user’s name is Ana” and “user mentioned the weather once.” We’ll come back to this.
The duplication problem
Duplication happens because agents store what they learn in the moment without checking what they already know. Your agent corrects a user preference, stores the correction, then next session stores the same correction again. Three sessions later, you’ve got four copies.
The fix is simple: recall before you store. In your agent’s AGENTS.md or skill config, this should be standard practice:
# Before storing, check if you already know this
memoclaw recall "user prefers dark mode" --limit 3
# If a matching memory exists, update it instead
memoclaw update <existing-id> "user prefers dark mode in all apps"
But let’s be honest, your agent probably already created duplicates. Here’s how to clean them up.
Consolidate (the easy way)
MemoClaw has a built-in consolidation command that finds similar memories and merges them:
memoclaw consolidate --dry-run
Always run with --dry-run first. This shows you what would be merged without actually doing it. The output lists memory pairs that exceed the similarity threshold, along with the proposed merged content.
If the preview looks good:
memoclaw consolidate
The default similarity threshold works for most cases, but if you’re getting false positives (merging memories that shouldn’t be merged), bump it up:
memoclaw consolidate --min-similarity 0.9
Consolidation costs $0.01 per call since it uses GPT-4o-mini to intelligently merge content. Worth it for a clean memory store, but not something you want running every five minutes.
Manual dedup for specific namespaces
If you want more control, combine list with bulk-delete:
# Find memories about a specific topic
memoclaw search "dark mode preference" --json | jq -r '.memories[].id'
# Review them, then delete the duplicates
memoclaw bulk-delete <id1> <id2> <id3>
You can also pipe directly:
memoclaw list --namespace old-project --json | jq -r '.memories[].id' | memoclaw bulk-delete
That last command nukes everything in a namespace. Use it when you’re done with a project and want to reclaim space.
Importance scores matter more than you think
Importance scoring is your best tool for memory hygiene, and most agents underuse it. Here’s a rough framework:
- 0.9-1.0: User corrections, explicit preferences, identity info. Things that should never decay or get lost.
- 0.7-0.8: Decisions, project context, learned patterns. Important but might change.
- 0.4-0.6: Session summaries, general observations. Useful context, not critical.
- 0.1-0.3: Transient stuff. Today’s weather, a one-off task detail.
When your agent stores memories with proper importance scores, recall naturally surfaces the right stuff first. A recall query returns results ranked by relevance and importance, so a 0.9 memory about the user’s name beats a 0.5 memory about what they had for lunch.
The problem is getting your agent to actually assign meaningful scores. In your AGENTS.md, be explicit:
When storing memories:
- User corrections → importance 0.95
- Stated preferences → importance 0.8
- Session context → importance 0.5
- Temporary observations → importance 0.3
Find stale and decaying memories
Memories go stale. What was true two months ago might not be true now. MemoClaw tracks this:
memoclaw suggested --category stale
memoclaw suggested --category decaying
The suggested command surfaces memories that haven’t been accessed or updated in a while. Review these periodically. Some you’ll want to update, some you’ll want to delete, and some are fine as-is.
For a time-based audit, list old memories directly:
memoclaw list --until 30d --sort-by importance --limit 30
This shows memories older than 30 days, sorted by importance. Low-importance old memories are prime deletion candidates.
Building a cleanup routine
Here’s what a weekly memory hygiene routine looks like in practice:
# 1. Check the state of things
memoclaw stats
# 2. Find and review suggested cleanups
memoclaw suggested --category stale --limit 20
# 3. Run consolidation (preview first)
memoclaw consolidate --dry-run
memoclaw consolidate
# 4. Prune low-importance old memories
memoclaw list --until 30d --sort-by importance --limit 20
# Review the list, then delete what's noise
memoclaw bulk-delete <ids>
If you’re running this on an OpenClaw agent, you can automate it. Add a cron job or a heartbeat task that runs consolidation weekly. Just make sure to use --dry-run logging so you can audit what happened.
The nuclear option
Sometimes you need to start over. Maybe you migrated from .md files and the import was messy. Maybe your agent went through a phase of storing everything it saw. The simplest way to clear a namespace:
memoclaw list --namespace experiments --json | jq -r '.memories[].id' | memoclaw bulk-delete
This deletes everything in a namespace. Use it when the cost of cleaning up exceeds the cost of starting fresh.
What clean memory actually looks like
After a good cleanup session, your memory store should have:
- No duplicate entries for the same fact
- Importance scores that reflect actual priority (not everything at 0.5)
- Old, irrelevant memories pruned
- Namespaces used to separate distinct projects or contexts
The payoff is better recall. When your agent asks “what does the user prefer?”, it gets one clear answer instead of five conflicting ones. Recall queries cost $0.005 each, so fewer, higher-quality memories also means less wasted spend on results your agent has to filter through.
Memory hygiene isn’t glamorous work. But the difference between an agent that remembers well and one that remembers everything is the difference between useful and annoying. Take 10 minutes a week to keep things clean. Your future agent sessions will thank you.