You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The bundled libsqlite3.dylib files in native/darwin-arm64/ and native/darwin-x64/ have an unresolved Homebrew build placeholder as their install name, making them non-functional on every machine. The "bundled dylib" feature introduced in 2.8.8 has never worked — it silently fails and falls back to customSqlitePath or Homebrew auto-detect.
Error
Error: Failed to load sqlite-vec extension: Error: This build of sqlite3 does not support dynamic extension loading
Root Cause
The bundled dylib was copied from Homebrew's build directory rather than the installed location. During brew install --build-from-source, Homebrew uses @@HOMEBREW_PREFIX@@ as a placeholder in the dylib's install name, which gets resolved to the actual prefix (e.g. /opt/homebrew) only during the install step.
$ otool -D native/darwin-arm64/libsqlite3.dylib
@@HOMEBREW_PREFIX@@/opt/sqlite/lib/libsqlite3.dylib
$ otool -L native/darwin-arm64/libsqlite3.dylib
@@HOMEBREW_PREFIX@@/opt/sqlite/lib/libsqlite3.dylib (compatibility version 9.0.0, current version 9.6.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.12)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1345.120.2)
Compare with a properly installed Homebrew SQLite:
The broken @@HOMEBREW_PREFIX@@ placeholder in the bundled dylib is a secondary issue. Even with a correctly built dylib, setCustomSQLite() would never work because OpenCode's embedded Bun runtime compiles SQLite with SQLITE_OMIT_LOAD_EXTENSION, and it initializes before any plugin code runs.
Evidence
The OpenCode v1.2.0 binary (opencode-darwin-arm64) embeds Bun with SQLite that has extension loading disabled at compile time:
Bun throws "SQLite already loaded" because its SQLite was initialized at startup
trySetCustomSQLite() catches this error and treats it as success (line 100-101)
sqliteVec.load(db) fails because the active SQLite has extension loading permanently disabled
Why no config workaround helps
customSqlitePath → setCustomSQLite() still gets "SQLite already loaded", same result
Bundled dylib (even if fixed) → same problem
Homebrew auto-detect → same problem
The setCustomSQLite() call is a no-op regardless of what path is provided, because Bun's internal SQLite is already loaded before any plugin code executes.
Possible fixes
OpenCode side: Rebuild the embedded Bun without SQLITE_OMIT_LOAD_EXTENSION
opencode-mem side: Use a standalone SQLite binding (e.g., better-sqlite3 with N-API) instead of bun:sqlite, shipping its own SQLite with extension support that isn't affected by Bun's built-in SQLite
opencode-mem side: Use sqlite-vec's pure WASM fallback if available, bypassing native extension loading entirely
Update 2: setCustomSQLite is fundamentally broken when running under OpenCode
Further investigation reveals the problem is not just SQLITE_OMIT_LOAD_EXTENSION — it's that Database.setCustomSQLite() can never succeed when called from a plugin.
Why setCustomSQLite is a no-op
setCustomSQLite() only works if called before any Database is instantiated. Once any code calls new Database(...), Bun's internal SQLite is locked in and setCustomSQLite() throws "SQLite already loaded".
OpenCode (the host application) opens its own SQLite databases during startup — before any plugin code runs. By the time opencode-mem's sqlite-bootstrap.js executes, it's already too late. The bootstrap code catches "SQLite already loaded" and treats it as success (line 100-101), but the active SQLite is still the built-in one without extension support.
Verified with standalone Bun
// This WORKS — setCustomSQLite before any Database:const{ Database }=require("bun:sqlite");Database.setCustomSQLite("/opt/homebrew/opt/sqlite/lib/libsqlite3.dylib");constdb=newDatabase(":memory:");db.loadExtension("path/to/vec0.dylib");// SUCCESS// This FAILS — simulating what happens under OpenCode:const{ Database }=require("bun:sqlite");constearlyDb=newDatabase(":memory:");// OpenCode does this at startupearlyDb.close();Database.setCustomSQLite("/opt/homebrew/opt/sqlite/lib/libsqlite3.dylib");// throws "SQLite already loaded"constdb=newDatabase(":memory:");db.loadExtension("path/to/vec0.dylib");// FAILS — extension loading disabled
The setCustomSQLite + bun:sqlite approach is a dead end for any compiled Bun host (which includes OpenCode). The plugin needs to use a SQLite binding that brings its own SQLite library, independent of bun:sqlite. Options:
better-sqlite3 (N-API) — standalone SQLite with full extension support, works in any Node/Bun runtime
sql.js (WASM) — pure WASM SQLite, no native dependencies at all
Request OpenCode to call setCustomSQLite before opening any databases — requires upstream OpenCode changes
Environment
OpenCode 1.2.0 (Homebrew, compiled Bun binary)
opencode-mem 2.8.9
macOS Sequoia (Apple Silicon)
Standalone Bun 1.3.9 (works fine when running directly)
This issue has been resolved by replacing sqlite-vec with hnswlib-wasm - a pure WASM implementation of HNSW (Hierarchical Navigable Small World) algorithm for vector search.
Why the Breaking Change?
OpenCode loads bun:sqlite BEFORE plugins run, so Database.setCustomSQLite() always fails with "SQLite already loaded" error. This means even a properly-built dylib with statically-linked sqlite-vec cannot be used. The only viable solution is to remove the native dependency entirely.
What Changed
Removed sqlite-vec dependency (native dylib no longer needed)
Vector search now uses hnswlib-wasm (pure WASM, works everywhere)
No more macOS-specific SQLite issues
No more Homebrew fallback needed
Migration
This is a breaking change. Existing vector indices will need to be rebuilt. The plugin will automatically rebuild HNSW indices from your stored memory data on first run.
Benefits
Plug-and-play: No native dependencies, no setup required
Cross-platform: Works identically on macOS, Linux, Windows
No more SQLite extension loading issues
Upgrade with: bun update opencode-mem or let OpenCode auto-update on next restart.
Activity
Alph4d0g commentedon Feb 20, 2026
Update: Deeper Root Cause Found
The broken
@@HOMEBREW_PREFIX@@placeholder in the bundled dylib is a secondary issue. Even with a correctly built dylib,setCustomSQLite()would never work because OpenCode's embedded Bun runtime compiles SQLite withSQLITE_OMIT_LOAD_EXTENSION, and it initializes before any plugin code runs.Evidence
The OpenCode v1.2.0 binary (
opencode-darwin-arm64) embeds Bun with SQLite that has extension loading disabled at compile time:What happens at runtime
SQLITE_OMIT_LOAD_EXTENSION)opencode-memplugin loads →sqlite-bootstrap.jscallsDatabase.setCustomSQLite(path)"SQLite already loaded"because its SQLite was initialized at startuptrySetCustomSQLite()catches this error and treats it as success (line 100-101)sqliteVec.load(db)fails because the active SQLite has extension loading permanently disabledWhy no config workaround helps
customSqlitePath→setCustomSQLite()still gets "SQLite already loaded", same resultThe
setCustomSQLite()call is a no-op regardless of what path is provided, because Bun's internal SQLite is already loaded before any plugin code executes.Possible fixes
SQLITE_OMIT_LOAD_EXTENSIONbetter-sqlite3with N-API) instead ofbun:sqlite, shipping its own SQLite with extension support that isn't affected by Bun's built-in SQLitesqlite-vec's pure WASM fallback if available, bypassing native extension loading entirelyAlph4d0g commentedon Feb 20, 2026
Update 2:
setCustomSQLiteis fundamentally broken when running under OpenCodeFurther investigation reveals the problem is not just
SQLITE_OMIT_LOAD_EXTENSION— it's thatDatabase.setCustomSQLite()can never succeed when called from a plugin.Why
setCustomSQLiteis a no-opsetCustomSQLite()only works if called before anyDatabaseis instantiated. Once any code callsnew Database(...), Bun's internal SQLite is locked in andsetCustomSQLite()throws "SQLite already loaded".OpenCode (the host application) opens its own SQLite databases during startup — before any plugin code runs. By the time
opencode-mem'ssqlite-bootstrap.jsexecutes, it's already too late. The bootstrap code catches "SQLite already loaded" and treats it as success (line 100-101), but the active SQLite is still the built-in one without extension support.Verified with standalone Bun
What we tried that doesn't work
customSqlitePathconfigsetCustomSQLitesilently fails (SQLite already loaded)DYLD_INSERT_LIBRARIESpreloadbunfig.tomlwithpreloadbunfig.toml--preloadflagBUN_PRELOADenv varThe only path forward
The
setCustomSQLite+bun:sqliteapproach is a dead end for any compiled Bun host (which includes OpenCode). The plugin needs to use a SQLite binding that brings its own SQLite library, independent ofbun:sqlite. Options:better-sqlite3(N-API) — standalone SQLite with full extension support, works in any Node/Bun runtimesql.js(WASM) — pure WASM SQLite, no native dependencies at allsetCustomSQLitebefore opening any databases — requires upstream OpenCode changesEnvironment
fix: resolve bundled SQLite dylib issue (#37)
tickernelz commentedon Feb 20, 2026
✅ Fixed in v2.11.0
This issue has been resolved by replacing sqlite-vec with hnswlib-wasm - a pure WASM implementation of HNSW (Hierarchical Navigable Small World) algorithm for vector search.
Why the Breaking Change?
OpenCode loads
bun:sqliteBEFORE plugins run, soDatabase.setCustomSQLite()always fails with "SQLite already loaded" error. This means even a properly-built dylib with statically-linked sqlite-vec cannot be used. The only viable solution is to remove the native dependency entirely.What Changed
Migration
This is a breaking change. Existing vector indices will need to be rebuilt. The plugin will automatically rebuild HNSW indices from your stored memory data on first run.
Benefits
Upgrade with:
bun update opencode-memor let OpenCode auto-update on next restart.feat: statically link sqlite-vec into SQLite dylib