Skip to main content
The mem0 CLI lets you add, search, list, update, and delete memories directly from the terminal. It works with the Mem0 Platform API and is available as both an npm package and a Python package. Both implementations provide identical behavior: same commands, same options, same output formats. Running it inside an agent? Put --agent before any command to get clean JSON instead of human output. See Use with AI agents.

Installation

Looking for Agent Mode signup? See Sign up as an agent: install, signup, first memory in four commands.

Authentication

Run the interactive setup wizard to configure your API key:
This prompts for your API key and a default user ID, validates the connection, and saves the configuration locally. For CI/CD or non-interactive environments, pass both values as flags:
You can also set your API key via environment variable:

Quick start

Commands

mem0 init

Interactive setup wizard. Prompts for your API key and default user ID.
If an existing configuration is detected, the CLI will ask for confirmation before overwriting. Use --force to skip the prompt (useful in CI/CD pipelines).
AI agents should use mem0 init --agent: see Sign up as an agent.

mem0 add

Add a memory from text, a JSON messages array, a file, or stdin.
--categories is not supported on add and exits with an error pointing at --custom-categories.
Search memories using natural language.

mem0 list

List memories with optional filters and pagination.

mem0 get

Retrieve a specific memory by ID.

mem0 update

Update the text or metadata of an existing memory.

mem0 delete

Delete a single memory, all memories for a scope, or an entire entity.

mem0 import

Bulk import memories from a JSON file.
The file should be a JSON array where each item has a memory (or text or content) field and optional user_id, agent_id, and metadata fields.

mem0 config

View or modify the local CLI configuration.

mem0 entity

List or delete entities (users, agents, apps, runs).
Deleting an entity removes it and every memory belonging to it. Preview first with --dry-run.

mem0 event

Inspect background processing events created by async operations (e.g. bulk deletes, large add jobs).

mem0 status

Verify your API connection and display the current project.

mem0 whoami

Print the identity the CLI is currently using. After mem0 init --agent, the server issues an identifier (default_user_id, for example user_a1b2c3d4e5f6) and the CLI stores it in ~/.mem0/config.json. That value is the agent’s stable identity across runs, and it is the row key on the AGENTRUSH leaderboard. Use this instead of parsing the config file by hand:
No network call. The command exits with code 1 if no default_user_id is configured yet. In that case, run mem0 init --agent first.

mem0 identify

Attach an agent name to an account created with mem0 init --agent, if you did not pass --agent-caller at the time. It keeps the same API key and only fills in the name, so it is safe to run more than once. See Sign up as an agent.

mem0 help

Print the command tree. Adding --json returns the whole tree as structured data, so an agent can discover the available commands and options for itself.

Output formats

Most commands take -o, --output to control how results are displayed. Not every command accepts every format: Passing a format a command does not accept is an error, so check the command’s own flag table above. There is no agent value for --output. Agent mode is turned on by the global --json/--agent flag placed before the command name, and it overrides --output. See Use with AI agents. The exact JSON shape depends on the command. search returns a bare array of memories, while list returns an envelope object with the memories under data:
Agent mode always returns the envelope, whichever command you run, so .data[] works everywhere:

Use with AI agents

The CLI is purpose-built for use inside AI agent tool loops. Pass --agent or --json as a global flag on any command to activate agent mode:
  • Every command outputs a consistent JSON envelope: {"status", "command", "duration_ms", "scope", "count", "data"}
  • The data field contains only the fields that matter: IDs, memory text, scores, categories. Noisy API fields are stripped.
  • All human-readable output is suppressed: no spinners, no colors, no banners.
  • Errors are returned as JSON to stdout with a non-zero exit code, so your agent can catch them the same way as successes.
Two other agent-friendly features:
  • --output json returns structured data without sanitization, useful when you want the full raw API response
  • mem0 help --json returns the complete command tree as JSON, so agents can self-discover available commands and options
For non-interactive environments (CI, agent runtimes), set credentials via mem0 init --api-key m0-xxx --user-id alice --force or the MEM0_API_KEY environment variable.

Errors and exit codes

Every command exits 0 when it succeeds and 1 when it fails, so if mem0 ...; then works as you would expect in a script. In agent mode (--json or --agent), failures still print a JSON envelope to stdout alongside the non-zero exit, so you can parse successes and failures the same way. Errors you are most likely to hit: Run mem0 status to check whether the CLI can reach the API and which project the key belongs to. It reports the connection state, the API URL, and any error.

Environment variables

Environment variables take precedence over values in the config file, which take precedence over defaults.

Global flags

These two flags belong to mem0 itself, so they go before the command name:
On init only, --agent means something different. mem0 init --agent creates an Agent Mode account (see Sign up as an agent); it does not switch the output to JSON. To get JSON from init, put the flag first: mem0 --json init.
The following flags are accepted by most commands, but they belong to the command, so they go after the command name:

What’s next

Quickstart

Store your first memory in under five minutes using the SDK or CLI

Memory operations

Learn about add, search, update, and delete operations in depth

API reference

See the complete REST API documentation