switch-project について
現在のディレクトリで使うプロジェクト範囲を変更し、全体検索を有効にする Mem0 スキルです。プロジェクト対応表と検索設定をローカルファイルに保存します。
主な機能
- 01ディレクトリのプロジェクト範囲設定
- 02メモリの全体検索を有効化
- 03メモリの全体検索を無効化
- 04ローカルファイルへの設定保存
活用シーン
- 01指定プロジェクトにメモリ検索を限定
- 02プロジェクトやユーザーをまたいだメモリ検索
- 03プロジェクト単位の検索範囲に戻す
MCP 対応
Mem0 MCP の search_memories ツールでメモリを検索し、プロジェクト変更を確認します。
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ mem0ai/ mem0 --skill switch-projectインストール後、Claude Code で/switch-projectを入力して読み込まれたか確認します。
詳細
Mem0 プロジェクトの切り替え
現在のディレクトリでの自動的な project_id の検出を上書きするか、グローバル検索モードを有効にします。
使用方法
/mem0:switch-project <project-name>— 特定のプロジェクトスコープに切り替えます/mem0:switch-project --global— グローバル検索を有効にします(すべてのメモリ、すべてのユーザー、すべてのプロジェクト)/mem0:switch-project --no-global— グローバル検索を無効にし、プロジェクトごとのスコープに戻します
実行方法
--global フラグが指定された場合:
-
Bash ツールを使用して、
~/.mem0/settings.jsonのglobal_search: trueを設定します:python3 -c " import json, os settings_file = os.path.expanduser('~/.mem0/settings.json') settings = {} if os.path.isfile(settings_file): with open(settings_file) as f: settings = json.load(f) settings['global_search'] = True with open(settings_file, 'w') as f: json.dump(settings, f, indent=2) print('Global search enabled') " -
次を出力します:
Global search enabled. Searches now return all memories across all users and projects. Writes still use the current user_id and app_id. Restart the session for the change to take effect.
--no-global フラグが指定された場合:
-
Bash ツールを使用して、
~/.mem0/settings.jsonのglobal_search: falseを設定します:python3 -c " import json, os settings_file = os.path.expanduser('~/.mem0/settings.json') settings = {} if os.path.isfile(settings_file): with open(settings_file) as f: settings = json.load(f) settings['global_search'] = False with open(settings_file, 'w') as f: json.dump(settings, f, indent=2) print('Global search disabled') " -
次を出力します:
Global search disabled. Searches now return only memories scoped to the current project. Restart the session for the change to take effect.
プロジェクト名が指定された場合(フラグなし):
-
プロジェクト名が指定されていない場合は、次のように尋ねます:「このディレクトリで使用する project_id は何ですか?」
-
Bash ツールを使用して、マッピングを
~/.mem0/project_map.jsonに書き込みます:python3 -c " import json, os map_file = os.path.expanduser('~/.mem0/project_map.json') mapping = {} if os.path.isfile(map_file): with open(map_file) as f: mapping = json.load(f) mapping[os.getcwd()] = '<PROJECT_NAME>' os.makedirs(os.path.dirname(map_file), exist_ok=True) with open(map_file, 'w') as f: json.dump(mapping, f, indent=2) print(f'Mapped {os.getcwd()} -> <PROJECT_NAME>') "(
<PROJECT_NAME>をユーザーが選択したプロジェクト名に置き換えます。) -
既存のメモリを検索して確認します:
query="project"、filters={"AND": [{"user_id": "<active_user_id>"}, {"app_id": "<PROJECT_NAME>"}]}、top_k=1を指定してsearch_memoriesを呼び出します
-
次を出力します:
Switched to project <PROJECT_NAME>. <N> memories found for this project. Note: This override persists across sessions for this directory.
コメント
Markdown 対応