Memory Hygiene Loop
July 20, 2026 · View on GitHub
Goal: Prevent memory rot — stale facts, duplicate episodics, unbounded scratch — on a schedule.
When to use
- Any project past week one of memory engineering
- Audit warns on size, staleness, or missing owners
- After incidents involving wrong remembered facts
Tiers
| Tier | Hygiene action |
|---|---|
| Scratch | Delete/archive past TTL |
| Episodic | Compact, dedupe, promote invariants |
| Durable | Revalidate evidence; revoke or refresh as_of |
Scheduling
Recommended:
/loop 1dlight pass (scratch TTL only)/loop 1wfull hygiene (compact + durable review)- GitHub Action weekly cron for teams
Week one: report-only (propose deletions, do not apply).
Required skills
memory-hygiene— scan, propose, applymemory-verifier— approve durable revokes/promotesmemory-write— apply patches
How the loop runs
- Scheduler fires.
- Measure sizes vs
memory-budget.md. - Flag: expired scratch, episodic > N days raw, durable without owner, conflicts.
- Propose patch list in
MEMORY-STATE.md→ Hygiene proposals. - (Phase 2) Auto-apply safe ops: scratch TTL, episodic dedupe.
- (Phase 3) Human/verifier for durable changes.
- Append summary to
memory-run-log.md.
Post-run critique
- False positive deletions
- Facts that should have been durable
- Budget adjustments for next week
Verification
- Never delete durable without revoke record
- Keep backup branch or git commit before apply
memory-auditscore must not drop more than 10 points silently
Human handoff
- Durable revokes
- Anything tagged security / compliance
- Contested decisions
Tool-specific notes
Grok
/loop 1w Run memory-hygiene skill. Report-only first. Update memory-run-log.md.
Claude Code: $memory-hygiene with explicit “do not apply durable changes.”
With loop Daily Triage: add memory size signals to triage output.
Failure modes
| Failure | Mitigation |
|---|---|
| Aggressive deletion | Report-only week; soft archive |
| Hygiene never run | Audit staleness signal |
| Fight with humans over facts | Require owner ack |
| Costly full-file rewrites | Patch-style edits |
Cost profile
| Scenario | Tokens |
|---|---|
| Light daily | ~10k |
| Weekly full | ~40–80k |
Scaffold
node tools/memory-init/cli.js . --pattern memory-hygiene-loop --tool grok