MemoFSMemoFS
CLI

Command Line Interface

Command-line interface (@memofs/cli) reference for initializing, syncing, and managing agent memory.

The @memofs/cli package provides the primary command-line tool for managing local and hybrid memory workflows.

Installation

Install the CLI as a development dependency in your project:

npm install -D @memofs/cli

Requires Node.js >= 22.

Or install globally:

npm install -g @memofs/cli

You can also run it on demand without installation:

npx @memofs/cli --help

Global Flags

All commands accept these global flags before the subcommand:

FlagDescriptionDefault
-r, --root <path>Project root containing .memofs/Current directory
--runtime <mode>Runtime mode: local or hybridlocal
--cloud-url <url>MemoFS Cloud API URLMEMOFS_CLOUD_URL env
--api-key <key>MemoFS Cloud API keyMEMOFS_API_KEY env
--workspace-id <id>Default cloud workspace IDMEMOFS_WORKSPACE_ID env
-p, --project-id <id>Default cloud project IDMEMOFS_PROJECT_ID env
--timeout-ms <n>Cloud request timeout in milliseconds (positive integer)
-j, --jsonOutput machine-readable JSON envelopefalse
-v, --verboseShow detailed outputfalse
-q, --quietSuppress all output except errorsfalse
--no-colorDisable colored terminal output (NO_COLOR env supported)false

Environment Variables

VariableDescription
MEMOFS_RUNTIMERuntime mode: local or hybrid
MEMOFS_CLOUD_URLMemoFS Cloud API URL
MEMOFS_API_KEYMemoFS Cloud API key
MEMOFS_WORKSPACE_IDCloud workspace ID
MEMOFS_PROJECT_IDCloud project ID
MEMOFS_ROOTProject root containing .memofs/
MEMOFS_RECALL_ENGINERecall engine: lexical, vector, hybrid, or auto
MEMOFS_LOCAL_EMBEDDINGSEnable local embeddings (1 or true)
MEMOFS_EMBEDDING_MODELTransformers.js embedding model ID
NO_COLORWhen present, disables ANSI colors in terminal output

JSON Output & Envelopes

When running with -j or --json, every command formats its stdout as a single JSON object conforming to JsonEnvelope<T>:

Success Envelope

{
  "ok": true,
  "command": "remember",
  "data": {
    "stored": true,
    "eventId": "evt_1723766400000_abc123",
    "path": ".memofs/memory/notes.md",
    "kind": "decision",
    "tags": ["auth"],
    "confidence": 1
  }
}

Error Envelope

{
  "ok": false,
  "command": "remember",
  "error": {
    "code": "CLI_USAGE_ERROR",
    "message": "Refusing to store possible secret (openai_key). Use --allow-secrets only after review."
  }
}

Error Codes

The CLI emits standardized, machine-readable error codes:

Error CodeExit CodeDescription
CLI_USAGE_ERROR1Invalid flags, missing required arguments, or invalid option combinations.
CLI_VALIDATION_ERROR1Schema validation failures in config, manifest, or connector definitions.
CLI_FS_ERROR1Filesystem operation failure, missing directory, or path traversal attempt.
CLI_PROTOCOL_ERROR1Corrupted .memofs/ protocol files or invalid manifest format.
CLI_JSONL_ERROR1Malformed JSONL lines encountered in strict parsing mode.
CLI_UNEXPECTED_ERROR1Unhandled runtime errors or exceptions.

Configuration File

Create .memofs/config.json to persist defaults without storing secrets:

memofs config init --runtime hybrid -p frozen-crest --cloud-url https://memofs.dev/api/v1
{
  "$schema": "../node_modules/@memofs/cli/schema/config.json",
  "runtime": "hybrid",
  "root": ".",
  "cloud": {
    "baseUrl": "https://memofs.dev/api/v1",
    "projectId": "frozen-crest"
  },
  "recall": {
    "engine": "hybrid",
    "localEmbeddings": true
  }
}

Inspect the resolved configuration:

memofs config get

Package Exports & Programmatic Usage

In addition to the binary memofs, the @memofs/cli npm package exports its runner, helper functions, types, and schema:

Subpaths

  • @memofs/cli: The primary JavaScript/TypeScript module exporting runMemoFsCli, createMemoFSFromCli, output writers, constants, and utilities.
  • @memofs/cli/schema/config.json: The JSON Schema draft-07 definition for .memofs/config.json.

Programmatic Invocation

You can invoke the CLI command runner programmatically:

import { runMemoFsCli } from "@memofs/cli";

const result = await runMemoFsCli({
  argv: ["remember", "Use PostgreSQL for metadata", "--kind", "decision"],
  cwd: process.cwd(),
});

console.log("Exit code:", result.exitCode);
console.log("Output:", result.stdout);

Direct MemoFS Client Creation

Or construct the underlying MemoFS class instance with automatic CLI flag, environment variable, and .memofs/config.json resolution:

import { createMemoFSFromCli } from "@memofs/cli";

// Returns a fully configured MemoFS instance
const memo = createMemoFSFromCli({
  root: ".",
  runtime: "hybrid",
});

// Call core memory methods directly
await memo.writeMemory({
  content: "Use PostgreSQL for metadata",
  kind: "decision",
});

const context = await memo.context({
  query: "database configuration",
  taskType: "coding",
});

For the complete TypeScript programmatic API specification, see the CLI API Reference and Core API Reference.

Command Categories

CategoryDescriptionDocumentation
MemoryRead, record, pack, audit, search, snapshot, and consolidate memory.Memory Commands
AgentManage local AgentFS sessions and working files.Agent Commands
GenerateScaffold agent rules (AGENTS.md, CLAUDE.md, etc.), hooks, and MCP configs.Generate Commands
ConnectorsManage and run external data ingestion connectors (GitHub, Notion).Connectors Commands
CloudVerify health, check readiness, and sync file replicas with MemoFS Cloud.Cloud Commands
ConfigInspect and initialize .memofs/config.json.Config Commands

On this page