diff --git a/openclaw/src/index.ts b/openclaw/src/index.ts index 97ba4503..cbc510c6 100644 --- a/openclaw/src/index.ts +++ b/openclaw/src/index.ts @@ -642,6 +642,9 @@ export default function claudeMemPlugin(api: OpenClawPluginApi): void { const toolName = event.toolName; if (!toolName) return; + // Skip memory_ tools to prevent recursive observation loops + if (toolName.startsWith("memory_")) return; + const contentSessionId = getContentSessionId(ctx.sessionKey); // Extract result text from all content blocks @@ -654,6 +657,12 @@ export default function claudeMemPlugin(api: OpenClawPluginApi): void { .join("\n"); } + // Truncate long responses to prevent oversized payloads + const MAX_TOOL_RESPONSE_LENGTH = 1000; + if (toolResponseText.length > MAX_TOOL_RESPONSE_LENGTH) { + toolResponseText = toolResponseText.slice(0, MAX_TOOL_RESPONSE_LENGTH); + } + // Fire-and-forget: send observation + sync MEMORY.md in parallel workerPostFireAndForget(workerPort, "/api/sessions/observations", { contentSessionId, diff --git a/plugin/scripts/bun-runner.js b/plugin/scripts/bun-runner.js index 414fc332..0de7c876 100644 --- a/plugin/scripts/bun-runner.js +++ b/plugin/scripts/bun-runner.js @@ -12,7 +12,7 @@ * Fixes #818: Worker fails to start on fresh install */ import { spawnSync, spawn } from 'child_process'; -import { existsSync } from 'fs'; +import { existsSync, readFileSync } from 'fs'; import { join } from 'path'; import { homedir } from 'os'; @@ -54,6 +54,24 @@ function findBun() { return null; } +// Early exit if plugin is disabled in Claude Code settings (#781). +// Sync read + JSON parse — fastest possible check before spawning Bun. +function isPluginDisabledInClaudeSettings() { + try { + const configDir = process.env.CLAUDE_CONFIG_DIR || join(homedir(), '.claude'); + const settingsPath = join(configDir, 'settings.json'); + if (!existsSync(settingsPath)) return false; + const settings = JSON.parse(readFileSync(settingsPath, 'utf-8')); + return settings?.enabledPlugins?.['claude-mem@thedotmack'] === false; + } catch { + return false; + } +} + +if (isPluginDisabledInClaudeSettings()) { + process.exit(0); +} + // Get args: node bun-runner.js