Repository avatar
Other Tools
v0.1.0
active

0gm-memory

io.github.0gfoundation/0gm-memory

Long-term memory for coding agents on 0GM-2.0: past sessions come back as dated verbatim quotes.

Documentation

0gm-memory

Long-term memory for coding agents. Your agent's past sessions are saved to 0GM-2.0's in-model memory (0GM-CMSA), and when it needs history it gets the exact past messages back, quoted word for word with their dates.

CI Licence: MIT Python

Claude Code · Codex · OpenCode · Hermes Agent · Cursor · Cline · any MCP client

  • Agents forget. Every new session starts blank, so decisions, reverted attempts and their reasons get lost.
  • This remembers for them. Finished sessions are saved automatically, secrets stripped on your machine first, into a wallet that holds up to 120M tokens of memory.
  • It returns evidence, not a summary. ask_memory hands back dated, verbatim quotes, so the agent reasons over what was actually said.

Quick start · Install per agent · How it works · Results · Privacy · FAQ

In 15 seconds

sequenceDiagram
    autonumber
    participant A as Coding agent
    participant P as 0gm-memory (your machine)
    participant W as 0GM-CMSA memory
    A->>P: session ends (hook or plugin)
    P->>P: redact secrets, buffer locally
    P->>W: save once the buffer passes about 70K tokens
    Note over A,W: days later, in a fresh session
    A->>P: ask_memory("why is the dev server on 47831?")
    P->>W: find the relevant past messages
    W-->>P: verbatim quotes with session dates
    P->>P: check each date against a local index
    P-->>A: [2026-11-24] User: "the Zebra scanner bridge hard-codes 8080 ..."

The same question in a fresh session, in the invented warehouse project (pallet-ledger) used for the real-session tests:

Without memoryWith 0gm-memory

You: Why is the dev server on port 47831 and not 8080?

Agent: PORT defaults to 47831 in config.py, but nothing in the code says why. It may have been chosen to avoid a conflict. Shall I change it back to 8080?

You: Why is the dev server on port 47831 and not 8080?

Agent (calls ask_memory):

[2026-11-24] User: "Move the dev server off port 8080. Reason: the Zebra scanner bridge on the dock PCs hard-codes 8080, so 'pallet-ledger serve' collides with it on every dock PC. We decided on port 47831."

It moved because the scanner bridge on the dock PCs owns 8080; changing it back would break every dock PC.

The quote is verbatim from a real Claude Code session on 24 Nov 2026; the answers are shortened.

What each agent gets

AgentAsk (ask_memory)Auto-saveHow sessions are savedTested in a real session
Claude CodeyesyesSessionEnd and PreCompact hooksyes, 24 Nov 2026
Codex CLIyesyes, once its hooks are trustedSessionEnd and PreCompact hooks on the rolloutyes, 24 Nov 2026
OpenCodeyesyesplugin on the session idle hook; save --opencode for past sessionsyes, 24 Nov 2026
Hermes Agentyes (zgm_ask_memory)yesmemory provider, after every turnyes, 24 Nov 2026
Cursoryesno, ask onlyits chat history is not in a format this package readsno (manifests checked only)
Clineyesno, ask onlynoneno
Other MCP clientsyesno, ask only0gm-memory save FILE by hand, for a supported transcript formatno

Sessions saved from one agent can be asked about from any other agent on the same key.

Quick start

You need uv (or pipx) and an API key from pc.0g.ai for a wallet that will hold only this project's memory. uv fetches Python 3.10 or later if needed.

uv tool install 0gm-memory              # or: pipx install 0gm-memory
export ZGM_MEMORY_KEY=<key from pc.0g.ai>
0gm-memory status                        # free, no network: shows the wallet and an empty buffer

Or run it without installing: uvx 0gm-memory status.

Connect your agent. For Claude Code:

claude mcp add 0gm-memory -e ZGM_MEMORY_KEY="$ZGM_MEMORY_KEY" -- 0gm-memory serve

and merge integrations/claude-code/hooks/hooks.json into .claude/settings.json so sessions are saved. Already have history? 0gm-memory save --claude (or --codex, --opencode) saves this folder's past sessions. Then ask your agent about something you decided earlier.

Install per agent

Each block assumes the command is installed as in the quick start. To run it without installing, use uvx 0gm-memory in place of 0gm-memory (the save hooks are faster with the installed command).

Claude Code: MCP server and save hooks
claude mcp add 0gm-memory -e ZGM_MEMORY_KEY="$ZGM_MEMORY_KEY" -- 0gm-memory serve

