Skip to content
 
 

Repository files navigation


Hivemind-PG
Hivemind-PG

One brain for all your agents — SQLite (solo) + PostgreSQL (team)

npm GitHub stars License Node

Self-hosted shared brain for Claude Code • OpenClaw • Codex • Cursor • Hermes • pi agents.
Fork of Activeloop Hivemind with SQLite (solo) + PostgreSQL (team) backends.

📦 Package: hivemind-pg on npm — the self-hosted alternative to @deeplake/hivemind (Deeplake Cloud).

Same agent integrations, same Skillify engine, same recall — only the storage layer changed. Use @deeplake/hivemind if you want cloud-managed storage; use hivemind-pg if you want your data on your own PostgreSQL or SQLite.

One engineer's agent figures out a tricky migration on Monday.

Tuesday, every agent on the team can execute the pattern.

On LoCoMo, the public long-context memory benchmark, Hivemind is 25% cheaper, 1.7× fewer tokens, and 31% fewer turns than running without shared memory.

Beyond memory. Hivemind doesn't just remember. It mines your team's traces for repeated patterns and codifies them into reusable skills that propagate back into every agent on the team.

  • 📥 Captures every session's prompts, tool calls, and responses as structured traces in your local database
  • 🧠 Codifies patterns into reusable SKILL.md files, available to every agent on your team
  • 🔍 Searches traces and skills with hybrid lexical + semantic retrieval (BM25 fallback when embeddings off)
  • 🔗 Propagates capability across sessions, agents, teammates, and machines in real time
  • 📁 Intercepts file operations on ~/.hivemind-local/memory/ through a virtual filesystem backed by SQL
  • 📝 Summarizes sessions into AI-generated wiki pages via a background worker at session end
  • 🔒 Isolates org data with PostgreSQL Row-Level Security (RLS) — your data never leaves your infrastructure

What's Different from Deeplake Cloud Hivemind

@deeplake/hivemind hivemind-pg
npm package @deeplake/hivemind hivemind-pg
Login Device Flow + account Zero login (SQLite) / env vars (PostgreSQL)
Data Activeloop servers Your machine / your PostgreSQL
Offline Must be online Fully offline
Latency 50–200ms <5ms (SQLite) / local network (PG)
Cost Billed per usage Free
Team sharing Built-in org/workspace PostgreSQL backend with RLS
Skill review Planned Built-in (draft → active flow)

What's the same? Hooks, Skillify mining, recall, goals, rules, VFS, codebase graph, proactive recall, embeddings — only the storage layer changed.

Quick start

Solo developer (SQLite — zero config)

npm install -g hivemind-pg
hivemind install

That's it. Your first coding session will automatically capture patterns and build a local memory database at ~/.hivemind-local/hivemind.db.

Team (PostgreSQL)

npm install -g hivemind-pg

# Set up PostgreSQL connection
export HIVEMIND_BACKEND=postgres
export HIVEMIND_DATABASE_URL="postgresql://user:pass@host:5432/hivemind"
export HIVEMIND_ORG_ID=my-team
hivemind install

See the Configuration section below for Docker / Supabase / Neon setup instructions.

Install for a specific assistant only:

hivemind install --only claude
hivemind claude install    # equivalent
hivemind codex install
hivemind cursor install
hivemind hermes install
hivemind pi install

Check what's wired up:

hivemind status

Supported assistants:

Platform Integration Auto-capture Auto-recall
Claude Code Marketplace plugin
OpenClaw Native extension
Codex Hooks (hooks.json)
Cursor Hooks (hooks.json 1.7+)
Hermes Agent Shell hooks + skill + MCP server
pi Extension API + skill + AGENTS.md

Uninstall

hivemind uninstall              # remove from every detected assistant
hivemind codex uninstall        # remove from one

How it works

Capture → Codify → Propagate → Compound. Every coding-agent interaction is captured as a structured trace in your local SQLite or PostgreSQL database. A background worker mines traces for repeated patterns and codifies them into SKILL.md files. Codified skills propagate into every connected agent's context at inference time.

Alice codes → capture → stored in shared DB
                                ↓
