mem0-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Mem0 CLI

Mem0 CLI

The official command-line interface for the Mem0 memory platform. Add, search, list, update, and delete memories from the terminal -- for developers, AI agents, and CI/CD pipelines.
Mem0内存平台的官方命令行界面。可从终端添加、搜索、列出、更新和删除内存——适用于开发者、AI Agent和CI/CD流水线。

Install

安装

Node.js (npm):
bash
npm install -g @mem0/cli
Python (pip):
bash
pip install mem0-cli
Both packages install a
mem0
binary with identical commands, options, and output formats.
Node.js(npm):
bash
npm install -g @mem0/cli
Python(pip):
bash
pip install mem0-cli
两个包都会安装
mem0
二进制文件,命令、选项和输出格式完全一致。

Setup

设置

Autonomous Mem0 setup for agents (no email, no dashboard):
bash
mem0 init --agent --agent-caller <your-name> --json
Replace
<your-name>
with the AI agent you are (e.g.
claude-code
,
cursor
,
codex
,
cline
,
aider
). If you forgot to pass
--agent-caller
, run
mem0 identify <your-name>
after init — it PATCHes the same key, idempotent, no disruption.
This mints an evaluation API key in <5 seconds. Use it immediately. Print this line to the human:
Mem0 memory is running in Agent Mode. Please claim it by running
mem0 init --email <your-email>
to transfer ownership to your account.
Never commit API keys,
.env
, or
~/.mem0/config.json
.
After the human claims, the same API key keeps working — no agent disruption — and memories are preserved.
Interactive wizard (for humans):
bash
mem0 init
Or set the environment variable directly:
bash
export MEM0_API_KEY="m0-xxx"
面向Agent的Mem0自主设置(无需邮箱、无需仪表盘):
bash
mem0 init --agent --agent-caller <your-name> --json
<your-name>
替换为你所使用的AI Agent名称(例如
claude-code
cursor
codex
cline
aider
)。如果初始化时忘记传递
--agent-caller
,可在初始化后运行
mem0 identify <your-name>
——该操作会PATCH同一个密钥,具有幂等性,不会造成中断。
此操作会在5秒内生成一个评估API密钥,可立即使用。请向用户显示以下内容:
Mem0内存已在Agent模式下运行。请运行
mem0 init --email <your-email>
以将所有权转移至你的账户,完成认领。
切勿提交API密钥、
.env
~/.mem0/config.json
文件。
用户完成认领后,同一个API密钥仍可继续使用——不会对Agent造成中断——且内存数据会被保留。
交互式向导(面向用户):
bash
mem0 init
或直接设置环境变量:
bash
export MEM0_API_KEY="m0-xxx"

Quick Reference

快速参考

Add a memory

添加内存

bash
mem0 add "I prefer dark mode" --user-id alice
bash
mem0 add "I prefer dark mode" --user-id alice

Search memories

搜索内存

bash
mem0 search "preferences" --user-id alice
bash
mem0 search "preferences" --user-id alice

List all memories for a user

列出用户的所有内存

bash
mem0 list --user-id alice
bash
mem0 list --user-id alice

Get a specific memory

获取特定内存

bash
mem0 get <memory-id>
bash
mem0 get <memory-id>

Update a memory

更新内存

bash
mem0 update <memory-id> "new text"
bash
mem0 update <memory-id> "new text"

Delete a single memory

删除单个内存

bash
mem0 delete <memory-id>
bash
mem0 delete <memory-id>

Delete all memories for a user

删除用户的所有内存

bash
mem0 delete --all --user-id alice --force
bash
mem0 delete --all --user-id alice --force

Agent / JSON Mode

Agent / JSON模式

