CLI

MemOS CLI

Connect MemOS to local terminals and Agent workflows through command-line tools.

MemOS CLI is designed for Agents and development environments that can execute shell commands. It wraps common memory operations into the memos command, so you can verify memory flows in a terminal or let an Agent search memories before answering and write useful new memories afterward.


1. When to Use It

  • You want to quickly test memory operations such as add, search, get, and delete in a terminal.
  • Your Agent framework can execute shell commands, but does not have a dedicated MemOS plugin.
  • You want one reusable Skill to work across multiple Agents instead of writing a separate plugin for each framework.

If you use OpenClaw, prefer the OpenClaw Cloud Plugin. If your client supports MCP natively, see the MCP Guide.


2. Install

npm install -g @memtensor/memos-cloud-cli

After installation, confirm that the CLI is available:

memos --help

3. Choose a Usage Mode and Configure

MemOS CLI has two usage modes: install a memory Skill for an Agent, or manually run memos commands in a terminal.


3.1 Use with Agents

To let an Agent automatically search and write memories, use memos init to install the memory Skill. --agent is currently required; if it is omitted, the command fails because the CLI needs to know where to install the Skill.

memos init --agent codex

You can also write the API Key during initialization:

memos init --api-key YOUR_API_KEY --agent codex

The currently supported Agents are listed below. Pass the matching value via --agent:

Agent--agent value
Codex CLIcodex
Cursorcursor
Claude Codeclaude
OpenClawopenclaw
Hermeshermes
Traetrae
Trae (China)trae-cn
OpenCodeopencode
Antigravityantigravity
CodeBuddyworkbuddy
Clinecline
GitHub Copilotcopilot

For example, to install the memory Skill for Cursor:

memos init --agent cursor

Once installed, the Agent will automatically load the Skill. During each conversation turn, the Agent will:

  1. Before answering — automatically run memos search to retrieve long-term memories related to the current task
  2. After answering — automatically run memos add to write new facts, preferences, etc. into MemOS

If you already have a MemOS plugin installed (e.g. the OpenClaw cloud plugin), add --memos-plugin to generate plugin-aware Skill guidance:

memos init --agent openclaw --memos-plugin
Using OpenClaw as an example, in the LOCOMO evaluation, using MemOS CLI alone reduced token usage by about 65.5%; integrating MemOS Cloud + CLI improved accuracy from 66.60% to 77.27%.
ParameterDescription
-k, --api-keyMemOS API Key
--user-idDefault user ID
--conversation-idDefault conversation ID
--memos-pluginGenerate plugin-aware Skill guidance when a MemOS memory plugin is installed
--agentInstall Skill to a specific Agent directory; required

3.2 Use Directly in Terminal

If you only use CLI commands manually in a terminal and do not install an Agent Skill, use memos config set to configure CLI variables. After these values are set, later commands automatically use them when the corresponding parameter is not provided.

Configure the API Key:

memos config set platform.api_key YOUR_API_KEY

Configure the default user ID:

memos config set defaults.user_id user_123

Configure the default conversation ID:

memos config set defaults.conversation_id conv_001

4. Quick Start

After completing Agent initialization or terminal configuration above, use the following commands to verify memory operations.

Add a memory:

memos add "The user prefers Python programming"

Search related memories:

memos search "programming language preference"

Chat with memory:

memos chat "Do you know my preference?"

Get memories for a user:

memos get user_123

Query the original text of a memory:

memos origin mem_123456

Delete one memory, or delete all memories for a user:

memos delete mem_123456
memos delete --user-id user_123

5. Command Reference

memos add

Write a memory into MemOS.

memos add "The user prefers Python for data analysis and often uses pandas"
memos add --message "The user frequently uses Jupyter Notebook" --user-id user_123
ParameterDescription
[MESSAGE]Memory content to write; use either this or --message
-m, --messageMemory content; alternative to the positional argument
--user-idUser identifier; defaults to defaults.user_id in config
--formatOutput format; defaults to agent

Search for memories related to a query.

