CLI

All commands below are invoked as shmem <subcommand> unless noted. Run any command with -h for inline help.

shmem install

Set up shmem on this machine in one non-interactive step: create the memory store, wire every detected agent (Claude Code, Codex, Antigravity, OpenCode), import their past sessions (Claude Code, Codex, Cursor, Cline, OpenCode), and find an LLM to answer with. Never prompts; safe to re-run. The install script runs it for you.

shmem install
Flag What it does
--for <host> Wire only this agent: claude-code, codex-cli, antigravity, or opencode. Cursor, Cowork, nanoclaw and OpenClaw need manual wiring; the error links to the steps.
--provider <name> Skip LLM detection and use this provider (anthropic, openai, gemini, openrouter, ollama, claude-cli, codex-cli, mock).
--no-import Skip importing past sessions.

LLM detection order: an existing SHMEM_QA_PROVIDER; an API key in the environment (Anthropic, OpenAI, Gemini, OpenRouter); Claude Code's Bedrock or Vertex settings (CLAUDE_CODE_USE_BEDROCK / CLAUDE_CODE_USE_VERTEX); a signed-in Claude Code or Codex CLI, used headlessly (claude-cli / codex-cli); and only when none of those exists and no hosted remote is configured, a running Ollama with a model pulled, with a warning that local answers are slower and weaker. The choice is written to ~/.shmem/.env. With none, install prints how to add one and exits 0 — capture works without an LLM.

Agent-CLI providers inherit the parent command's network restrictions. When CODEX_SANDBOX_NETWORK_DISABLED=1, install warns that they may not answer in that Codex command sandbox. Calls still run, because Codex also sets the marker for allowlisted sandboxes that do reach the network, and a failure that looks like a cut-off network gets this explanation. Run shmem ask from a regular terminal outside the session, or configure an API provider in an environment with network access; adding a key does not bypass the sandbox. Merely running inside an agent session does not imply that networking is disabled.

Agent config locations honor CLAUDE_CONFIG_DIR (Claude Code), CODEX_HOME (Codex), and XDG_CONFIG_HOME (OpenCode); the data root honors SHMEM_ROOT.

shmem init

Make the current directory a project: writes .shmem/project, so memories captured anywhere under it are tagged with that project and shmem ask --here scopes to it. Not needed to get started — shmem install already captures every session.

cd your-project
shmem init              # project named after the directory
shmem init my-app       # or name it

It changes nothing else in the repo; hooks, the memory note and the MCP server are per-user, from shmem install, which init runs first on a machine where shmem isn't set up. Commit .shmem/project so teammates' sessions in the repo share the project.

shmem login / shmem logout

Sign this machine in to your shmem account, so its memory syncs with the account and every other machine signed in to it.

shmem login                                       # the server this machine syncs with, else SHMEM_LOGIN_SERVER, else hosted
shmem login --remote https://shmem.example.com    # another server
shmem login --no-browser                          # print a link to open anywhere, then paste the code it shows
shmem login --remote https://shmem.example.com/mcp --token sk-...   # operator-issued token, no browser
shmem logout
Flag What it does
--remote <url> Sign in to this server instead. A URL without /mcp resolves to the address the server publishes for itself.
--no-browser Don't open a browser: print a link to open on any computer, then read the sign-in code its page shows. Automatic over SSH (SSH_CONNECTION set) and on Linux with no display.
--switch-account Sign in as a different account than this machine's, without asking.
--switch-server Move this machine to a different server than the one it syncs with, without asking.
--token <token> Use a token from the server's operator (its keys.json) instead of signing in.
--verbose Show the sync statistics behind the result lines.

shmem login opens your browser to sign in with the server's identity provider, and the browser hands the result back to shmem on a local loopback port. The machine is then signed in, saved as the default remote in ~/.shmem/remotes.json: it presents short-lived access tokens and renews them with the provider's refresh token as it goes. The output is a few result lines: who you're signed in as, how many memories uploaded from this machine (on the first sign-in to an account), what arrived from your other machines, and where else to use the account.