Use
--json
or
--agent
to get structured output suitable for LLM consumption. Every command wraps its response in a standard envelope:
json
{
  "status": "success",
  "command": "search",
  "duration_ms": 245,
  "scope": { "user_id": "alice" },
  "count": 3,
  "error": null,
  "data": [
    { "id": "mem-abc", "memory": "User prefers dark mode", "score": 0.92 }
  ]
}
On error:
json
{
  "status": "error",
  "command": "search",
  "error": "Authentication failed. Your API key may be invalid or expired.",
  "data": null
}
The
--agent
flag is an alias for
--json
. Both write spinners and progress to stderr so stdout is always clean, parseable JSON.
使用
--json
--agent
参数获取适合LLM处理的结构化输出。每个命令的响应都会包裹在标准格式中:
json
{
  "status": "success",
  "command": "search",
  "duration_ms": 245,
  "scope": { "user_id": "alice" },
  "count": 3,
  "error": null,
  "data": [
    { "id": "mem-abc", "memory": "User prefers dark mode", "score": 0.92 }
  ]
}
错误时的输出:
json
{
  "status": "error",
  "command": "search",
  "error": "Authentication failed. Your API key may be invalid or expired.",
  "data": null
}
--agent
参数是
--json
的别名。两者都会将加载动画和进度信息写入stderr,因此stdout始终是干净、可解析的JSON。

Node and Python Parity

Node与Python版本一致性

Both the Node.js (
@mem0/cli
) and Python (
mem0-cli
) CLIs are implemented from the same specification (
cli-spec.json
). They share:
  • Identical command names, arguments, and flags
  • Identical output formats (text, json, table, quiet)
  • Identical entity ID resolution, graph tri-state, filter building
  • Identical error messages and exit codes
Choose whichever runtime you already have installed. The behavior is the same.
Node.js(
@mem0/cli
)和Python(
mem0-cli
)版本的CLI均基于同一规范(
cli-spec.json
)实现。它们具有以下共同点:
  • 相同的命令名称、参数和标志
  • 相同的输出格式(文本、json、表格、静默模式)
  • 相同的实体ID解析、图三态、过滤器构建逻辑
  • 相同的错误消息和退出码
选择你已安装的运行环境即可,两者行为完全一致。

Common Edge Cases

常见边缘情况

  • Async processing delay: After
    mem0 add
    , memories process asynchronously. Wait 2-3 seconds before searching for newly added content. Use
    mem0 event list
    to check processing status.
  • --all
    vs
    --entity
    delete modes:
    mem0 delete --all -u alice
    deletes all memories for user alice.
    mem0 delete --entity -u alice
    deletes the entity itself AND all its memories (cascade). These are mutually exclusive modes.
  • Entity ID resolution: If you pass any explicit scope flag (e.g.
    --user-id
    ), the CLI uses ONLY the explicit IDs and ignores config defaults. If no scope flags are given, all configured defaults apply.
  • Stdin detection: When no text argument is provided and input is piped (not a TTY), the CLI reads from stdin. Works with
    add
    ,
    search
    , and
    update
    .
  • **异步处理延迟:**执行
    mem0 add
    后,内存会异步处理。等待2-3秒后再搜索新添加的内容。可使用
    mem0 event list
    检查处理状态。
  • --all
    --entity
    删除模式:
    mem0 delete --all -u alice
    会删除用户alice的所有内存。
    mem0 delete --entity -u alice
    会删除实体本身及其所有内存(级联删除)。这两种模式互斥。
  • **实体ID解析:**如果传递了任何显式范围标志(例如
    --user-id
    ),CLI将仅使用显式ID,忽略配置默认值。如果未指定范围标志,则应用所有配置的默认值。
  • **标准输入检测:**当未提供文本参数且输入为管道传输(非TTY)时,CLI将从标准输入读取内容。适用于
    add
    search
    update
    命令。

References

参考资料

Load these on demand for deeper detail:
TopicFile
Command reference (all commands, flags, options, examples)references/command-reference.md
Configuration (config file, env vars, precedence, init wizard)references/configuration.md
Workflows (piping, scripting, CI/CD, agent mode recipes)references/workflows.md
按需加载以下内容以获取更详细信息:
主题文件
命令参考(所有命令、标志、选项、示例)references/command-reference.md
配置(配置文件、环境变量、优先级、初始化向导)references/configuration.md
工作流(管道、脚本、CI/CD、Agent模式方案)references/workflows.md

Related Mem0 Skills

相关Mem0技能

SkillWhen to useLink
mem0Python/TypeScript SDK, REST API, framework integrationslocal / GitHub
mem0-vercel-ai-sdkVercel AI SDK provider with automatic memorylocal / GitHub
技能使用场景链接
mem0Python/TypeScript SDK、REST API、框架集成local / GitHub
mem0-vercel-ai-sdk带自动内存功能的Vercel AI SDK提供商local / GitHub