Bob codes → recall → sees Alice's patterns → avoids same mistakes
                                ↓
Skillify mines Alice's session → creates a skill
                                ↓
Auto-pull gives Bob the skill → Bob's agent auto-uses it
                                ↓
CTO writes a coding rule → all agents auto-follow

Features

🔍 Natural search

Just ask your agent naturally:

"What was Emanuele working on?"
"Search traces for authentication bugs we've solved"
"What did we decide about the API design?"
"Show me skills my team has codified for handling migrations"

🔒 Privacy controls

Disable capture entirely:

HIVEMIND_CAPTURE=false claude

Disable capture for a specific directory tree by dropping a .hivemind file with { "collect": false }.

Enable debug logging:

HIVEMIND_DEBUG=1 claude

🛡️ Row-Level Security (PostgreSQL)

When using PostgreSQL, RLS is enabled by default. Each org can only see its own data — enforced at the database level. Even if two orgs share the same database, they cannot read each other's memory.

⚠️ Important: RLS does not apply to PostgreSQL superusers. Create a non-superuser app user for hivemind connections.

✅ Skill Approval Flow

When skillApprovalFlow is enabled, newly mined skills start as draft and require approval before teammates can see them:

export HIVEMIND_SKILL_APPROVAL_FLOW=true
hivemind install

hivemind skillify list --status draft     # see pending skills
hivemind skillify approve my-skill        # approve → now everyone sees it
hivemind skillify reject bad-skill        # reject → removed

🔄 Optimistic Locking (PostgreSQL)

For teams: concurrent edits to the same skill or rule use compare-and-swap on the version column. On conflict, the second writer gets a clear error message instead of silently overwriting.

⚠️ Data collection notice

This plugin captures session activity and stores it locally in your SQLite or PostgreSQL database:

Data What's captured
User prompts Every message you send
Tool calls Tool name + full input
Tool responses Full tool output
Assistant responses The agent's final response
Subagent activity Subagent tool calls and responses
Codified skills Patterns extracted from traces

Your data stays on your machine. No cloud, no telemetry, no external API calls for storage.

Configuration

Environment Variables

Variable Default Description
HIVEMIND_BACKEND sqlite sqlite, postgres, or deeplake
HIVEMIND_SQLITE_PATH ~/.hivemind-local/hivemind.db SQLite database path
HIVEMIND_DATABASE_URL PostgreSQL connection string
HIVEMIND_ORG_ID Org identifier for multi-tenant
HIVEMIND_WORKSPACE_ID default Workspace within the org
HIVEMIND_ENABLE_RLS true (postgres) Enable Row-Level Security
HIVEMIND_SKILL_APPROVAL_FLOW false Require approval for new skills
HIVEMIND_TOKEN API token (only for deeplake backend)
HIVEMIND_API_URL https://api.deeplake.ai API endpoint (only for deeplake backend)
HIVEMIND_CAPTURE true Set to false to disable capture
HIVEMIND_MEMORY_PATH ~/.hivemind-local/memory Path that triggers interception
HIVEMIND_EMBEDDINGS true Set to false to force lexical-only mode
HIVEMIND_PROACTIVE_RECALL_DISABLED Set to 1 to disable proactive recall
HIVEMIND_DEBUG Set to 1 for verbose hook debug logs

.hivemind File (per-directory)

Drop a .hivemind JSON file at the root of a project to override settings:

{
  "orgId": "my-team",
  "workspaceId": "project-alpha",
  "collect": true
}
Field Effect
orgId Route this tree to this org — captured traces and memory reads
workspaceId Route to this workspace
collect falsenever capture traces from this tree

An HIVEMIND_ORG_ID / HIVEMIND_WORKSPACE_ID in your environment wins over a .hivemind file.

CLI Commands

hivemind install                    # set up hooks for your agent
hivemind status                     # show what's wired up
hivemind skillify status            # show mining scope, team, tracked projects
hivemind skillify scope <me|team>   # set mining scope
hivemind skillify pull              # fetch skills from shared DB
hivemind skillify push <name>       # push a local skill to shared DB
hivemind skillify list [--status draft]  # list skills
hivemind skillify approve <name>    # approve a draft skill
hivemind skillify reject <name>     # reject a draft skill
hivemind workspace list             # list workspaces (postgres)
hivemind workspace create <name>    # create a workspace
hivemind workspace switch <name>    # switch current workspace
hivemind rules add "rule text"      # add a team rule
hivemind rules list                 # list active rules
hivemind goal add "objective"       # add a goal
hivemind goal list [--all|--mine]   # list goals

