Skip to main content
Glama

xgmem

Long-term memory for coding agents. Claude Code, Codex, Cursor and any other MCP client share one local store, so what one agent learns about a project, the next one recalls instead of re-reading the code.

  • Free-text memories. No schemas; notes of any length.

  • Hybrid search, small results. Local embeddings (bge-small-en-v1.5 via fastembed) plus SQLite FTS5 keywords. Only the best matches come back in full, so recall stays cheap.

  • Stays in sync. Memories fingerprint the files they describe; stale and recall flag the ones whose code changed.

  • Follows the repo. Git projects are identified by their first commit, so memories survive moves, renames and re-clones.

  • Local only. One SQLite file, no API keys. Nothing leaves the machine.

Quick setup (Claude Code, Codex, Cursor)

Open your agent (Claude Code, Codex or Cursor's agent) in the project and paste this. It installs the server, adds the memory rules and saves the first memories. You only need to paste it once: if your tool needs a restart to load the server, the next session saves the first memories by itself. It's also safe to paste again, because steps that are already done get skipped.

Set up xgmem (long-term memory MCP server) for this project. Skip any step that's already done, and don't ask me questions unless a step fails.

1. Run `ONNXRUNTIME_NODE_INSTALL_CUDA=skip npx -y xgmem@latest --check` (on native Windows, run `npx -y xgmem@latest --check`). It installs xgmem, finds Node 22.16+ even if the default Node is older, and downloads the embedding model (~65MB, so allow a few minutes). If `npx` isn't found, tell me to install Node.js 22.16 or newer and stop. If the output doesn't end with `xgmem ok`, show me the output and stop.
2. Add the xgmem MCP server for the tool you are running in, if it isn't there yet:
   - Claude Code: claude mcp add xgmem --scope user -e ONNXRUNTIME_NODE_INSTALL_CUDA=skip -- npx -y xgmem@latest (on native Windows, end with `-- cmd /c npx -y xgmem@latest`). If `claude` isn't on PATH, which is the case when Claude Code runs only as an editor extension, use the `claude` binary inside the extension folder, e.g. ~/.vscode/extensions/anthropic.claude-code-*/resources/native-binary/claude (Cursor: ~/.cursor/extensions/...).
   - Codex: codex mcp add xgmem --env ONNXRUNTIME_NODE_INSTALL_CUDA=skip -- npx -y xgmem@latest
   - Cursor: add "xgmem": { "command": "npx", "args": ["-y", "xgmem@latest"], "env": { "ONNXRUNTIME_NODE_INSTALL_CUDA": "skip" } } under "mcpServers" in ~/.cursor/mcp.json (merge, keep existing servers)
3. Add the text between BEGIN and END to the rules file for your tool (create it if missing; if an older xgmem section is there, replace it instead of adding a second one):
   - Claude Code: CLAUDE.md at the repo root
   - Codex: AGENTS.md at the repo root, without the `@xgmem.md` line
   - Cursor: .cursor/rules/xgmem.mdc, starting with the frontmatter `---` / `alwaysApply: true` / `---`, without the `@xgmem.md` line
4. Add `xgmem.md` to .gitignore.
5. If the xgmem tools (recall, remember) aren't available in this session yet, which is normal right after step 2, tell me to restart (Claude Code: quit and reopen it, or the editor it runs in; Codex: restart it; Cursor: enable xgmem in Settings → MCP). Tell me there's no need to paste this prompt again, because the rules from step 3 make the next session save the first memories by itself. Then stop.
6. Otherwise, explore the repo and save 10-15 memories with `remember` (projectPath = repo root) covering architecture, main flows, config and gotchas. List the files each one describes in `files`.
7. Finish with one line: what you set up and how many memories you saved.

BEGIN
@xgmem.md

## Memory (xgmem)

If xgmem.md doesn't exist at the repo root yet, xgmem has no memories for this project. Before your first task, explore the repo and save 10-15 memories with `remember` (projectPath = repo root) covering architecture, main flows, config and gotchas, with `files` = the files each one describes. If the xgmem tools aren't available, skip this and tell me.

Before reading code to answer a question or start a task:

1. Look at the titles in xgmem.md, then call xgmem `recall` with a short query and `projectPath` set to this repo's root.
2. If the results answer it, use them and don't re-read those files. Weaker matches come back as one-liners; call `recall` with their `ids` only if you need them. If a result is marked STALE, re-read only the files it lists.
3. If nothing relevant comes back, or it's not enough, explore the code as usual.

After learning something non-obvious (architecture, data flow, decisions and why, gotchas, where things live, conventions):

- Call `remember` with a short title, specific facts (file paths, function names, values) and `files` = the files it describes. Same title replaces the old memory.
- Skip anything obvious from a single file, and never store secrets.

After changing code: call `stale` and re-save every memory it lists (same title), or `forget` it if it no longer applies.
END

Related MCP server: Knowledge Graph MCP Server

Manual setup

1. Install Node.js 22.16+. Versions 22.13–22.15 have node:sqlite but not its FTS5 full-text search, which xgmem needs. It doesn't have to be your default Node: if npx starts xgmem with an older one, xgmem looks for a newer install (nvm, fnm, volta, asdf, mise, n, Homebrew, nvm-windows) and uses that. Then run npx -y xgmem@latest --check once. It downloads the embedding model (~65MB) into ~/.xgmem/models, so the first remember doesn't wait on it, and prints xgmem ok.

On Linux x64, set ONNXRUNTIME_NODE_INSTALL_CUDA=skip wherever xgmem is installed (the --check command and the MCP configs below). Without it, the installer of onnxruntime-node tries to download GPU files from a GitHub release that no longer exists, and the install fails with Failed to download the binaries: 404. xgmem runs on the CPU, so it doesn't need them. The configs below set it on every platform, where it's harmless.

2. Add the MCP server.

Claude Code

claude mcp add xgmem --scope user -e ONNXRUNTIME_NODE_INSTALL_CUDA=skip -- npx -y xgmem@latest

On native Windows, end it with -- cmd /c npx -y xgmem@latest.

Codex (CLI, IDE extension and app share ~/.codex/config.toml)

codex mcp add xgmem --env ONNXRUNTIME_NODE_INSTALL_CUDA=skip -- npx -y xgmem@latest

or add it to ~/.codex/config.toml yourself:

[mcp_servers.xgmem]
command = "npx"
args = ["-y", "xgmem@latest"]
env = { ONNXRUNTIME_NODE_INSTALL_CUDA = "skip" }

Cursor (~/.cursor/mcp.json for all projects, or .cursor/mcp.json for one)

{
  "mcpServers": {
    "xgmem": {
      "command": "npx",
      "args": ["-y", "xgmem@latest"],
      "env": { "ONNXRUNTIME_NODE_INSTALL_CUDA": "skip" }
    }
  }
}

Other tools (Windsurf, Cline, VS Code, Gemini CLI, ...): any MCP client works. Use the Cursor JSON or the Codex TOML above, whichever format your tool expects, in the config file its MCP docs name. The server is always npx -y xgmem@latest over stdio, with ONNXRUNTIME_NODE_INSTALL_CUDA=skip in its environment.

3. Check it's connected. Claude Code: /mcp. Codex: codex mcp list. Cursor: Settings → MCP, then enable xgmem. Other tools: their MCP or tools panel.

4. Add the memory rules. Copy the text between BEGIN and END in the Quick setup prompt into your tool's rules file. That text makes the agent recall first, read code only when memory falls short, and save what it learns.

Tool

Rules file

Claude Code

CLAUDE.md (keep the @xgmem.md line, which loads the index)

Codex

AGENTS.md (drop the @xgmem.md line)

Cursor

.cursor/rules/xgmem.mdc with alwaysApply: true frontmatter, or AGENTS.md (drop the @xgmem.md line)

Other tools

Their rules or instructions file, or AGENTS.md, which many tools read (drop the @xgmem.md line)

5. Ignore the index. Add xgmem.md to .gitignore. It's created on the first remember, and its ids only make sense on your machine.

6. Save the first memories. The rules do this on the first session where xgmem.md is missing. To do it right away, ask: "Explore this repo and save 10–15 xgmem memories covering architecture, main flows, config and gotchas." Later sessions recall instead of re-exploring.

Tools

Tool

Arguments

What it does

remember

title, content, projectPath?, tags?, files?

Saves a memory; same title in the same project replaces it. No projectPath = global.

recall

query, projectPath?, limit? (default 5), or ids

Hybrid search over that project plus global memories (no projectPath = everything). The best matches come back in full, weaker ones as one-liners. ids returns specific memories in full.

stale

projectPath

Lists memories whose files changed since they were saved.

forget

id

Deletes a memory (ids are in xgmem.md and recall results).

How projects are matched: projectPath can be any folder inside the project (the git root is used). Git repos are keyed by their first commit; folders outside git by path. Recalling from a folder outside any repo (e.g. a parent of several repos) also searches the projects below it.

Where memories live

Everything is in one SQLite file, ~/.xgmem/xgmem.db (table memories). Browse it with DB Browser for SQLite, or print it:

node -e "const {DatabaseSync}=require('node:sqlite');const db=new DatabaseSync(require('os').homedir()+'/.xgmem/xgmem.db',{readOnly:true});for(const m of db.prepare('SELECT id,root,title,content FROM memories').all())console.log('#'+m.id,m.title,'('+(m.root||'global')+')\n'+m.content+'\n')"

Variable

Default

Purpose

XGMEM_HOME

~/.xgmem

Database and global xgmem.md

XGMEM_MODEL_DIR

~/.xgmem/models

Embedding model cache

Development

ONNXRUNTIME_NODE_INSTALL_CUDA=skip npm install   # the env var matters on Linux x64 (see Manual setup)
npm test   # builds, then runs an end-to-end check against the real server

CI runs npm test on Ubuntu, macOS and Windows with Node 22.16 and 24.

Try a local build in your agent by pointing the MCP config at it instead of npx:

npm run build
claude mcp add xgmem --scope user -- node /absolute/path/to/xgmem/dist/index.js

Codex and Cursor use the same idea: command = node, args = the path to dist/index.js.

Docker: docker build -t xgmem . && docker run -i -v ~/.xgmem:/data xgmem. The container can only write xgmem.md for mounted project paths, so npx fits per-project memory better.

Upgrading from 0.0.x

1.0 replaces the 0.0.x knowledge-graph tools (create_entities, read_graph, search_nodes, ...) with the four tools above. Old memories aren't migrated. The 0.0.x JSON files in MEMORY_DIR_PATH are left untouched, so you can keep or delete them.

License

MIT

Available Tools

14 tools
add_graph_observationsB

Add new observations to existing entities in the project knowledge graph.

Inputs: projectId (required), observations (required).

copy_memoryA

Copy memory entities and their relations from one project to another

Inputs: sourceProjectId (required), targetProjectId (required), entityNames (required).

create_entitiesB

Create multiple new entities in the project knowledge graph

Inputs: projectId (required), entities (required).

create_relationsB

Create multiple new relations between entities in the project knowledge graph

Inputs: projectId (required), relations (required).

delete_entitiesB

Delete multiple entities and their associated relations from the project knowledge graph

Inputs: projectId (required), entityNames (required).

delete_observationsB

Delete specific observations from entities in the project knowledge graph

Inputs: projectId (required), deletions (required).

delete_relationsB

Delete multiple relations from the project knowledge graph

Inputs: projectId (required), relations (required).

get_project_observationsB

Get all observations saved in the separate file for a given projectId.

Inputs: projectId (required).

list_projectsB

List all projects with stored memory

Inputs: no named parameters.

open_nodesB

Open specific nodes in a project's knowledge graph by their names

Inputs: projectId (required), names (required).

read_graphA

Read the entire knowledge graph for a specific project

Inputs: projectId (required).

save_project_observationsB

Save observations for a project to a separate file in the format { projectId, observations: [{ entityName, contents: [...] }] }.

Inputs: projectId (required), observations (required).

search_all_projectsB

Search for nodes across all projects' knowledge graphs based on a query

Inputs: query (required).

search_nodesB

Search for nodes in a specific project's knowledge graph based on a query

Inputs: projectId (required), query (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.5/5.0

    Scored across 14 tools

    Disambiguation5/5

    Each tool has a distinct purpose: CRUD for entities, relations, observations, plus project management and search. No significant overlap.

    Naming Consistency4/5

    Mostly snake_case verb_noun pattern consistent. Minor deviations like 'open_nodes' vs 'get_project_observations' and 'copy_memory' instead of 'copy_entities'.

    Tool Count5/5

    14 tools is well-scoped for a knowledge graph memory system, covering essential operations without excess.

    Completeness3/5

    Covers create, delete, read, and search, but missing update operations for entities, relations, and observations. No project deletion either.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      A TypeScript MCP server that allows querying documents using LLMs with context from locally stored repositories and text files through a RAG (Retrieval-Augmented Generation) system.
      4
      17
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      A TypeScript MCP server for managing persistent knowledge graphs with entities, directional relations, and time-based observations. It enables users to create, search, and track structured information with built-in concurrency control and JSON file storage.
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Open-source MCP server that gives any LLM long-term memory using a knowledge graph and vector search hybrid. It stores entities, observations, and relationships, enabling semantic recall across sessions with automatic clustering and fail-loud infrastructure.
      51
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      A universal MCP server providing persistent, structured memory through a knowledge graph with graph storage, semantic vector search, and multi-hop traversal for AI agents and IDEs.
      37 PyPI
      1
      MIT