Merge hooks/hooks.json into .claude/settings.json. To keep the key per project, put { "env": { "ZGM_MEMORY_KEY": "<key>" } } in .claude/settings.local.json (not committed).

Or install the plugin, which sets up both in one go: /plugin marketplace add 0gfoundation/0gm-memory, then /plugin install 0gm-memory@0gm-memory. Details, timeouts and safety nets: integrations/claude-code.

Codex CLI: MCP server and save hooks
codex mcp add 0gm-memory --env ZGM_MEMORY_KEY="$ZGM_MEMORY_KEY" -- 0gm-memory serve

Merge hooks.json into ~/.codex/hooks.json and trust the hooks: Codex skips untrusted hooks silently, and codex exec never asks. How to trust them, and the env_vars list for config.toml: integrations/codex.

OpenCode: MCP server and a save plugin

In the project's opencode.json:

{ "mcp": { "servers": { "0gm-memory": { "type": "local", "command": ["0gm-memory", "serve"],
  "environment": { "ZGM_MEMORY_KEY": "{env:ZGM_MEMORY_KEY}" }, "timeout": { "execution": 300000 } } } } }

Copy plugins/0gm-memory.js to .opencode/plugins/ to save sessions, and run 0gm-memory save --opencode once for past ones. Details: integrations/opencode.

Hermes Agent: memory provider
hermes plugins install 0gfoundation/0gm-memory/integrations/hermes
hermes memory setup     # choose 0gm-memory, paste the key

The provider imports the 0gm-memory package, which Hermes installs from PyPI as a declared dependency. See integrations/hermes.

Cursor: ask only

In .cursor/mcp.json:

{ "mcpServers": { "0gm-memory": { "command": "0gm-memory", "args": ["serve"],
  "env": { "ZGM_MEMORY_KEY": "${env:ZGM_MEMORY_KEY}" } } } }

Or use the one-click Add to Cursor link and the Cursor plugin. Details: integrations/cursor.

Cline: ask only

In cline_mcp_settings.json (or ask Cline to install this repository; it follows llms-install.md):

{ "mcpServers": { "0gm-memory": { "command": "0gm-memory", "args": ["serve"],
  "env": { "ZGM_MEMORY_KEY": "<key>" }, "timeout": 300 } } }
Any other MCP client, Docker
{ "mcpServers": { "0gm-memory": { "command": "0gm-memory", "args": ["serve"],
  "env": { "ZGM_MEMORY_KEY": "<key>" } } } }

"command": "uvx", "args": ["0gm-memory", "serve"] needs no install step. Docker: integrations/docker.

How it works

flowchart LR
    A[Session ends<br/>or compacts] -->|hook or plugin| B[Read transcript]
    B --> C[Drop memory lookups,<br/>redact secrets]
    C --> D[(Local buffer)]
    D -->|over ~70K tokens| E[One multi-turn call<br/>to the 0G router]
    E --> F[(0GM-CMSA memory)]
    G[ask_memory] --> H[0GM-2.0<br/>quotes past messages]
    F -.-> H
    H --> I[Dates checked<br/>against local index]
    I --> J[Dated verbatim quotes,<br/>plus buffer matches]

0GM-2.0 writes memory when its server compacts a conversation, which it does by itself once a plain multi-turn call passes 65,536 tokens. So the package buffers sessions locally and sends them as one call at about 70K estimated tokens, and the server archives them into the wallet. Each message carries its session date, and every quote that comes back is checked against a local index of what was saved, so a wrong date is corrected and marked. Until a session is saved, ask_memory also searches the local buffer and lists those matches separately. Calls to the memory tools, and answers that only restate memory, are never saved back, so old answers do not echo into new ones.

Tools and commands

MCP toolWhat it doesCost and time
ask_memory(query)Returns verbatim quotes of the relevant past messages with their session dates, or NO RELEVANT MESSAGES. It does not answer; the agent reasons over the quotesA few cents a call (about $0.07 measured on 0GM-2.0). Seconds on a small wallet, up to about 100 s on one of millions of tokens
save_session(transcript_path)Redacts and buffers a transcript; saves to the wallet once the buffer is big enough. Re-saving adds only new messagesFree while buffering; see Cost
memory_status()What is buffered and saved, memories used of 64, last save, spendFree, no network
CommandWhat it does
0gm-memory serveRun the MCP server on stdio
0gm-memory ask "question"The same as ask_memory
0gm-memory save FILE...Save transcripts (Claude Code, Codex, an OpenCode export, or JSONL of role and content)
0gm-memory save --claude / --codex / --opencodeSave this folder's past sessions from that agent. --since YYYY-MM-DD and --session ID narrow it; messages already saved are skipped
0gm-memory status [--json]Buffer, saves, spend and the hook log path. No network
0gm-memory hookFor agent hooks: reads the hook JSON and saves in the background
0gm-memory forget --local / --walletDelete this machine's buffer and logs, or every memory in the wallet (asks for the wallet id)