Semantic search (optional)

Hivemind ships with a local embedding daemon (nomic-embed-text-v1.5) for hybrid semantic + lexical search. Off by default (~600 MB dependency footprint). Enable with hivemind embeddings install. Without it, search degrades silently to BM25/lexical-only.

For PostgreSQL, install the pgvector extension for native vector similarity search. Without it, vector search falls back to brute-force.

Proactive recall

On a recall-worthy prompt, Hivemind automatically searches team summaries and injects a relevant snippet into the agent's context — so prior work shows up unprompted.

On by default. Disable with HIVEMIND_PROACTIVE_RECALL_DISABLED=1.

Skills (skillify)

Hivemind codifies recurring patterns from your team's recent sessions into reusable skills that propagate to every agent on your team, automatically.

hivemind skillify                            # show current scope, team, per-project state
hivemind skillify scope <me|team>            # who counts as "in scope" for mining
hivemind skillify pull                       # install teammates' skills locally

Rules (cross-agent team principles)

Hivemind shares team rules across every agent in the org, injected at SessionStart.

hivemind rules add "no DROP TABLE on prod creds"
hivemind rules list                          # latest 10 active
hivemind rules edit <rule-id> "<new text>"   # bumps version
hivemind rules done <rule-id>                # mark closed

Goals + KPIs

Personal / team objectives + measurable targets live in the virtual filesystem under ~/.hivemind-local/memory/goal/ and ~/.hivemind-local/memory/kpi/.

hivemind goal add "ship the search bar"
hivemind goal list [--all|--mine]
hivemind goal done <goal_id>

Architecture

                    ┌─────────────────────────┐
                    │    StorageBackend        │
                    │  (src/storage/backend.ts)│
                    └──────┬──────────┬───────┘
                           │          │
               ┌───────────┤          ├───────────┐
               ▼           ▼          ▼           ▼
        SqliteBackend  PostgresBackend  DeeplakeBackend
        (default)      (team/RLS)      (backward compat)
               │           │
               ▼           ▼
         ~/.hivemind-   PostgreSQL +
         local/         pgvector +
         hivemind.db    RLS policies
  • SqliteBackend — zero config, single user, WAL mode, <5ms latency
  • PostgresBackend — multi-tenant, RLS org isolation, pgvector, optimistic locking
  • DeeplakeBackend — adapter for backward compatibility with @deeplake/hivemind
  • Factory (createBackend()) — auto-selects by config, auto-injects RLS context

Per-agent integration mechanisms: docs/ARCHITECTURE.md.

Security & storage

Local-first

  • No cloud. All data stored in SQLite (local) or your own PostgreSQL server
  • No telemetry. No external API calls for storage or analytics
  • No account required. SQLite backend works with zero login
  • TLS between agents and PostgreSQL (if configured)
  • RLS enforces org isolation at the database level

Code-level controls

  • SQL values escaped with sqlStr(), sqlLike(), sqlIdent()
  • ~70 allowlisted builtins run in the virtual FS; unrecognized commands are denied
  • Credentials stored with mode 0600, config dir with mode 0700

Backward compatibility

The deeplake backend preserves full compatibility with the original @deeplake/hivemind cloud service. Set HIVEMIND_BACKEND=deeplake; HIVEMIND_TOKEN=<your-token> to use it.

Development

git clone https://github.com/mingfeiqiao/hivemind.git
cd hivemind
npm install
npm run build     # tsc + esbuild
npm test          # vitest

Test locally with Claude Code:

claude --plugin-dir claude-code

License

Apache License 2.0, © Activeloop, Inc. See LICENSE for details.

Fork maintained by mingfeiqiao. Upstream: activeloopai/hivemind.

About

Hivemind turns your traces into reusable skills across agents

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages