Critical fixes:
- C1: Pin/dream update_memory now reads content first via get_memory
before updating, preventing metadata-only calls that wipe content
- C2: SessionStart memory count uses GET /v3/memories/?page_size=1 for
real count from pagination envelope instead of search limit=100
- C3: on_task_completed.sh uses ${MEM0_PROJECT_ID:-unknown} to avoid
crash when identity resolution fails under set -u
Important fixes:
- I1: session_stats.py tracks recent_ids (memory IDs + timestamps) for
/mem0:forget undo support. Capped at 50 entries.
- I2: /mem0:health --deep mode adds memory quality analysis: duplicate
detection, stale entry scan, contradiction flags, orphan tagging
- I3: /mem0:stats ASCII histogram for category distribution with bar
chart, sorted by count descending
- I4: mem0-mcp skill documents access counter pattern: get_memory then
update_memory to track which memories are actually used
- I5: on_pre_commit.py reads COMMIT_EDITMSG first (current commit),
falls back to HEAD only if EDITMSG unavailable
Tests: 91 -> 94 (3 new for recent_ids tracking)
4.3 KiB
name, description
| name | description |
|---|---|
| mem0-health | Diagnostic health check for the mem0 plugin. Verifies API key, MCP server connectivity, identity resolution, and memory read/write capability. TRIGGER: user runs /mem0:health, or asks "is mem0 working", "mem0 health", "check mem0 connection", "debug mem0". |
Mem0 Health Check
Run a diagnostic check on the mem0 plugin. Useful for troubleshooting.
Execution
Run ALL checks, then display a single summary. Do not stop on the first failure.
Check 1: API key
echo "${MEM0_API_KEY:-${CLAUDE_PLUGIN_OPTION_MEM0_API_KEY:-NOT_SET}}"
- If
NOT_SET: FAIL — "No API key configured" - If set: PASS — show first 6 chars +
...(never print the full key)
Check 2: Identity resolution
Read the active identity from the SessionStart banner or resolve manually:
user_id: fromMEM0_RESOLVED_USER_IDor$USERproject_id: fromMEM0_PROJECT_IDor current directory namebranch: fromMEM0_BRANCHorgit rev-parse --abbrev-ref HEAD
PASS if all three are non-empty. WARN if any falls back to defaults.
Check 3: MCP server connectivity
Call search_memories with:
-
query="health check",user_id=<id>,limit=1 -
filters={"AND": [{"user_id": "<id>"}, {"app_id": "<project_id>"}]} -
If returns successfully (even empty): PASS
-
If errors: FAIL — show the error message
Check 4: Memory write capability
Call add_memory with:
messages=[{"role": "user", "content": "Health check probe — safe to delete."}]user_id=<id>,app_id=<project_id>metadata={"type": "health_check", "probe": true}
If it returns a memory ID: PASS — then immediately call delete_memory with that ID to clean up.
If it errors: FAIL — show the error.
Check 5: Session stats tracker
SCRIPT_DIR="${CLAUDE_PLUGIN_ROOT:-${CODEX_PLUGIN_ROOT:-${CURSOR_PLUGIN_ROOT:-}}}/scripts"
python3 "$SCRIPT_DIR/session_stats.py" peek 2>/dev/null && echo "OK" || echo "FAIL"
Display
## mem0 Health Check
| Check | Status | Detail |
|--------------------|--------|-------------------------------|
| API Key | PASS | m0-dVe... |
| Identity | PASS | user=kartik, project=mem0 |
| MCP Connectivity | PASS | 142ms round-trip |
| Memory Write/Read | PASS | write + delete OK |
| Session Tracker | PASS | stats file active |
All checks passed. mem0 is healthy.
If any check fails, add a ## Troubleshooting section with specific fix steps for each failure.
Extended mode: Memory Quality Analysis
When invoked with --deep (e.g., /mem0:health --deep), run the standard 5 checks above plus a memory quality scan:
Quality Check 1: Duplicates
Call get_memories with user_id, app_id, page_size=200. Compare all pairs within the same metadata.type group for high textual overlap (shared nouns/keywords > 60%). Report:
Potential duplicates: <N> pairs
[mem0:<id1>] ≈ [mem0:<id2>] — both about "<shared topic>"
Quality Check 2: Stale memories
Flag memories where:
metadata.typeissession_stateorcompact_summaryAND older than 90 daysmetadata.confidence< 0.3 AND older than 30 days
Stale candidates: <N>
[mem0:<id>] — session_state, 142d old
Quality Check 3: Contradictions
Within each metadata.type group, flag pairs that assert opposing facts about the same topic. Use semantic judgment — look for negation patterns, conflicting tool/framework choices, or reversed decisions.
Possible contradictions: <N>
[mem0:<idA>] vs [mem0:<idB>] — conflicting on "<topic>"
Quality Check 4: Orphan memories
Memories with no metadata.type set, or with metadata.type not in the 17 known coding categories. These were likely written without proper tagging.
Untagged/orphan memories: <N>
Quality summary
## Memory Quality
| Metric | Count | Action |
|----------------|-------|---------------------------------|
| Duplicates | <N> | Run /mem0:dream to merge |
| Stale | <N> | Run /mem0:dream to prune |
| Contradictions | <N> | Run /mem0:dream to resolve |
| Orphans | <N> | Consider retagging via MCP |
If all counts are 0: Memory quality: clean. No duplicates, stale entries, or contradictions found.