From 2a83e530e981f3794dde2075e958748e2b918272 Mon Sep 17 00:00:00 2001 From: bigphoot Date: Sat, 24 Jan 2026 22:32:27 -0800 Subject: [PATCH] feat: Add multi-tenancy support for claude-mem pro Wire tenant, database, and API key settings into ChromaSync for remote/pro mode. In remote mode: - Passes tenant and database to ChromaClient for data isolation - Adds Authorization header when API key is configured - Logs tenant isolation connection details Local mode unchanged - uses default_tenant without explicit params. Co-Authored-By: Claude Opus 4.5 --- src/services/sync/ChromaSync.ts | 34 +++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/services/sync/ChromaSync.ts b/src/services/sync/ChromaSync.ts index e9d11e59..d3775279 100644 --- a/src/services/sync/ChromaSync.ts +++ b/src/services/sync/ChromaSync.ts @@ -109,6 +109,11 @@ export class ChromaSync { const port = parseInt(settings.CLAUDE_MEM_CHROMA_PORT || '8000', 10); const ssl = settings.CLAUDE_MEM_CHROMA_SSL === 'true'; + // Multi-tenancy settings (used in remote/pro mode) + const tenant = settings.CLAUDE_MEM_CHROMA_TENANT || 'default_tenant'; + const database = settings.CLAUDE_MEM_CHROMA_DATABASE || 'default_database'; + const apiKey = settings.CLAUDE_MEM_CHROMA_API_KEY || ''; + // In local mode, verify server is reachable if (mode === 'local') { const serverManager = ChromaServerManager.getInstance(); @@ -122,7 +127,31 @@ export class ChromaSync { const protocol = ssl ? 'https' : 'http'; const chromaPath = `${protocol}://${host}:${port}`; - this.chromaClient = new ChromaClient({ path: chromaPath }); + // Build client options + const clientOptions: { path: string; tenant?: string; database?: string; headers?: Record } = { + path: chromaPath + }; + + // In remote mode, use tenant isolation for pro users + if (mode === 'remote') { + clientOptions.tenant = tenant; + clientOptions.database = database; + + // Add API key header if configured + if (apiKey) { + clientOptions.headers = { + 'Authorization': `Bearer ${apiKey}` + }; + } + + logger.info('CHROMA_SYNC', 'Connecting with tenant isolation', { + tenant, + database, + hasApiKey: !!apiKey + }); + } + + this.chromaClient = new ChromaClient(clientOptions); // Verify connection with heartbeat await this.chromaClient.heartbeat(); @@ -132,7 +161,8 @@ export class ChromaSync { host, port, ssl, - mode + mode, + tenant: mode === 'remote' ? tenant : 'default_tenant' }); } catch (error) { logger.error('CHROMA_SYNC', 'Failed to connect to Chroma HTTP server', { project: this.project }, error as Error);