memos search "data analysis tool preference"
memos search "programming language" --format json --detail detail
ParameterDescription
[QUERY]Search query; use either this or --query
-q, --querySearch query; alternative to the positional argument
--user-idUser identifier; defaults to defaults.user_id in config
--include-preferenceInclude preference memories (true / false); defaults to true
--include-tool-memoryInclude tool memories (true / false); defaults to false
--include-skill-memoryInclude skill memories (true / false); defaults to false
--memory-limit-numberMax number of main memories to recall; defaults to 9
--preference-limit-numberMax number of preference memories to recall; defaults to 9
--tool-memory-limit-numberMax number of tool memories to recall; defaults to 6
--skill-memory-limit-numberMax number of skill memories to recall; defaults to 6
--formatOutput format; defaults to agent
--detailDetail level for non-JSON output; defaults to simple; supports simple, detail

memos get

Get memories by user.

memos get user_123
memos get user_123 --format json --detail detail
ParameterDescription
[USER_ID]User identifier; falls back to defaults.user_id in config
--user-idAlias for [USER_ID]; same fallback rules
--pagePage number; omitted from request body if not set
--sizePage size; omitted from request body if not set
--include-preferenceInclude preference memories (true / false); defaults to API default if not set
--include-tool-memoryInclude tool memories (true / false); defaults to API default if not set
--formatOutput format; defaults to agent
--detailDetail level; defaults to simple; supports simple, detail

memos origin

Query the original text of a memory by memory ID.

memos origin mem_123456
memos origin mem_123456 --format json
ParameterDescription
MEMORY_IDMemory ID whose original text should be queried; required
--formatOutput format; defaults to agent

memos delete

Delete one memory, or delete all memories for a user.

memos delete mem_123456 --format json
memos delete --user-id user_123 --format json
ParameterDescription
[MEMORY_ID]Memory ID to delete; pass this to delete a single memory
--user-idDelete all memories for this user; use either this or MEMORY_ID
--formatOutput format; defaults to agent

memos chat

Chat using MemOS memories as context.

memos chat "Do you know my preferences?"
memos chat "Do you know my preferences?" --user-id user_123 --format table
ParameterDescription
[QUERY]Chat question; use either this or --query
-q, --queryChat question; alternative to the positional argument
--user-idUser identifier; defaults to defaults.user_id in config
--formatOutput format; defaults to agent

memos extract

Extract candidate memories from a message without writing them.

memos extract "The user likes coffee and prefers dark mode" --format json
ParameterDescription
[MESSAGE]Message to extract from; use either this or --message
-m, --messageMessage to extract from; alternative to the positional argument
--user-idUser identifier; defaults to defaults.user_id in config
--formatOutput format; defaults to agent

memos rerank

Rerank candidate documents by relevance.

memos rerank "python backend" "Flask guide" "React guide" --format json
ParameterDescription
[QUERY]Rerank query; use either this or --query
[DOCUMENTS]...Candidate document texts; multiple positional arguments
-q, --queryRerank query; alternative to the positional argument
--documentsCandidate document texts; can be repeated
--top-nReturn only the top N results
--formatOutput format; defaults to agent

memos feedback

Submit feedback to improve memory management quality.

memos feedback "Prefer concise, direct technical answers." --user-id user_123 --format json
ParameterDescription
[FEEDBACK_TEXT]Feedback content; use either this or --feedback-content
--feedback-contentFeedback content; alternative to the positional argument
--user-idUser identifier; defaults to defaults.user_id in config
--formatOutput format; defaults to agent

memos message

Retrieve original conversation messages.

memos message --user-id user_123 --conversation-id conv_001
memos message --user-id user_123 --limit 10 --format table
ParameterDescription
--user-idUser identifier; required
--conversation-idConversation ID; defaults to defaults.conversation_id in config
--limitMax messages to return; defaults to 6, max 50
--formatOutput format; defaults to agent

memos status

Query the processing status of an async task. The task ID comes from the task_id returned by add or feedback in async mode.

memos status abc123-task-id --format json
ParameterDescription
[TASK_ID]Async task ID; required
--formatOutput format; defaults to agent

