Files
mem0/mem0-plugin/CHANGELOG.md
T
Mgeeeek db1b733c24 feat(plugin): holistic import of on-disk Claude state into mem0
When a user installs mem0-plugin, mem0 starts empty even though Claude
Code has been quietly accumulating their CLAUDE.md instructions,
auto-memory, and subagent learnings on disk for months. The existing
hooks capture live state going forward but cannot backfill what already
exists.

This commit adds a one-shot importer that walks every Claude state
surface and backfills it into mem0:

- `mem0-plugin/scripts/import_claude_state.py` (new, ~575 lines):
  discovers CLAUDE.md hierarchy (+ @imports), .claude/rules,
  ~/.claude/projects/*/memory, and ~/.claude/agent-memory; chunks each
  file at markdown headings (H2 default, H3 for oversize sections,
  small-sibling merge, code-fence safe); tags chunks with metadata
  matching the existing mem0-mcp skill vocabulary (convention /
  user_preference / task_learning / anti_pattern / decision); POSTs
  sequentially to /v1/memories/ with infer=True (server-side dedup).
  Marker file at ~/.mem0/imports/claude-state.json tracks content-hash
  per chunk for idempotent re-runs and crash-resume safety.

  Flags: --dry-run, --reset, --no-infer, --source <type>.

- `mem0-plugin/scripts/on_session_start.sh`: adds a one-time nudge
  block after the existing bootstrap output. Emits the holistic-import
  prompt only when ~/.mem0/imports/claude-state.json doesn't exist
  and the SOURCE isn't "compact". Propagates to Cursor and Codex for
  free (shared bash entry point).

- README, CHANGELOG, plugin.json bumped to 0.2.0.

Patterned exactly on the existing on_pre_compact.py: stdlib only
(urllib, hashlib, pathlib, argparse), reuses _identity.resolve_user_id,
same logging setup, same ~/.mem0/ storage convention. Zero new packages,
zero new deps.

Smoke-tested locally: --help renders, missing MEM0_API_KEY exits 1
with helpful message, hook emits nudge when marker absent and stays
silent when marker present.

Research and design context: https://www.notion.so/Claude-State-Holistic-Import-Research-Findings-366f22c70c9081d7abdcc6b94a80e8d9
2026-05-20 19:53:28 +05:30

3.5 KiB
Raw Blame History

Changelog

All notable changes to the Mem0 plugin will be documented in this file.

0.2.0

Added

  • Holistic import: a one-shot scripts/import_claude_state.py script backfills existing CLAUDE.md hierarchy (+ @imports), .claude/rules, ~/.claude/projects/*/memory, and ~/.claude/agent-memory into mem0. Heading-based markdown chunking (~50–500 tokens per chunk), metadata tagging using the mem0-mcp skill vocabulary, content-hash-tracked idempotent re-runs via a marker file at ~/.mem0/imports/claude-state.json. infer=True by default; --no-infer opt-out, --dry-run, --reset, and --source <type> flags supported.
  • SessionStart hook nudges the agent to run the importer on first session after install. The nudge stays silent once the marker file exists. Propagates to Cursor and Codex automatically (shared on_session_start.sh entry point).
  • Research and design context for the importer is documented in a Notion page (link in PR description).

0.1.3

Fixed

  • user_id resolution no longer derives from MEM0_API_KEY. v0.1.2 changed the resolver to fall back to "mem0-" + sha256(MEM0_API_KEY)[:12] ahead of $USER, which silently moved every existing user to a new bucket on update. Memories written under the previous $USER value became unreachable from the plugin. Resolution is now back to MEM0_USER_ID → $USER → "default".
  • Dropped the "regardless of which machine you're on" line from the SessionStart bootstrap, since cross-machine consolidation now requires setting MEM0_USER_ID explicitly.

Notes for users upgrading from 0.1.2

  • The ~/.mem0/identity.json cache file is no longer read or written. Safe to delete.
  • If you wrote memories during the v0.1.2 window, they live under mem0-<sha256(api_key)[:12]>. To recover: temporarily export MEM0_USER_ID=mem0-<hash>, search/export, then unset.
  • Want a single bucket across machines (the original goal of #5076)? Set MEM0_USER_ID explicitly in your shell profile. The plugin will not auto-derive one.

0.1.2

Added

  • Deterministic user_id resolver (_identity.sh / _identity.py) — reverted in 0.1.3, see above.
  • SessionStart-compact handler (capture_compact_summary.py) that stores the post-compaction summary as a memory with metadata.type=compact_summary.
  • Coding-taxonomy setup script (setup_coding_categories.py) — one-shot project.update(custom_categories=[...]) for architecture_decisions, anti_patterns, task_learnings, tooling_setup, bug_fixes, coding_conventions, user_preferences.
  • Opt-in hook logging via MEM0_DEBUG=1 → ~/.mem0/hooks.log.
  • mem0-mcp skill replacing the Claude-Code-specific mem0-codex skill.

Fixed

  • session_id now written to memory metadata (on_pre_compact.py).
  • SessionStart bootstrap exits silently when MEM0_API_KEY is unset.
  • block_memory_write.sh regex tightened to MEMORY.md / .claude/memory/* — no longer blocks docs/memory/*.md.
  • Removed duplicate PreCompact write path (kept agent-driven, dropped the parallel Python REST entry from hooks.json / cursor-hooks.json).
  • Hook-side captures (session_state, compact_summary) now set expiration_date = today + 90 days.

0.1.1

  • Cursor plugin fully functional (#4547).
  • Codex plugin support and integration docs (#4665).
  • Codex lifecycle hooks via opt-in installer (#4917).
  • Removed invalid keys from Claude plugin config (#4821).

0.1.0

  • Initial release: Mem0 plugin for Claude Code and Cursor (#4518).