{"slug": "show-hn-engrim-a-universal-local-first-sqlite-memory-engine-for-ai-clis", "title": "Show HN: Engrim – A universal, local-first SQLite memory engine for AI CLIs", "summary": "Engrim, a universal local-first SQLite memory engine for AI CLIs, has been released on Hacker News, claiming to preserve project decisions and state across model switches with a 99%+ reduction in reloaded context cost. The tool, tested across 105 continuous sessions on a 50,000-line algorithmic trading system with zero regressions, integrates with Google Antigravity, Claude Code, Cursor MCP, and Windsurf, and is installable via pip.", "body_md": "**The Universal Cross-Model & Cross-Agent Episodic Memory Store.**\n\nA local-first, project-scoped SQLite memory engine that allows developers to freely switch between models and environments (**Google Antigravity**, **Claude Code**, **Cursor MCP**, **Windsurf**) on the **SAME** project without losing architectural decisions, user constraints, or project state.\n\n**\"Why pay for 200,000 tokens of forgotten noise on every turn? The models are disposable utilities; your project's decisions are not.\"**\n\nAs context windows scale to 1M+ tokens, developers face **attention dilution**: reasoning degrades, cost multiplies with every conversational turn, and clearing context causes total amnesia.\n\n`engrim` replaces attention dilution with **4,000 characters of curated episodic working memory**:\n\n- **Switzerland of AI Memory** : Decouples project intelligence from any single AI vendor or proprietary cloud silo. Switch from Gemini 3.8 in Antigravity to Claude 3.7 Sonnet in Claude Code to GPT-4o in Cursor mid-project — your agents pick up right where the others left off.\n- **Save Button for Autonomous Coding** : Externalize decisions, constraints, and state as you work. Clear your agent session freely (`/clear` ) and watch context reload intact.\n- **Smart, Hot Context Loading** : Combines SQLite FTS5 (bm25 keyword search) with static vector embeddings (`model2vec` ) in a zero-latency hybrid reciprocal-rank fusion engine.\n\n**Tested across 105 continuous sessions on a 50,000-line algorithmic trading system. Zero regressions across 186 unit tests, zero context amnesia across model switches.**\n\nIn production testing on an active algorithmic trading codebase running real capital:\n\n- Over **153,000 tokens of work** across days of architecture, parameter tuning, and debugging was consolidated into an active memory pack under**1,000 tokens** (<1% of the context window).\n- That is a **99%+ cut in reloaded context cost** on every session restart.\n- Seamlessly switched between Google Antigravity CLI, Claude Code, and Cursor MCP on identical repos with zero model drift or architectural regression.\n\n```\ngraph TD\n    subgraph Agents [\"Supported Agent Environments\"]\n        AGY[\"Google Antigravity<br/>(PreInvocation & Stop Hooks)\"]\n        CLAUDE[\"Claude Code<br/>(SessionStart & Stop Hooks)\"]\n        CURSOR[\"Cursor / Windsurf<br/>(Model Context Protocol stdio)\"]\n    end\n\n    subgraph CoreEngine [\"engrim Core Engine (v1.3.0)\"]\n        ADAPTERS[\"Adapters & Hooks<br/>(agy, claude, mcp)\"]\n        PROVENANCE[\"Agent Provenance Engine<br/>(origin_agent tracking)\"]\n        ROUTER[\"Hybrid Retrieval & Minder<br/>(bm25 lexical + vector cosine)\"]\n    end\n\n    subgraph Storage [\"Local-First SQLite Store (~/.engrim/memory.db)\"]\n        MEMORIES[(\"Curated Memories<br/>(decisions, facts, feedback)\")]\n        FTS5[\"FTS5 Full-Text Search<br/>(porter stemmer, triggers)\"]\n        VEC[\"Vector Embeddings<br/>(model2vec static embeddings)\"]\n        LOG[\"Flight Recorder Log<br/>(turns + action lines)\"]\n    end\n\n    AGY <-->|\"hook / CLI\"| ADAPTERS\n    CLAUDE <-->|\"hook / CLI\"| ADAPTERS\n    CURSOR <-->|\"JSON-RPC (stdio)\"| ADAPTERS\n    ADAPTERS --> PROVENANCE\n    PROVENANCE --> ROUTER\n    ROUTER --> MEMORIES\n    MEMORIES --- FTS5\n    MEMORIES --- VEC\n    ADAPTERS --> LOG\npip install engrim\n```\n\nRun `engrim setup` without arguments. It automatically detects installed environments on your machine and configures them all:\n\n```\nengrim setup\n```\n\n- If `~/.gemini` exists$\\rightarrow$ wires Antigravity lifecycle hooks, skill, and MCP server.\n- If `~/.claude` exists$\\rightarrow$ wires Claude Code SessionStart, Stop, status line, and CLAUDE.md.\n- If `~/.cursor` exists$\\rightarrow$ generates and merges Cursor MCP configuration.\n\n```\nengrim setup --agy\n```\n\n- Configures `~/.gemini/config/hooks.json` to execute`engrim hook --agent agy --event boot` on`PreInvocation` and`engrim hook --agent agy --event stop` on`Stop` .\n- Deploys the canonical Antigravity skill to `~/.gemini/config/skills/engrim/SKILL.md` .\n- Registers the MCP server in `~/.gemini/antigravity-cli/mcp_config.json` and`~/.gemini/config/mcp_config.json` .\n\n```\nengrim setup --claude\n```\n\n- Wires `SessionStart` ,`SessionEnd` ,`Stop` , and`UserPromptSubmit` hooks in`~/.claude/settings.json` .\n- Configures live ambient status line in Claude Code's status bar.\n- Appends memory usage notes to `~/.claude/CLAUDE.md` .\n\n```\nengrim setup --cursor\n```\n\n- Adds `engrim` to`~/.cursor/mcp.json` running`engrim serve --mcp` .\n\nAdd `engrim` to your `~/.codeium/windsurf/mcp_config.json`:\n\n```\n{\n  \"mcpServers\": {\n    \"engrim\": {\n      \"command\": \"engrim\",\n      \"args\": [\"serve\", \"--mcp\"]\n    }\n  }\n}\nengrim setup --all\n```\n\n- Configures every supported environment in one command.\n\n*(Use `--dry-run` with any setup command to inspect changes without modifying disk).*\n\nWhen multiple agents collaborate on a single codebase, provenance matters. `engrim` records the origin of every memory entry with the `origin_agent` field:\n\n- Allowed values: `antigravity` ,`claude-code` ,`cursor` ,`cli` , or`user` .\n- Automatically populated based on the active hook, MCP client, or CLI session.\n- Subtly surfaced in `engrim context` and`engrim list` :\n\n```\n🧠 engrim · memory restored for this project — you don't have to re-explain · /workspace\n  18 of 54 curated records loaded (~3850 chars) · the rest one `recall` away\n\n[DECISION]\n- #961 [DECISION] (via Antigravity): Inverted stop loss matrix for high volatility  (risk, execution)\n- #942 [DECISION] (via Claude Code): Switched primary database from MongoDB to PostgreSQL  (db, schema)\n- #910 [DECISION] (via Cursor): Standardized on Pydantic v2 schemas across API boundaries  (api, types)\n```\n\nExisting databases are non-destructively migrated on first access via `ALTER TABLE memories ADD COLUMN origin_agent TEXT`.\n\nLaunch the zero-dependency, JSON-RPC 2.0 stdio MCP server:\n\n```\nengrim serve --mcp\n# or: engrim mcp\n```\n\n`stdout` is strictly reserved for JSON-RPC messages, redirecting all diagnostic logs to `stderr`.\n\n| Tool | Signature | Purpose | \n|---|---|---|\n| `engrim_recall` | `(query: str, project: str = \"auto\", k: int = 5, type: str = None)` | Hybrid (keyword + semantic) search over project memory. | \n| `engrim_add` | `(type: str, summary: str, detail: str = None, tags: list[str] = [])` | Write a durable memory record persisted across sessions. | \n| `engrim_context` | `(project: str = \"auto\", budget: int = 4000)` | Retrieve the session-boot memory pack within a character budget. | \n| `engrim_review` | `(project: str = \"auto\")` | Check uncaptured decisions from transcript logs before clearing. | \n\n| Command | Usage | Description | \n|---|---|---|\n| `engrim add` | `engrim add -t decision -s \"...\" [--origin-agent agy]` | Insert memory record (types: `decision` ,`fact` ,`feedback` ,`state` ,`user` ,`reference` ). | \n| `engrim recall` | `engrim recall -q \"database\"` | Ranked hybrid recall for the project ( `--log` searches raw turns). | \n| `engrim context` | `engrim context [-b 4000]` | Priority-ordered, budget-capped session-boot pack. | \n| `engrim hook` | `engrim hook --agent agy --event boot` | Agent lifecycle hook runner for Antigravity and Claude Code. | \n| `engrim setup` | `engrim setup [--agy\\|--claude\\|--cursor\\|--all]` | Universal multi-agent environment configuration. | \n| `engrim serve` | `engrim serve --mcp` | Start stdio MCP server for agent integrations. | \n| `engrim review` | `engrim review` | \"Safe to clear\" coverage check: scans logs for uncurated decisions. | \n| `engrim list` | `engrim list [-k 20]` | List recent memories for the current project. | \n| `engrim supersede` | `engrim supersede --id 12 --status superseded` | Mark a record superseded without erasing history. | \n| `engrim sync` | `engrim sync [DIR]` | Mirror markdown memories into the store (idempotent seed-once). | \n\n1. **Capture as you work** : Whenever a major decision or architectural rule is made, run`engrim add` or invoke`engrim_add` via your agent.\n2. **Use `resume-pointer`** : Before ending a session or clearing, add a record tagged`resume-pointer` describing the immediate next task. The newest pointer is pinned under`[▶ RESUME HERE]` at the top of the next session's boot pack.\n3. **Verify with `engrim review`** : Check that all recent decisions are captured.\n4. **Clear freely (`/clear`)** : The session window is wiped clean;` engrim` automatically re-injects the active memory pack on the next prompt or invocation.\n\n- **100% Local & Offline** : All memory records and logs reside in a local SQLite file (`~/.engrim/memory.db` ). No telemetry, no cloud sync, no tracking.\n- **Model Storage** : Uses`model2vec` for local static embeddings (~30ms load time, no GPU required, runs on CPU). Can run pure-lexical (`ENGRIM_EMBED=off` ) for zero extra dependencies.\n- **POSIX File Permissions** : Databases are created with restricted owner-only permissions (`0600` ).\n- **Git Protection** :`*.db` is gitignored by default; your memories never accidentally commit to version control.\n\nMIT © 2026 Tim Gordon.", "url": "https://wpnews.pro/news/show-hn-engrim-a-universal-local-first-sqlite-memory-engine-for-ai-clis", "canonical_source": "https://github.com/timgordontg/engrim", "published_at": "2026-09-07 04:49:36+00:00", "updated_at": "2026-09-07 05:27:44.713676+00:00", "lang": "en", "topics": ["ai-tools", "ai-infrastructure", "developer-tools"], "entities": ["Engrim", "Google Antigravity", "Claude Code", "Cursor MCP", "Windsurf", "SQLite", "model2vec"], "alternates": {"html": "https://wpnews.pro/news/show-hn-engrim-a-universal-local-first-sqlite-memory-engine-for-ai-clis", "markdown": "https://wpnews.pro/news/show-hn-engrim-a-universal-local-first-sqlite-memory-engine-for-ai-clis.md", "text": "https://wpnews.pro/news/show-hn-engrim-a-universal-local-first-sqlite-memory-engine-for-ai-clis.txt", "jsonld": "https://wpnews.pro/news/show-hn-engrim-a-universal-local-first-sqlite-memory-engine-for-ai-clis.jsonld"}}