Views or changes the default memory scope (project, session, or global) used when saving and searching memories. Use when the user wants to control whether memo
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-mem0-scope-2eb1b96c5a61 ,按照其中的说明把「mem0-scope」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
View or change the default memory scope — the scope the memory tools use when
no explicit scope is given. The setting persists in ~/.mem0/settings.json
(default_scope) and the plugin reads it fresh on each memory operation, so a
change takes effect immediately in the current session.
The three scopes:
project (default) — this repo only. Filters by user_id + app_id.session — this run only. Adds run_id (the current session) so memories are
isolated to this conversation.global — across ALL your projects. Reads use app_id="*"; writes drop
app_id so the memory is user-wide.Look at the user's message for a target scope word: project, session, or
global (also accept "repo"→project, "run"→session, "all"/"everywhere"→global).
Read the current default scope from settings:
_S="$HOME/.mem0/settings.json"
[ -f "$_S" ] && grep -o '"default_scope"[[:space:]]*:[[:space:]]*"[a-z]*"' "$_S" | grep -o '[a-z]*"$' | tr -d '"' || echo "project"
If the command prints nothing, the scope is project (the default).
(Optional) Show how many memories live in the current scope by calling
get_memories with scope="<current>", page_size=1, and reading the
count (or result length) from the response.
Display using the identity the plugin exported (do NOT re-shell git):
Mem0 memory scope
Current default scope: <current>
project - this repo only (user + app_id) <marker if active>
session - this run only (adds run_id) <marker if active>
global - all your projects (app_id = *) <marker if active>
User: ${MEM0_USER_ID}
Project: ${MEM0_APP_ID}
Session: ${MEM0_SESSION_ID}
To change: /mem0-scope session (or project / global)
Put [active] next to the current scope. If you fetched a count in step 2,
add a Memories in scope: <N> line.
Validate the target is one of project, session, global. If not, show the
three options and stop.
Read the existing settings so you preserve every other key. Use the Read tool
on ~/.mem0/settings.json (it may not exist yet — treat a missing file as
{}).
Write the file back with the Write tool, keeping ALL existing keys and only
setting "default_scope" to the target. Pretty-print with 2-space indent and
a trailing newline. Do not drop global_search, auto_save, or any
other field that was present.
Example resulting file (when other keys already existed):
{
"auto_save": true,
"search_limit": 10,
"default_scope": "global"
}
Confirm:
Default memory scope changed: <old> -> <new>
<one line describing the effect — see below>
Applies immediately to memory tools in this session.
To revert: /mem0-scope <old>
Effect lines:
scope to override it for that one call.delete_all_memories deliberately ignores the default scope: deleting
user-wide always requires an explicit scope="global", so changing the
default can never turn a routine cleanup into a cross-project wipe.global scope (this user, all their projects) is distinct from the separate
global_search setting (all users). Leave global_search untouched here.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.