Skip to main content

Cross-agent persistent memory for AI coding assistants

Project description

OpenMemory

Cross-agent persistent memory for AI coding assistants.

Python Version License

OpenMemory is a lightweight, persistent memory system that enables AI coding assistants to remember context across sessions, share knowledge between different agents, and retrieve relevant past decisions through semantic search.

Features

  • Zero-Config SQLite Storage — Auto-discovers project root, stores in .openmemory/memory.db
  • Cross-Agent Compatibility — Works with Claude Code, Kilo Code, Antigravity, GitHub Copilot, Cursor, Codex, and any tool with shell access
  • Semantic Search — Hash-based embeddings for finding related entries without heavy ML dependencies
  • Automatic Context Loading — Injects project history into prompts via plugins for OpenCode, Kilo Code, Claude Code, and Antigravity
  • Simple CLI — Log, search, and retrieve context with intuitive commands
  • Lightweight — No heavy dependencies, runs offline, no API keys required

Quick Start

Installation

pip install memosq

Usage

# Log a decision
memosq log \
  --agent "claude-code" \
  --action "refactored" \
  --summary "Moved JWT validation to middleware" \
  --files "src/auth.ts,src/middleware.ts" \
  --decision "All auth logic should be centralized" \
  --tags "auth,security,middleware"

# Search memory
memosq search --query "authentication changes" --limit 5

# Get project context
memosq context

# Show recent entries
memosq recent --limit 10

# Filter by topic
memosq topic --name "auth" --limit 10

# Initialize OpenMemory for a project (creates .openmemory/ + configs)
memosq init --all

# Initialize with specific agent configs
memosq init --with-claude --with-cursor --with-kilo --with-git

Auto-Mode (opencode Integration)

OpenMemory includes a plugin for opencode that makes memory management completely automatic:

  • Session Start: Automatically loads project context
  • During Chat: Logs user prompts and assistant responses
  • File Changes: Tracks code modifications automatically
  • No Commands Needed: The user never touches the CLI

Enable Auto-Mode

Add to ~/.config/opencode/opencode.jsonc:

{
  "plugin": [
    "opencode-orchestrator",
    "memosq"
  ]
}

Auto-Mode (Kilo Code Integration)

Kilo Code is a fork of OpenCode and supports the same plugin system. OpenMemory includes a plugin for Kilo Code that makes memory management completely automatic:

  • Session Start: Automatically loads project context
  • During Chat: Logs user prompts and assistant responses
  • File Changes: Tracks code modifications automatically
  • No Commands Needed: The user never touches the CLI

Enable Auto-Mode

Add to ~/.config/kilo/kilo.jsonc:

{
  "plugin": [
    "opencode-orchestrator",
    "/Users/ege/Desktop/fikir/openmemory/plugin/kilo-memory-plugin.js"
  ]
}

Auto-Mode (Antigravity Integration)

Antigravity is Google's AI coding agent with SDK support. OpenMemory includes hooks for Antigravity that make memory management completely automatic:

  • Session Start: Automatically loads project context
  • During Chat: Logs user prompts and assistant responses
  • File Changes: Tracks code modifications automatically
  • No Commands Needed: The user never touches the CLI

Enable Auto-Mode

from google.antigravity import Agent, LocalAgentConfig
from memosq.antigravity import OpenMemoryHooks

hooks = OpenMemoryHooks()
config = LocalAgentConfig(
    hooks=hooks.get_hooks(),
    policies=hooks.get_policies()
)
async with Agent(config) as agent:
    response = await agent.chat("Hello")

Auto-Mode (Claude Code Integration)

Claude Code supports hooks that run automatically. OpenMemory includes hooks for Claude Code that make memory management completely automatic:

  • Session Start: Automatically loads project context
  • During Chat: Logs user prompts and assistant responses
  • File Changes: Tracks code modifications automatically
  • No Commands Needed: The user never touches the CLI

Enable Auto-Mode

Add to ~/.claude/settings.json:

{
  "hooks": {
    "SessionStart": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "memosq",
            "args": ["context"],
            "async": true
          }
        ]
      }
    ],
    "UserPromptSubmit": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "memosq",
            "args": ["log", "--agent", "claude-code", "--action", "user_prompt", "--summary", "{{prompt}}", "--tags", "prompt,claude"],
            "async": true
          }
        ]
      }
    ]
  }
}

Architecture

┌─────────────────────────────────────────────┐
│              AI Agent (Any)                  │
│  (Claude, Copilot, Cursor, Codex, etc.)     │
└──────────────────┬──────────────────────────┘
                   │
                   ▼