Returned status values include running, completed, and failed.


memos kb

Knowledge base management subcommand group: create knowledge bases, upload documents, and query or delete files.


memos kb create

Create a knowledge base.

memos kb create --name "Product FAQ" --description "Common product questions" --format json
ParameterDescription
--nameKnowledge base name; required
--descriptionKnowledge base description; optional
--formatOutput format; defaults to agent

memos kb remove

Remove (delete) a knowledge base.

memos kb remove base_xxxxx --format json
ParameterDescription
[KB_ID]Knowledge base ID; required
--formatOutput format; defaults to agent

memos kb add-file

Upload documents to a knowledge base. Supports PDF, DOCX, DOC, TXT, JSON, MD, XML.

memos kb add-file --kb-id base_xxxxx --files '["https://example.com/doc.pdf"]' --format json
memos kb add-file --kb-id base_xxxxx --files '[{"content":"https://cdn.example.com/file.docx"}]' --format json
ParameterDescription
--kb-idTarget knowledge base ID; required
--filesJSON array of file entries: URL strings or {"content": "..."} objects; required
--formatOutput format; defaults to agent

memos kb get-file

Get knowledge base file details and processing status.

memos kb get-file --file-ids '["file_id_1", "file_id_2"]' --format json
ParameterDescription
--file-idsJSON array of file IDs; required
--formatOutput format; defaults to agent

memos kb list-file

List files in a knowledge base with pagination, optionally filtered by type.

memos kb list-file --kb-id base_xxxxx
memos kb list-file --kb-id base_xxxxx --type skill --page 2 --page-size 10 --format json
ParameterDescription
--kb-idKnowledge base ID; required
--typeFilter by type: document or skill; optional
--pagePage number; defaults to 1
--page-sizeItems per page; defaults to 20
--formatOutput format; defaults to agent

memos kb delete-file

Delete files from a knowledge base.

memos kb delete-file --kb-id base_xxxxx --file-ids '["file_id_1"]' --format json
ParameterDescription
--kb-idKnowledge base ID; required
--file-idsJSON array of file IDs to delete; required
--formatOutput format; defaults to agent

6. Output Formats

All commands support --format. The default format is agent. search and get also support --detail.

FormatUse case
tableHuman-readable terminal output
markdownPaste into documentation
agentDefault; inject directly into Agent context
jsonScripts, workflows, or structured processing
memos search "python"
memos search "python" --format table --detail simple
memos search "python" --format markdown --detail detail
memos search "python" --format agent --detail simple
memos search "python" --format json --detail detail

7. Configuration Commands and Environment Variables

View or modify local configuration:

memos config show
memos config get platform.api_key
memos config set platform.api_key YOUR_API_KEY
memos config set defaults.user_id user_123
memos config set defaults.conversation_id conv_001
Environment VariableDescription
MEMOS_API_KEYYour API Key
MEMOS_BASE_URLAPI Base URL; defaults to https://memos.memtensor.cn/api/openmem/v1

Global options:

ParameterDescription
--api-key TEXTOverride the API Key in local configuration
--base-url TEXTOverride the API Base URL
--versionShow version number

All CLI requests include a source=cli tag. When the framework can be identified from environment variables or parent processes, the framework info is also attached to memory API requests.


8. CLI, Plugin, and MCP

IntegrationBest forCharacteristics
PluginAgent frameworks with deep MemOS integrationDeepest integration and best experience; requires per-framework adaptation
CLI + SkillAny Agent framework that can execute shell commandsHighly portable, low adaptation cost, great for cross-framework automation
MCPMCP-native clientsStandardized tool protocol for clients that support MCP

The three approaches are complementary. Plugin is best for deep integration, CLI + Skill for general automation, and MCP for MCP-native clients.


Next Steps

Quick Start

Run the basic memory write and search flow with API / SDK

MCP Guide

Connect MemOS memory tools through MCP clients

OpenClaw Cloud Plugin

Use the OpenClaw plugin for deeper Agent integration