From ctx
Reconciles Claude Code's MEMORY.md with ctx knowledge graph: detects cross-system/intra-ctx duplicates, stale working nodes, conflicts, bloat; resolves with user approval.
How this skill is triggered — by the user, by Claude, or both
Slash command
/ctx:cleanupThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Reconcile Claude Code's built-in MEMORY.md system with the ctx knowledge graph. Detect duplicates, stale nodes, conflicts, and bloat across both systems, then resolve them with user approval.
Reconcile Claude Code's built-in MEMORY.md system with the ctx knowledge graph. Detect duplicates, stale nodes, conflicts, and bloat across both systems, then resolve them with user approval.
$1 — Project name (optional, auto-detected from git)--global — Include all projects, not just the current oneThis is a phased command — run each phase in order, presenting findings to the user between phases.
Gather the complete state of both memory systems.
Actions:
basename $(git rev-parse --show-toplevel))sh "${CLAUDE_SKILL_DIR}/scripts/analyze-sync.sh" "$PROJECT"
~/.claude/projects/ (search for directory matching project name)ctx list --tag "project:$PROJECT" --format json
project:global):
ctx list --tag "project:global" --format json
If --global was passed, also inventory all other projects:
~/.claude/projects/*/memory/project:* tags in ctx via ctx tagsSave the inventory mentally — it feeds all subsequent phases.
Analyze the inventory for seven categories of issues. For each issue found, record: the issue type, affected items (node IDs / MEMORY.md line numbers), severity (high/medium/low), and recommended action.
Issue categories (consult references/sync-strategies.md for detailed detection patterns):
Cross-system duplicates — Same knowledge in both MEMORY.md and ctx
Intra-ctx duplicates — Two+ ctx nodes with near-identical content
Stale working nodes — tier:working nodes from completed tasks
Pinned tier bloat — Too many pinned nodes consuming context budget
Conflicts — Contradictory information across systems
Orphaned content — Knowledge for projects that no longer exist or are inactive
Missing structure — Nodes without tier tags, without project tags, or with empty content
Present findings to the user in a structured report. Group by severity (high first).
Report format:
## Memory Sync Report — [project]
### Token Budget
- MEMORY.md: ~X tokens (Y lines)
- ctx pinned: X tokens (Y nodes)
- ctx working: X tokens (Y nodes)
- Total auto-loaded: X tokens
### Issues Found
#### HIGH: Stale Working Nodes (N found)
| Node ID | Content Preview | Created | Recommendation |
|---------|----------------|---------|----------------|
| 01KK... | Sprint complete... | Mar 15 | -> tier:reference |
#### MEDIUM: Cross-System Duplicates (N found)
| MEMORY.md Line | ctx Node | Content | Recommendation |
|---------------|----------|---------|----------------|
| L5-7 | 01KH... | Release rules | Remove from MEMORY.md |
... (all categories)
### Summary
- X issues found (Y high, Z medium, W low)
- Estimated token savings: ~N tokens
MANDATORY: After presenting the report, MUST use the AskUserQuestion tool (not plain text) to ask how to proceed. Use this exact configuration:
Do NOT proceed to Phase 4 without this user response. Do NOT present these options as text — use the AskUserQuestion tool.
Execute approved fixes. For each fix, use the appropriate mechanism:
ctx node actions:
ctx tag <id> tier:reference && ctx untag <id> tier:workingctx tag <id> tier:off-context && ctx untag <id> tier:workingctx delete <id> (only for true duplicates or empty nodes)<ctx:supersede old="ID1" new="ID2"/> when one node replaces anotherctx tag <id> project:name or ctx tag <id> tier:referenceMEMORY.md actions:
Cross-system actions:
After each batch of fixes, show a summary of what changed.
After remediation:
ctx status to show the new stateAfter cleanup, advise the user on keeping systems in sync:
The using-ctx skill already handles this — it instructs the agent to cross-check before writing to either system. If the user feels drift is happening, the skill instructions may need strengthening.
Periodic cleanup — Run /ctx:cleanup quarterly or when starting major new work.
Hook option — For persistent drift, a PostToolUse hook on MEMORY.md writes can enforce cross-checking. See references/sync-strategies.md for the hook design. Only recommend this if the user reports ongoing issues after multiple cleanups.
references/sync-strategies.md — Detailed sync strategies, division of labor rules, issue detection patterns, token budget guidelines, and hook-based sync designscripts/analyze-sync.sh — Dumps both memory systems for comparison (run with project name argument)npx claudepluginhub zate/cc-plugins --plugin ctxReviews, consolidates, and prunes Claude Code project memory files. Supports dry-run and atomic apply modes for safe batch maintenance.
Organizes, extracts, prunes, and verifies Claude Code persistent memory files to keep MEMORY.md under the 200-line truncation limit and topic files up to date with project state.
Optimizes Claude Code memory files in 4 interactive steps: removes duplicates by cross-referencing CLAUDE.md/rules, migrates entries to persistent configs, compresses, and validates with cleanup. Run in main conversation to declutter memory.