Exit codes: 0 ok, 1 bad input, 2 configuration (for example no key), 3 the router call failed (save keeps the buffer and sends it again next time). With no network a call fails at once; rate limits and server errors are retried with backoff.

Recommended project rule

Agents call ask_memory when you mention past work, but not by themselves before a routine change such as "move the port back to 8080". To make them check first, add this line to the project's CLAUDE.md or AGENTS.md:

Before changing configuration, dependencies or an earlier decision, call ask_memory to check for a past decision; if it conflicts, stop and ask the user before changing it.

Configuration

VariableDefaultWhat it does
ZGM_MEMORY_KEYAPI key for this project's wallet
ZGM_MEMORY_KEY_SERVICEmacOS: name of a keychain item holding the key
ZG_API_KEYUsed if nothing above is set
ZGM_MEMORY_DISABLE1 turns everything off: nothing is read or sent
ZGM_MEMORY_HOMEplatform data folderLocal state: ~/Library/Application Support/0gm-memory, ~/.local/share/0gm-memory or %LOCALAPPDATA%\0gm-memory
ZGM_MEMORY_FLUSH_TOKENS70000Estimated tokens per save. Larger saves mean fewer, bigger saves
ZGM_MEMORY_ASK_TIMEOUT, ZGM_MEMORY_SAVE_TIMEOUT300, 600Seconds per call
ZGM_MEMORY_MAX_RETRIES4Retries on 429 and 5xx, with backoff
ZGM_MEMORY_TOOL_RESULT_CHARS1500How much of each tool result is kept
ZGM_MEMORY_NO_ENTROPY_REDACTION1 keeps random-looking strings that match no known secret format
OPENCODE_DB$XDG_DATA_HOME/opencode/opencode.dbOpenCode's database, read by save --opencode and the plugin
ZGM_MEMORY_OPENCODE_BINopencodeOpenCode command, used only if its database cannot be read
ZGM_MEMORY_BASE_URLhttps://router-api.0g.ai/v1Router
ZGM_MEMORY_MODEL0gm-2.0Model id; the default is one constant (DEFAULT_MODEL in src/zgm_memory/config.py)

The key is read in this order: ZGM_MEMORY_KEY, ZGM_MEMORY_KEY_SERVICE, a key entered in plugin settings, ZG_API_KEY. It is only sent in the Authorization header and never logged; local state is filed under a one-way hash of it.

Upgrading from 0gm-msa-memory. The package was renamed. The old names keep working for now:

  • Every ZGM_MEMORY_* variable falls back to its old name MSA_MEMORY_* (and ZGM_MEMORY_KEY_SERVICE to MSA_KEY_SERVICE); when both are set, the new name wins.
  • On first run, local state in the old 0gm-msa-memory data folder is copied to the new 0gm-memory folder. The old folder is left untouched; delete it once you are happy.
  • A .msamemoryignore file is still read; .0gmmemoryignore wins when both are present.
  • 0gm-msa-memory still runs as a deprecated alias of the 0gm-memory command.

Results

Measured on test wallets. Small samples and single runs, so read them as indications, not rankings. Methods and raw results: FINDINGS and eval/beam/ in the demos repository.

