/ctx:cleanup [project-name] [--global]from ctx
Reconciles Claude Code's MEMORY.md with the ctx knowledge graph by detecting duplicates, stale nodes, conflicts, and bloat, then resolving them with user approval.
Ships in ctx. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
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)What SKILL.md sets; muted values are Claude Code's defaults
Removing stale, redundant, or incorrect nodes from persistent memory
Three short reads, in order
5 skills in this plugin
npx claudepluginhub zate/cc-plugins --plugin ctxOther plugins' skills for the same job