Which projects sync. The first time a machine syncs with an account, login lists the machine's projects with their memory counts and asks which sync: all of them, none, or the ones you pick. Memory saved outside a project is the default project, and past agent sessions shmem install imported count too. Enter means none.

  • A project that syncs uploads its memory and keeps syncing.
  • One that doesn't is local-only on this machine: its memory stays here, still searchable, and nothing in it uploads, now or later.
  • Projects you start using after login sync.

shmem admin project list shows which is which, and shmem admin project sync <name> syncs a local-only project later. Writes still queued from a previous account or server aren't sent to the new account unless their project syncs. Signing back in to the account this machine synced as before signing out doesn't ask again. With no terminal to ask on (an agent or a script running login), none sync until someone chooses. Until then, shmem status and other commands say the choice is still to make, agents are reminded to ask, and running shmem login again on the signed-in machine asks it. --sync all, --sync none, or --sync-project <name> (repeatable) answers for scripts. Any line about access (such as an invite-only notice with a request-access link) or about the Claude app connector comes from the server, so another server shows its own or none. While a session works, running shmem login again prints the account, server and last sync instead of signing in again.

Which server. With no --remote, login uses the server this machine already syncs with; on a machine that has never signed in, SHMEM_LOGIN_SERVER if set; otherwise hosted (https://shmem.secondmoment.ai/mcp). Signing in to a different server than the one this machine syncs with, or as a different account, asks first, since it moves syncing there; --switch-server and --switch-account answer yes. That account's first sync then asks which projects sync, as above.

New machines get everything. The first sync downloads the last 30 days, so answers work within seconds, then the rest of the account's history in the background; shmem status shows older memories: downloading until it's done.

Without a browser on this machine (SSH, headless), sign-in uses the server's callback page: open the printed link on any computer, sign in, and paste the code the page shows. The code works only on the machine that started the sign-in, once, within 10 minutes; the PKCE verifier never leaves the machine. A server without the callback page can't sign in a machine no browser can reach; sign in elsewhere, or use --token.

In Claude Code, a signed-in machine turns off a claude.ai shmem connector (any connector whose name contains shmem) by adding a permissions deny rule for its tools, such as mcp__claude_ai_shmem__*, to ~/.claude/settings.json: local shmem already covers the same account. shmem logout removes the rule. See The Claude app.

The machine stays signed in until shmem logout, or until the provider ends the session: it expires, it is revoked, or the account is deactivated. Then shmem says signed out of <server> (in shmem status, after commands that would have synced, and once an hour to your agent through the prompt hook); memory keeps saving locally and syncs after the next shmem login. A server that refuses this machine's credentials is reported the same way.

Sign-in needs a server with OIDC configured (SHMEM_OAUTH_ISSUER), reached over https (plain http only on a loopback host); the identity provider's endpoints must be https too. For a server without it, --token uses a token from its keys.json.

shmem logout ends this machine's session at the identity provider (through the server, or by revoking the token, whichever the provider supports) and removes the remote. Memory already on the machine stays and keeps saving; it no longer syncs, and logout says how many recent memories hadn't uploaded yet (they upload if you sign in again as the same account). A token that wasn't issued by sign-in can't be revoked this way; the server's operator removes it from keys.json.

shmem remote add | list | remove | show | set-default | set-token

Manage remote shmem servers configured in ~/.shmem/remotes.json (file mode 0600). To connect a machine to a server, use shmem login; these commands are for inspecting remotes and for advanced setups with more than one. The first remote added becomes the default; the sync layer uses it unless an explicit <remote> argument overrides on push / pull.

shmem remote add origin https://shmem.example.com/mcp --token sk-...
shmem remote list           # marker * shows default
shmem remote show origin    # full details including token
shmem remote set-default staging
shmem remote remove origin  # promotes the next remote to default
echo "$KEY" | shmem remote set-token origin   # replace the token in place

set-token replaces a remote's token, keeping its URL and default status; it reads the token from stdin when no token argument is given, which keeps it out of the process list. Apps that mint a short-lived key per session use it to install each new key (see Embedding shmem). On a remote signed in with shmem login, it ends that session.

shmem push [remote]

Manually push local writes to a remote. Default mode drains the pending-write queue (writes that haven't yet made it because the client was offline). With --all, uploads every local fact, idempotent by dedup_key. Projects that are local-only on this machine (shmem admin project unsync) are left out unless named with --project:

shmem push                # drain queue to default
shmem push --stranded     # list own facts that never reached the queue, confirm, push (--yes skips the prompt)
shmem push --all          # full upload of facts written here (never replicas)
shmem push --all --project work  # only one project's facts (repeatable); names a local-only project to push it anyway
shmem push staging --all  # explicit remote

shmem pull [remote]

Pulls remote writes into the local DB. Default mode is delta-since-cursor, then a sweep of the projects shared with you; --all walks the entire remote dataset from time 0 (use after restoring from a backup or bootstrapping a fresh machine); it also applies every delete recorded in that walk, so it catches up on deletes made on your other machines. You rarely need it: CLI reads, a local shmem-mcp's read tools and background ticker, and the prompt hook all run the same pull automatically (see Sharing: when a machine syncs). If another sync is already running, shmem pull waits for it to finish.

shmem pull           # delta-since-cursor from default
shmem pull --all     # bootstrap a fresh machine

shmem config show

One-shot diagnostic that prints every effective shmem setting with provenance (where each value came from). Useful when answers seem off and you need to see what shmem is actually using — provider, model, API key presence, caller identity, project route, DB path, remote sync state, cursor age, reachability. Pass --json for machine-readable output.

shmem config show          # human-readable, every dimension with source
shmem config show --json   # for monitoring / dashboards

Every value line shows the source — ~/.shmem/.env, shell env, auto-detect from API key, default, or cwd .shmem/project walk-up. Provenance is the load-bearing piece: knowing the QA provider is "anthropic" isn't enough — knowing it came from auto-detect vs explicit .env is what lets you reason about config drift between machines.

shmem ignore [defaults | install]

Show and manage your .shmemignore rules. With no subcommand, syncs them with your account (when signed in) and lists the files that apply, with rule counts and where they sync. shmem's credential filters are built in and always apply after your own rules.

shmem ignore                  # sync, then show your rules and the built-in ones
shmem ignore defaults         # print the built-in credential rules
shmem ignore install --force  # replace the global file with an empty one, ready to edit

See Get Started for the file format.

See Get Started for the full walkthrough and the "Agents that span multiple directories" section for the --global flow.

Per-directory hook routing

shmem hook user-message / response / tool-use / gemini-response resolve the target project in this order on every invocation:

  1. Walk up from the cwd field in the hook's JSON payload looking for a .shmem/project marker file. A marker counts only when it is a small regular file (a symlink to one is fine) holding a single project name, with no /, \ or .. path, and, in a directory other users can write such as /tmp, one you own. Any other is passed over with a warning, and the walk goes on up.
  2. If none is found, use SHMEM_DEFAULT_PROJECT (set in ~/.shmem/.env or your shell).
  3. Then SHMEM_PROJECT (deprecated for the shmem CLI; still honored for one release with a one-shot warning. Continues to be the canonical config mechanism for shmem-mcp).
  4. Otherwise, fall back to the default project.

This means globally-installed hooks route correctly even across many directories in one session — create per-directory routing by running shmem init inside each project you want tracked separately.

Duplicate hook registrations

Claude Code merges hook configs from every settings level (~/.claude/settings.json, the project's .claude/settings.json, and .claude/settings.local.json) and runs all of them per event — so shmem hooks installed both globally and in a project would capture every fact twice. shmem dedupes this at runtime: only the most specific registration captures. When the registered commands differ, the less specific invocation detects the more specific one and exits; when they're identical, sibling invocations race for an atomic per-event claim marker (under ~/.shmem/hook-dedup/) and only the first captures. Set SHMEM_HOOK_DEDUP=off to disable — e.g. if two registrations intentionally write to different databases via env wrappers.

shmem ask

Ask a question and get a grounded answer from memory. Runs the full question-answering pipeline.

shmem ask "What auth approach did we choose?"

Needs an LLM (see shmem install). With none configured locally, ask answers through the default remote's QA when one is configured (honoring --project and --meta; --mine, --shared and --private need a local LLM), and otherwise fails with a note on how to add one.

On February 12 you chose JWT over sessions, because the API needed to be
stateless [1].

Sources
  [1] Auth decision: JWT over sessions, API must stay stateless
      Feb 12 14:10 · api · github.com/acme/api
      8f2c1a3b…

Sources

The answer cites the facts it relies on with inline markers like [1] or [2][3], numbered in order of first appearance, and the Sources block after it lists each one:

  • a short title: the fact's title metadata, else its first line, truncated;
  • when it was written, its project, and the repository it was captured in — or from <name> for a teammate's fact (one that reached you through a shared space, or, on a server, any fact another account owns);
  • its permalink on the dashboard when shmem dashboard is running for this store (http://127.0.0.1:8706/#/fact/<id>), otherwise the first characters of its fact id.

The dashboard holds your whole memory, so it answers only on 127.0.0.1/localhost and only to a browser signed in to it. shmem dashboard prints a link with a token (--open opens it); the first visit signs that browser in until the dashboard stops, so the plain address and these permalinks work in it for that run. Open the printed link again after a restart. The token is kept in ~/.shmem/dashboard-token, and scripts can send it as Authorization: Bearer <token>; to change it, delete the file and restart the dashboard. Browsers share cookies across every port on 127.0.0.1, so while you're signed in, don't open pages from other local servers you don't trust.

Parts a fact doesn't have are left out. No Sources block is printed when the answer cites nothing, as when it comes from general knowledge. --json prints the answer, question type, fact count and a citations array (n, fact_id, title, created, project, repo, from, url) instead; through a remote that predates reporting it, facts_consulted is left out. An answer from a remote server's QA reads the server's structured result, so it prints the same way; a server too old to return one has its text printed as it came.

The dashboard's Ask page (shmem dashboard) shows the same answer with each marker as a link and a Sources list under it; clicking either opens the fact in full — content, time, source, project, author, and all of its metadata. Every fact has a permalink, #/fact/<id> on the dashboard's address, which opens it on its own page and survives a reload or a new tab; the markers and sources link to it, and --json and the dashboard's /api/ask give it as each citation's url. Answers from a remote server's QA carry no permalinks: the hosted server has no fact pages.

Default scope

When you run shmem ask from inside a project directory — one with a .shmem/project marker reachable by walking up from cwd — retrieval is automatically scoped to that project. If the project has zero matches, shmem ask auto-broadens to all projects and prints (no facts in project=<X> — broadened to all projects) on stderr before answering. From a directory without a marker, ask searches every project.

This matches the way git, npm, and most other CLI tools behave: operate on the local thing unless told otherwise.

Override the auto-default with the flags below or with SHMEM_DEFAULT_PROJECT=ALL in your environment / ~/.shmem/.env.

Flags

Flag Description Default
-t, --tree Path to MemoryDB directory Active project
-n, --max-facts Max facts to retrieve 50
--now Override current time for temporal reasoning (RFC3339 or YYYY/MM/DD) —
-p, --project NAME Restrict to a specific project tag (explicit; no auto-broaden) —
--here Same as the auto-default but explicit; disables auto-broaden when empty false
--global Search every project (opt out of the auto-default current-project scope) false
--mine Restrict to facts the calling user authored (uses SHMEM_CALLER_USER) false
--shared / --private Restrict to shared-only or private-only facts mixed
--meta KEY=VALUE Only consider facts whose metadata matches, e.g. stamp_repo=github.com/acme/billing (see Metadata filters) —
--json Print the answer and its citations as JSON false

Requires an LLM provider for answer synthesis. Set SHMEM_PROVIDER (covers both roles), or SHMEM_QA_PROVIDER for synthesis alone.

shmem query

Search facts directly with multi-index keyword matching. Lower-level than ask — returns raw facts without LLM synthesis. Same auto-default and auto-broaden behavior as shmem ask.

shmem query auth jwt                              # auto-scopes to current project; broadens if empty
shmem query --global auth jwt                     # search every project explicitly
shmem query -s user -p my-project database
shmem query --since 7d "deployment"
shmem query --meta branch=dev --meta thread=t1 --meta thread=t2 "deployment"
shmem query --ids secret | shmem delete --stdin
Flag Description Default
-s, --source Filter by source type (user, llm, tool) All
-n, --limit Max results 20
-p, --project NAME Restrict to a specific project tag (explicit; no auto-broaden) —
--here Same as the auto-default but explicit; disables auto-broaden when empty false
--global Search every project (opt out of the auto-default current-project scope) false
--mine Restrict to facts the calling user authored false
--shared / --private Restrict to shared-only or private-only facts mixed
--since Only include facts after this time (RFC3339 or relative: 1h, 30m, 7d, 2w) —
--before Only include facts before this time —
--meta KEY=VALUE Only include facts whose metadata matches, e.g. stamp_branch=main (see Metadata filters) —
--full Show full fact content Truncated
--ids Output only fact IDs, one per line false

shmem add

Add a memory to the database. Usually invoked by hooks; call directly only when the user explicitly asks to remember something.

Each shmem add should store one atomic fact — a single self-contained statement carrying its own names and keywords. Retrieval is keyword-based, so a paragraph that packs several facts together buries its entities where search can't rank them. To store many facts at once, use --batch with one fact per NDJSON line rather than concatenating them into one blob.

shmem add "The deploy key is in 1Password under 'prod-deploy'"
echo "User prefers dark mode" | shmem add -s user
shmem add -s llm "Suggested using connection pooling for the DB layer"
Flag Description Default
-t, --tree Path to MemoryDB directory Active project
-s, --source Source type (user, llm, tool) user

Caller identity is stamped from SHMEM_CALLER_USER and an agent label: SHMEM_CALLER_AGENT if set, otherwise the agent running the command (claude-code under Claude Code, codex-cli under Codex, gemini-cli under Gemini CLI, pi under Pi), otherwise cli.

shmem whoami

Show the two identities shmem tracks and whether they agree.

shmem whoami
author stamp:  alice@laptop
author agent:  claude-code
account:       alice

facts owned by "alice": 12043
facts owned by another identity: 6001  (not shareable)

Exits non-zero when the two disagree, so scripts can gate on it. See Author stamp vs. account identity.

shmem delete

Delete facts by ID. Accepts IDs as arguments or from stdin.

A fact in a shared space is first retracted from every space you can write to, so its readers drop their copies on their next sync. A fact still held by a space you can only read is kept, and the space's owner has to remove it. Retraction removes the fact itself, not what readers already learned from it.

shmem delete abc123 def456
shmem query --ids secret | shmem delete --stdin
shmem delete --project my-app abc123
Flag Description Default
-p, --project Project name Current project
--stdin Read fact IDs from stdin (one per line) false

shmem import

Import existing history: agent transcripts, ChatGPT exports, GitHub, files. See shmem import.

shmem gateway serve

Capture traffic from an LLM gateway. See shmem gateway serve.

shmem admin

Status, models, projects, groups and other maintenance commands. See shmem admin.

shmem docs

Open the shmem documentation in your browser. Serves the embedded docs site on localhost.

shmem docs

Global flags

Available on all commands:

Flag Description Default
--model LLM model name Provider-specific
--ollama-url Ollama server URL http://localhost:11434
-v, --verbose Enable verbose output false
--version Print version —