┌─────────────────────────────────────────────┐
│           OpenMemory CLI / Plugin             │
│         (scripts/memosq.py)              │
└──────────────────┬──────────────────────────┘
                   │
                   ▼
┌─────────────────────────────────────────────┐
│         OpenMemory Core Library               │
│         (memosq/__init__.py)             │
│                                              │
│  • SQLite Storage                             │
│  • Semantic Search (Hash-based Embeddings)   │
│  • Context Builder                            │
│  • Auto-discovery                             │
└──────────────────┬──────────────────────────┘
                   │
                   ▼
┌─────────────────────────────────────────────┐
│         .openmemory/memory.db                │
│     (Shared across all agents in project)    │
└─────────────────────────────────────────────┘

Data Format

Each memory entry contains:

{
  "id": 1,
  "timestamp": "2026-06-11T01:20:02",
  "agent": "claude-code",
  "action": "refactored",
  "summary": "Moved JWT validation to middleware",
  "files": "src/auth.ts,src/middleware.ts",
  "decision": "All auth logic should be centralized",
  "outcome": "success",
  "tags": "auth,security,middleware",
  "embedding": "[0.12, 0.05, ...]"
}

Semantic Search

OpenMemory uses a lightweight hash-based embedding system:

  • No ML dependencies — No PyTorch, TensorFlow, or transformers
  • Offline — Works without internet or API keys
  • Fast — 128-dim vectors computed in microseconds
  • Effective — Shared vocabulary creates overlap between related entries

For production use, you can swap in sentence-transformers by overriding the _generate_embedding method.

Best Practices

  1. Log decisions, not just actions — Include WHY, not just WHAT
  2. Use consistent tags — Makes filtering and searching effective
  3. Include file paths — Helps agents understand scope
  4. Search before assuming — Check if similar work was done before
  5. Update on failures — Log what didn't work and why

API Usage

from memosq import OpenMemory

# Initialize
memory = OpenMemory()

# Log an entry
memory.log(
    agent="claude-code",
    action="implemented",
    summary="Added rate limiting to API endpoints",
    files="src/middleware/rate-limit.ts",
    tags="api,security,performance"
)

# Search
results = memory.search("authentication changes", limit=5)

# Get recent entries
recent = memory.recent(limit=10)

# Get project context
context = memory.get_context()

# Get entries by topic
topic = memory.get_topic("auth", limit=10)

Storage

Memory is stored in .openmemory/memory.db at the project root. The database is auto-discovered by:

  1. Looking for .openmemory/ in the current directory
  2. Walking up the tree for .git/ or .openmemory/
  3. Using the first found project root

This means all agents working on the same project share the same memory automatically.

Commands

Command Description
memosq log Create a new memory entry
memosq search Semantic search across all entries
memosq recent Show most recent entries
memosq context Project summary and statistics
memosq topic Filter by tag/topic
memosq init Initialize OpenMemory for a project

Initialize

Run memosq init once per project to set up automatic memory:

# Basic setup (creates .openmemory/ + database)
memosq init

# Setup with all supported agent configs
memosq init --all

# Setup with specific agents
memosq init --with-claude --with-cursor --with-kilo --with-git

What init creates:

  • .openmemory/ directory with memory.db SQLite database
  • --with-claude.claude/settings.json (auto-log hooks)
  • --with-cursor.cursorrules (logging instructions)
  • --with-kilokilo.jsonc + .kilo/rules/ (config)
  • --with-git.git/hooks/post-commit (auto-log commits)
  • --all → Enables all of the above

Contributing

See CONTRIBUTING.md for details.

Changelog

See CHANGELOG.md for version history.

License

MIT — see LICENSE

Related


Made for agents, by agents. 🧠

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

memosq-1.0.0.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

memosq-1.0.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file memosq-1.0.0.tar.gz.

File metadata

  • Download URL: memosq-1.0.0.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for memosq-1.0.0.tar.gz
Algorithm Hash digest
SHA256 92731d23a3fdb1b0962c21826dc73515e4d7ed7a8ca823b4fd88f3dab0c0a0c5
MD5 86398f63149fe72bb430b376ef7abcf3
BLAKE2b-256 70959e38a21202b2d814369ebcba51db5495347a04ab083e41173d478aecde05

See more details on using hashes here.

File details

Details for the file memosq-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: memosq-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for memosq-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b2691770134dca095ef65556a0585f2796ae5a5e2e7fa4e9a8738e65056d043c
MD5 32947a3146d948cc96393a17182e4548
BLAKE2b-256 e26de082e36688baca7c6ebbe9ae3f3ad5b479d5a3585352bc2542b3a0b5b52a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page