CLI
Add, search and manage memory from your terminal, with a JSON mode built for AI agents and exit codes a script can branch on.
Install
npm install -g memorysync-cli
Or run it without installing, which is the easier path inside a container or a one-off script:
npx memorysync-cli help
Needs Node 18 or newer. The package has no dependencies, so there is no transitive tree to audit and nothing is compiled at install time.
Authenticate
init asks for a key, verifies it against the API before saving anything, and records a default user and project.
memorysync init
For CI or any non-interactive shell, pass the values instead. Without a terminal there is no prompt, and the command fails with the flag to add rather than hanging on stdin.
memorysync init --api-key ms_live_xxx --user alice --force
Or skip stored credentials entirely and set MEMORYSYNC_API_KEY, which takes precedence over anything on disk.
Quick start
# Store a factmemorysync add "I prefer TypeScript over JavaScript" --user alice# Search it backmemorysync search "language preference" --user alice# Recent memories, as a tablememorysync list --user alice -o table# Pipe something inecho "Ships on Fridays" | memorysync add --user alice
Commands
Every command accepts every output format, and memorysync help <command> prints its flags and examples.
| Command | What it does | Uses quota |
|---|---|---|
init | Store a credential, pick a default user and project. | — |
add | Store a fact. Reads stdin, so it composes with pipes. | add |
search | Natural-language search. | retrieval |
list | Recent memories for a user. | retrieval |
get | One memory, including ingestion state. | — |
delete | Delete memories. Previews unless you pass --yes. | — |
import | Bulk load JSON or JSONL, validated before anything is sent. | add |
export | Write memories out as json, jsonl or csv. | retrieval |
quota | Plan usage and when the cycle resets. | — |
status | Credential, API reachability and active scope. | — |
doctor | Diagnose setup problems and say what to fix. | — |
whoami | The identity and scope in use. | — |
project | List projects, or set the default for a profile. | — |
source | Inspect and control connected knowledge sources. | — |
event | Track asynchronous ingestion, including a blocking wait. | — |
config | Local configuration and profiles. | — |
mcp | Connect MemorySync MCP to your AI clients. | — |
completion | Shell completion for bash, zsh, fish and PowerShell. | — |
help | Command help. With --json, the whole tree. | — |
Use it inside an agent
Put --json (or --agent) before the command name. Every command then answers with one envelope on stdout, whether it succeeded or failed, with no colour and no spinners.
memorysync --json search "preferences" --user alice | jq '.data[].text'
{"status": "success","command": "search","duration_ms": 134,"scope": { "user": "alice", "profile": "default" },"count": 2,"data": [{ "id": "m_60632", "text": "Prefers TypeScript", "score": 0.97 }],"quota": {"metric": "retrieval_requests","used": 12,"limit": 1000,"exhausted": false}}
Results are always an array under data, for every command, so .data[] works everywhere. Failures use the same envelope with status: "error" and a non-zero exit, so one code path handles both outcomes.
memorysync help --json returns the entire command tree, so an agent can discover the surface for itself rather than being told about it in a prompt.
Exit codes
Distinct per cause, so a script can branch without parsing stderr.
| Code | Meaning | Retry? |
|---|---|---|
0 | Success. | — |
1 | Unclassified failure. | Maybe |
2 | Usage: unknown command, bad flag, missing argument. | No |
3 | Authentication: missing, wrong, expired or revoked key. | No |
4 | Plan limit reached. Nothing was stored or returned. | Not until reset |
5 | Network: unreachable, or timed out. | Yes |
6 | Not found. | No |
130 | Interrupted. | — |
memorysync add "$FACT" --user "$USER_ID"case $? in0) echo "stored" ;;3) echo "credential problem"; exit 1 ;;4) echo "out of quota - nothing was stored"; exit 1 ;;5) echo "network problem, retrying"; sleep 5 ;;esac
Output formats
Set with -o. Every command accepts all five, so a script never has to remember which command refuses which format.
text- Human-readable, with colour when the terminal supports it. The default.
table- Aligned columns, with long values truncated to keep rows on one line.
json- The raw structured result, for piping to jq.
yaml- The same data, easier to read at a glance for nested objects.
quiet- Nothing on stdout. Use the exit code.
Profiles
For more than one environment or account, without juggling exported variables in separate shells.
memorysync init --profile staging --api-key ms_live_xxx --user alicememorysync config profilesmemorysync config use-profile stagingmemorysync --profile production status
Precedence, highest first: explicit flags, environment variables, the profile, then defaults. Environment beats the profile deliberately, so a CI image cannot be steered by a config file that happens to be baked into it.
Deleting
delete previews by default and changes nothing until you pass --yes. The preview is the server's own dry run, so what it lists is exactly what a confirmed run removes.
memorysync delete m_60632 --user alice # previews, deletes nothingmemorysync delete m_60632 --user alice --yes # performs itmemorysync delete --all --user alice # previews the whole scope
Connected sources
Inspect and drive the connectors feeding memory — GitHub, Slack, Notion, Google Drive, OneDrive, Granola, Amazon S3 and crawled sites — without opening the dashboard.
memorysync source listmemorysync source status githubmemorysync source sync githubmemorysync source pause slack
Connecting a new source needs a browser round trip for OAuth, so that stays in the dashboard. A CLI that half-connected a source would be worse than one that does not try.
Shell completion
# bashmemorysync completion bash > /etc/bash_completion.d/memorysync# zshmemorysync completion zsh > "${fpath[1]}/_memorysync"# fishmemorysync completion fish > ~/.config/fish/completions/memorysync.fish# PowerShell — add to your profilememorysync completion powershell | Out-String | Invoke-Expression
Start a new shell afterwards for it to take effect.
When something is wrong
Start with doctor. It checks the credential and where it is stored, file permissions, DNS, API reachability, quota headroom, the project binding and your Node version, then prints what to fix. It exits 0 even when checks fail, because diagnosing is what it was asked to do.
memorysync doctor
| Symptom | Cause | Fix |
|---|---|---|
| Exit 3, "No API key found" | No credential in the environment, the keychain or the config directory. | Run memorysync init, or set MEMORYSYNC_API_KEY. |
| Exit 2, "This command needs an end user" | Memory is scoped per user and none was given. | Pass --user, or set a default during init. |
| Exit 4, or writes that store nothing | A plan limit is reached, and the API degrades silently by design. | Run memorysync quota to see usage and the reset date. |
| add succeeds but search finds nothing | Embedding is asynchronous, so a new memory is briefly not searchable. | Use add --wait, or memorysync event wait <id>. |
| add returns a status of skipped | Extraction discarded it as filler, or merged it into a near-duplicate. | Not a failure and not worth retrying. Store a concrete, durable statement. |
| Exit 5 on every command | The API is unreachable: DNS, a proxy, or an egress rule. | memorysync doctor separates DNS from the API call. |
Environment variables
| Variable | Effect |
|---|---|
MEMORYSYNC_API_KEY | Credential. Overrides anything stored. |
MEMORYSYNC_BASE_URL | API base URL. |
MEMORYSYNC_USER_ID | Default end user. |
MEMORYSYNC_PROJECT_ID | Default project. |
MEMORYSYNC_PROFILE | Profile to use. |
MEMORYSYNC_OUTPUT | Default output format. |
MEMORYSYNC_TIMEOUT | Per-request timeout, in milliseconds. |
MEMORYSYNC_CONFIG_DIR | Config location. Defaults to ~/.memorysync. |
NO_COLOR | Disable colour. |
Where to go next
- MemorySync MCP
- Give an assistant the same memory through the Model Context Protocol, instead of shelling out.
- SDKs
- Call the API from your own code, in Python or TypeScript.
- API reference
- Every endpoint the CLI wraps, with request and response shapes.