Installing shmem (agent install guide)
You're reading this because a user pasted this URL to an AI agent and asked it to install shmem for them. This page is structured for you, the agent, to act on without follow-up. Humans installing manually should use Get Started instead.
Terms: installing shmem constitutes acceptance of the Self-Hosted Software Terms of Use. Since you're installing on the user's behalf, surface that link so they're aware.
TL;DR
With a shell, run one command:
curl -fsSL https://shmem.secondmoment.ai/docs/install.sh | sh
It installs shmem and shmem-mcp, then runs shmem install, which wires every agent it finds on the machine, imports their past sessions, and picks an LLM to answer with. It's safe to re-run, and asks at most two things, on a terminal (an agent or script, or shmem install --yes, gets a suggestion instead): whether Claude Code may run shmem's memory tools without review (see Claude Code), and, if you already use shmem in the Claude app, whether to sign this machine in to the same account. Then:
- Relay its output to the user. It says what was wired, what was imported, and how questions will be answered.
- Verify: run
shmem ask "what was I working on last week?"and relay the answer.
Without a shell (a chat-only client), give the user the command above to run in a terminal.
Don't ask the user for an API key in chat. shmem install finds keys already in the environment; if it finds no LLM, it prints a note saying how to add one, and you relay that.
What shmem is, in two sentences
shmem is a local-first long-term memory layer for AI agents. Every conversation you have with the user gets captured into a shared SQLite DB at ~/.shmem/db/; any agent on the user's machine can query it with shmem ask / shmem query or via the MCP tools ask_memory / recall_memory / add_memory.
The pitch is cross-agent context — what the user discussed with Claude Code yesterday is recallable from Codex today. Your job during install is to make that immediate.
What shmem install does
Each step is idempotent; re-running picks up a newly installed agent or a newly added key.
-
Creates the memory store at
~/.shmem(or$SHMEM_ROOT), records the user's author stamp, and writes default credential filters. -
Wires every agent it detects — see Per-agent wiring. New agent sessions capture automatically; running sessions pick it up when restarted.
-
Imports past agent sessions from Claude Code, Codex, Cursor, Cline, and OpenCode, with a progress line per source. Imports are local parse-and-insert: no network, no LLM calls. A ChatGPT export or GitHub history it finds is only pointed at (
shmem import --from chatgpt/--from github), since importing those is the user's choice. -
Finds an LLM for answering questions, in this order:
- an existing
SHMEM_QA_PROVIDERsetting - an API key in the environment:
ANTHROPIC_API_KEY,OPENAI_API_KEY,GEMINI_API_KEY,OPENROUTER_API_KEY - Claude Code's own Bedrock or Vertex settings (
CLAUDE_CODE_USE_BEDROCK/CLAUDE_CODE_USE_VERTEX) - a signed-in Claude Code or Codex CLI, used headlessly (
claude -p/codex exec). Install says so: each answer uses the user's plan and takes a few seconds, and an API key is faster. - only when none of those exists and the machine doesn't sync with a hosted server: a running Ollama with a model pulled. Install warns that local answers are slower and noticeably worse; relay that line.
With none of these, install prints a note saying how to add a key, an agent sign-in, or a local model, and still exits 0: capture works without an LLM, only answers wait.
- an existing
Flags, for when you need them:
shmem install --for codex-cli # wire one agent only: claude-code | codex-cli | antigravity | opencode
shmem install --provider anthropic # skip LLM detection
shmem install --no-import # skip importing past sessions
shmem install --allow-memory-tools # Claude Code: let auto mode run the memory tools (=no removes the rules)
Install honors SHMEM_ROOT for its data, CLAUDE_CONFIG_DIR for Claude Code's config directory, CODEX_HOME for Codex's, and XDG_CONFIG_HOME for OpenCode's. A custom SHMEM_ROOT is written into each agent's hooks and memory tools as a default, so agents use it without the variable set in their environment. A session that sets its own SHMEM_ROOT overrides it for both.
Already installed?
Run the one-liner anyway, or just shmem install — it re-wires idempotently and only imports sessions it hasn't seen. To check state without changing anything: shmem status --json reports installed, configured_hosts, qa_provider, and fact_count.
Answering without an LLM
shmem ask (and the ask_memory MCP tool) always returns a synthesized answer or a reason, never raw facts. With no local LLM, ask uses the hosted server's QA when a remote is configured; otherwise it fails with the same note install printed. Relay that note to the user rather than working around it.
Per-agent wiring
Claude Code
Merges UserPromptSubmit / PostToolUse / Stop hooks into ~/.claude/settings.json (or $CLAUDE_CONFIG_DIR/settings.json), each tagged --caller-agent claude-code, registers the shmem-mcp server at user scope (through claude mcp add-json --scope user when claude is on PATH, otherwise in ~/.claude.json), and adds a short memory section to the user-level CLAUDE.md so Claude reaches for ask_memory / recall_memory. A shmem server entry that doesn't run shmem-mcp (a hosted URL, say) is left as it is.
Auto mode and the allow rule. In Claude Code's auto permission mode, a safety classifier reviews every tool call that no permissions.allow rule covers. It judges calls one at a time, so it can refuse one memory save among several alike, even one the user asked for. Install asks once, on a terminal, whether to allow shmem's memory tools. A yes adds permissions.allow rules to ~/.claude/settings.json for reading and adding memory (mcp__shmem__ask_memory, recall_memory, add_memory and the other read tools, and Bash(shmem ask:*), Bash(shmem query:*), Bash(shmem add:*) for the shell fallback). Deleting memory and the sharing, group and project tools stay under review, since they remove facts or publish them to other people. shmem records the rules it wrote: shmem install --allow-memory-tools=no removes those and no others, and a rule you remove yourself stays removed.
Run by an agent, install can't ask, and prints a note instead. Relay it: ask the user whether to allow the memory tools, and on a yes run shmem install --allow-memory-tools. To allow them by hand, add "mcp__shmem" (every tool of the server) or the individual tool names to permissions.allow.
Codex CLI
Writes the same three hooks to ~/.codex/hooks.json (or $CODEX_HOME/hooks.json), sets [features] hooks = true in config.toml (Codex only runs hooks with this flag), registers shmem-mcp under [mcp_servers.shmem] there, and appends the memory section to AGENTS.md.
Antigravity
Covers the agy CLI and the Antigravity app and IDE, which share ~/.gemini/config/. Adds a shmem entry to ~/.gemini/config/hooks.json with one Stop hook. Antigravity has no prompt-submit or after-agent event, so at the end of each turn the hook reads the conversation transcript Antigravity points it at and saves both the prompt and the reply. Install also registers shmem-mcp under mcpServers in ~/.gemini/config/mcp_config.json and appends the memory section to ~/.gemini/AGENTS.md, a global rules file every Antigravity surface loads. --for agy works as an alias.
OpenCode
Registers the shmem-mcp server and the shmem-opencode capture plugin in ~/.config/opencode/opencode.json. OpenCode installs the plugin from npm on next startup.
Writes the memory primer to ~/.config/opencode/shmem.md and lists it under instructions in the same file, so OpenCode tells the agent when to call ask_memory (without it, the plugin would capture every turn but the agent would have no nudge to read memory back). shmem rewrites that file on every install, so put your own instructions elsewhere. It is an instructions entry rather than a section in a global AGENTS.md because OpenCode 1.x stops reading ~/.claude/CLAUDE.md once a global AGENTS.md exists.
Cowork
Cowork sessions run in a sandboxed ARM64 Linux environment. The working architecture uses the shmem CLI binary directly — not an MCP server daemon.
-
Install the shmem binary in the sandbox:
# Inside a Cowork session ARCH=linux_arm64 VERSION=$(curl -s https://api.github.com/repos/second-moment-ai/homebrew-tap/releases/latest | grep '"tag_name"' | sed 's/.*"tag_name"[[:space:]]*:[[:space:]]*"v\([^"]*\)".*/\1/') curl -fsSL "https://github.com/second-moment-ai/homebrew-tap/releases/download/v${VERSION}/shmem_${VERSION}_${ARCH}.tar.gz" \ | tar -xz -C ~/.local/bin shmem -
~/.shmemis FUSE-mounted — Cowork bridges~/.shmemto the Mac's real~/.shmem/. The Mac-side shmem process handles remote sync; the sandbox does not push directly. -
Set caller identity per invocation so sandbox writes are attributable:
export SHMEM_CALLER_USER=alice@cowork-sandbox export SHMEM_CALLER_AGENT=cowork shmem ask "what were we working on?" -
Hooks are not wired — auto-capture does not work in the Cowork sandbox (hook isolation). Memory operations are explicit CLI calls (
shmem ask,shmem add,shmem query).
Known limitation: shmem push fails from the sandbox because FUSE cannot service SQLite's schema-init transaction (disk I/O error 2570). This is benign — the Mac side handles the push.
Cursor
No automated wiring yet. Tell the user: "Cursor doesn't have a public hooks API I can configure automatically. To wire shmem in, open Cursor Settings → MCP and add a new server with this command: shmem-mcp. After that, Cursor's agent will be able to call ask_memory / recall_memory / add_memory." (shmem install still imports past Cursor chats.)
nanoclaw / OpenClaw / other self-hosted agent harnesses
These are container-based. Add shmem-mcp to the agent group's MCP config — specifics depend on the harness, so ask the user to point you at their fork's structure.
There are two topologies. Prefer the second.
A. shmem inside the container. Install the matching Linux release in the container image (do not mount a macOS host binary in — it will fail with exec format error), and mount ~/.shmem/db/ read-write so the agent can read and write.
B. shmem on the host, reached over HTTP. Run one shmem-mcp --transport streamable-http on the host and point every container at it. No binary in the image, no mount, no architecture matching, and one long-running server amortizes the per-process index build instead of paying it every invocation.
If you take B, three things bite in practice:
- Use
host.docker.internal:8705, not the Docker bridge IP. Harnesses increasingly reject plain-HTTP MCP URLs except forlocalhostandhost.docker.internal, and a storedhttp://172.17.0.1:8705/mcpgets dropped at container spawn — usually with the MCP server silently removed rather than an error the user sees. - Add it to
NO_PROXY. Any proxy that injects anAuthorizationheader on outbound requests will overwrite shmem's bearer token, producing a401 invalid tokenthat looks exactly like a bad key. - Both failures look identical to the agent — "no memory tools" or an empty result. Verify from inside the container before believing either:
curl -sS -X POST http://host.docker.internal:8705/mcp \
-H "Authorization: Bearer <your token from keys.json>" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"probe","version":"1"}}}'
A 200 with an initialize result means the path is good. 401 means something is rewriting the header — retry with --noproxy '*' to confirm it's the proxy.
Keep the container's shmem-mcp and the host's shmem on the same release.
Anything else
shmem install --for <host> names the hosts it can wire and errors for others. If the host speaks MCP, register shmem-mcp (stdio) as a server in its config. If it doesn't, tell the user shmem doesn't auto-wire it yet and offer to file an integration request.
Installing the binary another way
The install script detects OS and architecture, downloads the latest release from the public homebrew-tap repo, and installs to ~/.local/bin when that's on $PATH (otherwise /usr/local/bin, with sudo). Overrides: SHMEM_INSTALL_DIR=..., SHMEM_NO_SUDO=1, SHMEM_VERSION=vX.Y.Z, and SHMEM_NO_SETUP=1 to install the binaries without running shmem install.
Manual tarball (any platform, including Windows): download shmem_<version>_<os>_<arch>.tar.gz from https://github.com/second-moment-ai/homebrew-tap/releases (darwin_amd64, darwin_arm64, linux_amd64, linux_arm64, windows_amd64), put shmem and shmem-mcp on $PATH, and run shmem install.
Stripped containers sometimes lack curl/wget or tar; install them first (apt-get install -y curl, apk add curl, dnf install -y curl).
Signing in: only when the user asks
Memory stays on this machine until the user signs in to a shmem account; then it syncs with the account, their other machines, and the Claude app. Offer sign-in only when the user asks for it or agrees to it. Install's output ends by mentioning shmem login; relay that, and don't run it unprompted. The exception is when install says the user already has an account (it saw a shmem connector in the Claude app): then ask whether to sign this machine in.
Use shmem's MCP login tool first. Install registers shmem's local MCP server, and its login tool runs the sign-in:
- Call
login. It starts sign-in, opens the browser where there is one, and waits up to 45 seconds. Usually the user finishes in time and it returns the result lines (✓ signed in as …, what uploaded or arrived): relay them. - If it returns the link instead (the user hasn't finished, or no browser opened), show the user the link, then call
loginagain to keep waiting. - Over SSH or with no browser, the first call returns the link at once. Ask the user to open it on any computer and paste back the code the page shows, then call
loginwithcodeset to it. - If the tool returns a question (switching to another account), put it to the user and call again with
switch_accountset to their answer:truefor yes,falsefor no. - On a first sign-in to an account, the result lists this machine's projects and asks which sync with the account. None sync until the user answers: put the list and the question to them, and don't pick for them. Then call
loginwithsyncset toallornone, orsync_projectsset to the projects they chose. The others stay on this machine only, now and later.
The upload and catch-up keep running in the background after the tool returns, so the agent session can end.
Shell fallback. If the MCP tools aren't available yet (an install that just registered the server may need the agent session restarted before they appear), run shmem login in the background, or with the longest timeout your shell tool allows: it waits up to 10 minutes for the browser. Relay the link it prints right away, then relay its result lines when it finishes. With no terminal to ask on, a first sign-in syncs none of the machine's projects and lists them. Ask the user which should sync, then run shmem login --sync-project <name> (repeatable), or shmem login --sync all; the signed-in machine takes the answer without signing in again. Over SSH, shmem login reads the code from the terminal, which a backgrounded command can't do; ask the user to run shmem login in their own terminal, or restart the session so the login tool is available.
The new-machine recipe. When the user says something like "set up shmem, I already use it on my laptop": run the install one-liner, relay its output, then sign in with the login tool (or the fallback) as above. The user already asked, so don't ask again. Sign-in downloads the last 30 days right away and older memories in the background. Then verify with ask_memory (or shmem ask "what was I working on last week?") and relay the answer: it should know what they did on the other machine.
Other servers: the login tool signs in only to this machine's own server. For a self-hosted or company server, ask the user to run shmem login --remote <url> in their own terminal. If the server has no sign-in, its operator issues a token: shmem login --remote <url> --token <token>, which the user runs themselves. Don't ask for tokens in chat.
Troubleshooting
shmem: command not found after install
The binary went somewhere not on $PATH — the script says so and prints the export PATH=... line to add. Setup still ran; hooks use the absolute path. If neither ~/.local/bin/shmem nor /usr/local/bin/shmem exists, retry with tracing: curl -fsSL https://shmem.secondmoment.ai/docs/install.sh | sh -x, and look for the first non-zero exit.
An agent wasn't detected
Install detects an agent by its config directory or its binary on $PATH. If the agent was installed after shmem, re-run shmem install. To force one: shmem install --for <host>.
Hooks not firing (Cowork specifically)
Cowork isolates ~/.claude/settings.json per session, so the hooks shmem writes don't get picked up. Tell the user to use the MCP tools (ask_memory / add_memory) explicitly instead of expecting auto-capture.
~/.codex/config.toml got reformatted
Codex's hook install round-trips config.toml through a TOML library, which strips comments and may reorder sections. Values are preserved. If the user had hand-written comments they care about, tell them they're gone and suggest their dotfiles backups.
Captures show the wrong caller_agent
Re-run shmem install, which bakes --caller-agent <host> into each hook command, and remove any SHMEM_CALLER_AGENT= line from ~/.shmem/.env: the label belongs to each tool, not the machine.
Anything else
Check ~/.shmem/.env for the config that's loaded and shmem admin status for what shmem thinks its state is. If you can't recover, tell the user what you tried, what you saw, and the shmem admin status output, and stop. Don't pretend it worked.
What this guide does NOT cover
- Hosted accounts and the Claude app. See Hosted and The Claude app.
- Per-repo projects.
shmem initinside a repo gives it its own project tag (it writes.shmem/projectand nothing else); it isn't part of getting started. See Projects. - Removing shmem (
rm -rf ~/.local/bin/shmem ~/.local/bin/shmem-mcp ~/.shmem/). If the user changes their mind, point them at this; don't auto-uninstall.