BEAM at 10M tokens (Mem0's long-conversation benchmark): 40 questions, one run, questions answered correctly.

xychart-beta
    title "BEAM-10M: correct answers out of 40 (one run)"
    x-axis ["0GM-2.0 (preview)", "This plug-in", "GPT-5.1 + RAG", "Mem0 + GPT-5", "Perfect context"]
    y-axis "Correct (of 40)" 0 --> 40
    bar [22, 22, 21, 19, 34]
SetupCorrect of 40
0GM-2.0 (preview), a plain question to the wallet22
This plug-in (quoting lookup, v2)22
GPT-5.1 with embedding retrieval (RAG)21
Mem0 with GPT-519
Ceiling: the right evidence placed in the prompt34

The first four are within noise of each other on 40 questions, and the gap to the ceiling shows that finding the evidence is still the hard part. What this package offers is not a higher score but nothing to host, and answers that come back as dated quotes.

Real agent sessions (24 Nov 2026, invented project, test wallet):

CheckResult
Fresh Claude Code session, memory tools only, three questions about past decisions3 of 3 answered with verbatim, correctly dated quotes (34 s and $0.022 for the lookup)
Fresh Codex, OpenCode and Hermes sessionsEach recalled decisions from earlier sessions, from the wallet, with dates
Synthetic history spanning 17 Sep to 24 NovQuotes carried the right session dates
Fake keys, passwords and .env contents planted in sessions0 found on disk or in any request
TimeA lookup took 6 to 45 s on a small wallet; a save took 18 to 31 s

Privacy and data

  • What is sent, after redaction: user and assistant message text, tool calls (cut to 400 characters), tool results (cut to 1,500) and your ask_memory questions. They go to 0G's router (router-api.0g.ai) and are stored in your wallet. Nothing is sent while sessions are only buffered.

  • What is never sent: thinking blocks, subagent side chains, system reminders, calls to the memory tools, and the output of tool calls that touched .env, key or credential files.

  • Redaction runs on your machine before anything is buffered, and again on the exact request body: API keys and tokens in known formats, private keys, secret-looking assignments, passwords said in a sentence and random-looking strings. It is a strong filter, not a guarantee; see SECURITY.md.

  • Opt out, or add rules, per project with a .0gmmemoryignore file in the project or any parent folder:

    *                # save nothing from this project
    Acme Corp        # or: redact this string everywhere
    re:CUST-\d{6}    # and this pattern
    path:legal/**    # and drop tool output for these files
    

Retention and how to wipe everything: PRIVACY.md.

Cost

Measured on 4 Dec 2026 with 0GM-2.0: a save (about 70K tokens of sessions) cost $0.28, and a question $0.07.

A typical weekSavesQuestionsAbout
Busy: 1M tokens of sessions1430$6
Light: 300K tokens of sessions410$2

0GM-2.0 pricing on 0G Private Computer: memory writes are $3.00 per million newly written tokens, including the first 30 days of storage; stored memory renews at $3.00 per million tokens per 30 days, and using it resets the 30 days. Unused memory expires after 30 days. Check pc.0g.ai for current prices. memory_status shows what has been spent from its state folder (Hermes keeps its own folder, so it reports its own share).

Limits

  • A save needs about 70K tokens. The most recent sessions wait in the local buffer until there is enough; ask_memory still finds them there.
  • Up to 120M tokens of memory per wallet. If a save is ever refused with 429 "Automatic session quota reached", raise ZGM_MEMORY_FLUSH_TOKENS so each save carries more, and open an issue.
  • Memories expire after 30 days without use, under 0GM-2.0's memory pricing. See PRIVACY.md.
  • Slow on big wallets. Seconds on a small wallet; 55 to 101 s per lookup on wallets of 1M to 12M tokens.
  • Recall is not complete. Ask one specific question per call: a lookup that bundled five questions missed a fact that a specific question then found.
  • No per-fact delete. You can wipe a whole wallet, not one session.
  • One wallet per project. Everything in a wallet can turn up in any answer (see the FAQ).
  • Backfills cost per save. save --claude on a long history saves once per ~70K tokens.

FAQ

What is a wallet? The account that holds the memory. You create it with an API key from pc.0g.ai and pay for use with credit on that key; nothing else is needed.

Why one wallet per project? With two long conversations in one wallet, 7 of 20 answers about the first brought in material from the second; loaded one per wallet, the same 40 questions scored 0.664 against 0.593. The package keeps a separate buffer per key, but only separate wallets keep memories apart.

Is this RAG? No index is built: the model reads its own memory. On the benchmark above it scored about the same as embedding retrieval. The trade is different: nothing to host, and evidence comes back as dated quotes.

What happens if a save fails? Nothing is lost: the buffer is kept and sent again with the next save. save exits with 3, and memory_status counts the failure.

Can I delete memories? 0gm-memory forget --wallet deletes every memory in the wallet (it asks you to confirm with the wallet id). forget --local deletes this machine's buffer and logs.

Does it work offline? Buffering does; saving and asking need the router.

Will it slow my agent down? The save hooks return in about 0.1 s and do the work in the background. A lookup takes seconds, and runs only when the agent asks.

Contributing

From source:

git clone https://github.com/0gfoundation/0gm-memory && cd 0gm-memory
uv run --extra dev pytest          # unit tests, no network
uv run --extra dev ruff check .
ZGM_MEMORY_KEY=... uv run python scripts/live_e2e.py all --out e2e-results   # live, costs under $0.50

Issues and pull requests are welcome; see CONTRIBUTING.md and the Code of Conduct. Security reports: SECURITY.md.

Licence

MIT

PYPI
0gm-memory
Install Command
pip install 0gm-memory
Runtime: uvx