memory-hygiene

Audit and optimize Claude Code's persistent memory system — axioms, phase templates, MEMORY.md, lessons, memory files, and ADRs — using a research-backed tiered architecture with promotion/demotion lifecycle and agency-aware staleness detection. v3.4 fixes the cross-plugin lookup of session-handoff's label_audit.py, which silently found nothing on a plugin install. v3.3 added a label-table integrity audit and a peer workflow for auditing a project's docs/ directory against a canonical 7-bucket taxonomy.
The Problem
Claude Code's memory system has two failure modes that compound over time:
- Truncation: MEMORY.md exceeding ~200 lines is silently truncated — context lost without warning.
- Lost in the Middle: Even within the context window, LLMs show >30% accuracy degradation for information in the middle of long contexts (Liu et al. 2023). A critical lesson at line 617 of a 1400-line file is effectively invisible.
This means bulk-loading large files into context is counterproductive — it wastes tokens AND buries the important rules. The solution is a tiered architecture:
T0: Axioms (≤12 items, always loaded) — Universal + Role behavioral overrides
T0: CLAUDE.md (~70 lines, always loaded) — workflow rules, retrieval strategy
T1: MEMORY.md (~40-80 lines, always loaded) — index pointers
T1.5: .claude/rules/ (auto on file match) — phase-specific rules with paths: globs
T2: Topic files (~50 lines each, on demand) — per-topic context
T3: Archives (unlimited, grep only) — lessons, handoffs, sessions
v3.0 adds phase templates (~/.claude/templates/phase_*.md) — reusable rule sets that auto-activate when you touch matching files. Rules that are only relevant during specific project phases (data sourcing, deliverables, code review) don't waste attention in every session — they load precisely when needed.
Without regular maintenance, the system also accumulates: duplicate lesson numbers, orphaned memory files, stale references to renamed code, ADR numbering conflicts, and lessons that should be promoted to axioms but remain buried in archives.
Quick Start
You: my lessons file is 1400 lines and critical rules keep getting ignored
Claude: [Reads axioms.md, CLAUDE.md, MEMORY.md, lessons, topic files, ADRs]
[Checks tiered loading, axioms health, staleness, duplicates]
[Produces structured audit report grouped by severity]
## Memory Hygiene Audit
### Critical
- axioms.md missing — no behavioral overrides loaded at session start
- CLAUDE.md says "read lessons.md" (bulk-load anti-pattern)
### Axioms
- 6 lessons in T3 qualify for axioms promotion (override default behavior)
- CLAUDE.md retrieval strategy: needs update (grep, not bulk-read)
### Tiering
- 3 items at wrong tier (lesson #68 at line 617 → promote to T0)
- lessons.md: 1,406 lines (archive only, never bulk-read)
### Staleness
- 2 memory files reference functions that no longer exist
### Duplicates
- Global lessons: 5 number collisions
### Recommendations
- Create axioms.md with 15-20 behavioral overrides from lessons.md
- Update CLAUDE.md checklist: load axioms.md, grep lessons.md
- Merge 5 lesson pairs, suffix 5 number collisions
Want me to proceed with all fixes?
You: yes, go ahead
Claude: [Creates axioms.md, updates CLAUDE.md, fixes duplicates, verifies]
Done. axioms.md: 52 lines (18 behavioral overrides). CLAUDE.md: updated
to grep-not-read strategy. No duplicate lesson numbers remain.
Installation
Claude Code:
# Plugin install (recommended)
/plugin marketplace add wan-huiyan/memory-hygiene
/plugin install memory-hygiene@wan-huiyan-memory-hygiene
# Git clone (always works)
git clone https://github.com/wan-huiyan/memory-hygiene.git ~/.claude/skills/memory-hygiene
Cursor (2.4+):
# Per-project rule (most reliable)
mkdir -p .cursor/rules
# Copy SKILL.md content into .cursor/rules/memory-hygiene.mdc with alwaysApply: true
# Manual global install
git clone https://github.com/wan-huiyan/memory-hygiene.git ~/.cursor/skills/memory-hygiene