--- name: export description: Exports all project memories to a portable Markdown file for backup or migration. Use when backing up memories, migrating to another project, sharing memory state with teammates, or archiving before cleanup. --- # Mem0 Export Export all memories for the current project to a portable Markdown file. ## Execution ### Step 1: Resolve identity Determine the active identity: - `user_id` from `MEM0_USER_ID` env var, else `$USER`, else `"default"` - `project_id` (used as `app_id`) from `MEM0_PROJECT_ID` env var, or via the project resolver ### Step 2: Fetch all memories Call `get_memories` with: - `filters={"AND": [{"user_id": ""}, {"app_id": ""}]}` - `page_size=200` If the response is paginated (i.e. the result contains a `next` cursor or the count equals `page_size`), continue fetching pages until all memories are retrieved. ### Step 3: Format each memory as a YAML-frontmatter block For each memory record, produce a block in this exact format: ``` --- id: created_at: type: confidence: branch: files: categories: --- ``` Notes: - The `---` delimiters must be on their own lines with no extra whitespace. - `files` and `categories` are written as comma-separated values on a single line. - Leave a blank line after the content before the next `---` (for readability). - If a field is missing or null, write an empty string (not "null"). ### Step 4: Write the export file Determine the output filename: ``` mem0-export--.md ``` Where `` is today's date in UTC. Write all formatted blocks to this file using the Write tool (or equivalent). The file is written to the current working directory. ### Step 5: Print summary ``` Exported memories to ``` Where `` is the total number of memory blocks written. ## Error Handling - If `get_memories` returns an error or zero memories, print: ``` No memories found for project . Nothing exported. ``` - If the write fails, report the error to the user. ## Output formatting IMPORTANT: Do NOT use markdown in your output. OpenCode TUI renders text verbatim — markdown like **bold**, ## headers, and | table | syntax appears as raw characters. Use plain text with indentation for structure. Use dashes for lists. Use spaces to align columns instead of markdown tables.