Back to Mem0

mem0 CLI

cli/README.md

2.0.14.3 KB
Original Source

mem0 CLI

The official command-line interface for mem0 — the memory layer for AI agents. Works with the Mem0 Platform API. Available in Python and Node.js.

For AI agents: pass --agent (or --json) on any command for structured JSON output purpose-built for tool loops — sanitized fields, no colors or spinners, errors as JSON. See Agent mode below.

Installation

bash
npm install -g @mem0/cli
bash
pip install mem0-cli

Both packages install a mem0 binary with identical behavior.

Quick start

bash
# Interactive setup wizard
mem0 init

# Or login via email (get a new API key)
mem0 init --email [email protected]

# Or authenticate with an existing API key
mem0 init --api-key m0-xxx

# Add a memory
mem0 add "I prefer dark mode and use vim keybindings" --user-id alice

# Search memories
mem0 search "What are Alice's preferences?" --user-id alice

# List all memories for a user
mem0 list --user-id alice

# Update a memory
mem0 update <memory-id> "I switched to light mode"

# Delete a memory
mem0 delete <memory-id>

Commands

CommandDescription
mem0 initSetup wizard — login via email or configure API key manually
mem0 addAdd a memory from text, JSON messages, a file, or stdin
mem0 searchSearch memories using natural language
mem0 listList memories with optional filters and pagination
mem0 getRetrieve a specific memory by ID
mem0 updateUpdate the text or metadata of a memory
mem0 deleteDelete a memory, all memories for a scope, or an entity
mem0 importBulk import memories from a JSON file
mem0 configView or modify CLI configuration
mem0 entityList or delete entities (users, agents, apps, runs)
mem0 eventInspect background processing events (bulk deletes, large add jobs)
mem0 statusVerify API connection and display current project
mem0 versionPrint the CLI version

Run mem0 <command> --help for detailed usage on any command.

Agent mode

Pass --agent (or its alias --json) as a global flag on any command to get output designed for AI agent tool loops:

bash
mem0 --agent search "user preferences" --user-id alice
mem0 --agent add "User prefers dark mode" --user-id alice
mem0 --agent list --user-id alice

Every command returns the same envelope shape:

json
{
  "status": "success",
  "command": "search",
  "duration_ms": 134,
  "scope": { "user_id": "alice" },
  "count": 2,
  "data": [
    { "id": "abc-123", "memory": "User prefers dark mode", "score": 0.97, "created_at": "2026-01-15", "categories": ["preferences"] }
  ]
}

What agent mode does differently from --output json:

  • Sanitized data: only the fields an agent needs (id, memory, score, etc.) — no internal API noise
  • No human output: spinners, colors, and banners are suppressed entirely
  • Errors as JSON: errors go to stdout as {"status": "error", "command": "...", "error": "..."} with a non-zero exit code

Use mem0 help --json to get the full command tree as JSON — useful for agents that need to self-discover available commands.

Output formats

Control how results are displayed with --output:

FormatDescription
textHuman-readable with colors and formatting (default)
jsonStructured JSON for piping to jq (raw API response)
tableTabular format (default for list)
quietMinimal — just IDs or status codes
agentStructured JSON envelope with sanitized fields (set by --agent/--json)

Environment variables

VariableDescription
MEM0_API_KEYAPI key (overrides config file)
MEM0_BASE_URLAPI base URL
MEM0_USER_IDDefault user ID
MEM0_AGENT_IDDefault agent ID
MEM0_APP_IDDefault app ID
MEM0_RUN_IDDefault run ID
MEM0_ENABLE_GRAPHEnable graph memory (true / false)

Implementations

LanguageDirectoryPackageDocs
TypeScriptnode/@mem0/cliREADME
Pythonpython/mem0-cliREADME

Documentation

Full documentation is available at docs.mem0.ai/platform/cli.

License

Apache-2.0