From 6c0939bd92abba3bfe0cc687c22558811a130661 Mon Sep 17 00:00:00 2001 From: Hieu Le <78847613+hieu-lee@users.noreply.github.com> Date: Mon, 16 Nov 2026 19:29:49 +0100 Subject: [PATCH] fix(server): Claude threads load plugins installed after the session started A live Claude process only loaded plugins present when it started. Each reused turn now stats Claude's plugin install record and settings files, and reloads plugins only when those files changed. When the plugin list changes, the composer menu rescans too. Fixes #37712 Co-Authored-By: Claude Opus 5.5 --- .../Adapters/ClaudeAdapterV2.test.ts | 123 +++++++++++++++++- .../Adapters/ClaudeAdapterV2.testkit.ts | 1 + .../Adapters/ClaudeAdapterV2.ts | 119 ++++++++++++++++- ...laudeAutomaticDelivery.integration.test.ts | 4 + .../src/provider/Drivers/ClaudeDriver.ts | 2 +- .../src/provider/Drivers/ClaudeSkills.ts | 45 ++++++- docs/user/providers-claude.md | 3 + 7 files changed, 281 insertions(+), 16 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index 1d549d7f2c18..4f3d73eb7ce3 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -1135,6 +1135,7 @@ describe("ClaudeAdapterV2 Auto-accept edits", () => { readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.void, close: Effect.void, @@ -1258,6 +1259,7 @@ describe("ClaudeAdapterV2 append-system-prompt-file launch argument", () => { readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.void, close: Effect.void, @@ -1547,6 +1549,7 @@ describe("ClaudeAdapterV2 provider installation gate", () => { readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.void, close: Effect.void, @@ -1735,6 +1738,7 @@ const captureSdkExecutablePaths = Effect.fn("captureSdkExecutablePaths")(functio readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.void, close: Effect.void, @@ -1929,6 +1933,7 @@ describe("ClaudeAdapterV2 resume compaction", () => { readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.void, close: Effect.void, @@ -2314,6 +2319,7 @@ describe("ClaudeAdapterV2 attachments", () => { readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.void, close: Queue.shutdown(messages), @@ -2856,6 +2862,7 @@ describe("ClaudeAdapterV2 native fork", () => { readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.void, close: Effect.void, @@ -3205,6 +3212,7 @@ describe("ClaudeAdapterV2 native session identity", () => { readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.void, close: Effect.void, @@ -3550,7 +3558,8 @@ describe("ClaudeAdapterV2 background wake turns", () => { > & Partial>; readonly environment?: NodeJS.ProcessEnv; - readonly onSessionInit?: (cwd: string) => Effect.Effect; + readonly onWorkspaceSkillsChanged?: (cwd: string) => Effect.Effect; + readonly reloadPlugins?: ClaudeAdapterV2.ClaudeAgentSdkQuerySession["reloadPlugins"]; readonly subagentLaunchToolUseId?: string; readonly subagentModel?: string; readonly nativeSessionId?: string; @@ -3626,7 +3635,9 @@ describe("ClaudeAdapterV2 background wake turns", () => { path: yield* Path.Path, random: yield* SecureRandom.SecureRandom, idAllocator, - ...(options?.onSessionInit ? { onSessionInit: options.onSessionInit } : {}), + ...(options?.onWorkspaceSkillsChanged + ? { onWorkspaceSkillsChanged: options.onWorkspaceSkillsChanged } + : {}), ...(options?.routeModelCatalog ? { routeModelCatalog: options.routeModelCatalog } : {}), continuationRequests: { offer: (request) => @@ -3689,6 +3700,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: options?.stopTask ?? (() => Effect.void), interrupt: Effect.void, close: Queue.shutdown(processMessages), @@ -3732,6 +3744,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { callMcpTool: options?.mcp?.callMcpTool ?? (() => Effect.die("unexpected MCP tool call")), listPermissionRules: options?.mcp?.listPermissionRules ?? Effect.succeed([]), + reloadPlugins: options?.reloadPlugins ?? Effect.succeed([]), stopTask: options?.stopTask ?? (() => Effect.void), interrupt: options?.interrupt ?? Effect.void, close: options?.close?.(sdkMessages) ?? Effect.void, @@ -4175,7 +4188,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { const harness = yield* makeWakeHarnessWithOptions({ freshQueueOnReopen: true, close: (queue) => Queue.shutdown(queue), - onSessionInit: (cwd) => + onWorkspaceSkillsChanged: (cwd) => Effect.sync(() => { initCwds.push(cwd); }), @@ -4243,6 +4256,100 @@ describe("ClaudeAdapterV2 background wake turns", () => { ), ); + it.effect("reloads a live session's plugins when plugin files change between turns", () => + Effect.gen(function* () { + const fileSystem = yield* FileSystem.FileSystem; + const configDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-claude-plugins-" }); + const plugin = (name: string) => ({ name, path: `/plugins/${name}` }); + let reloadedPlugins = [plugin("first")]; + let reloads = 0; + let failNextReload = true; + const rescans: Array = []; + const harness = yield* makeWakeHarnessWithOptions({ + settings: { ...DEFAULT_CLAUDE_SETTINGS, homePath: configDir }, + reloadPlugins: Effect.suspend(() => { + reloads += 1; + if (!failNextReload) return Effect.succeed(reloadedPlugins); + failNextReload = false; + return Effect.fail( + new ClaudeAdapterV2.ClaudeAgentSdkQueryRunnerError({ + method: "reloadPlugins", + cause: new Error("reload failed"), + }), + ); + }), + onWorkspaceSkillsChanged: (cwd) => + Effect.sync(() => { + rescans.push(cwd); + }), + }); + const runTurn = Effect.fnUntraced(function* (ordinal: number) { + const event = harness.events.findLast( + (candidate) => candidate.type === "provider_thread.updated", + ); + yield* harness.runtime.startTurn( + makeClaudeTestTurnInput({ + threadId: harness.threadId, + providerThread: + event?.type === "provider_thread.updated" + ? event.providerThread + : harness.providerThread, + now: DateTime.makeUnsafe(0), + attemptId: RunAttemptId.make(`plugin-reload-${ordinal}`), + text: `Turn ${ordinal}`, + attachments: [], + providerTurnOrdinal: ordinal, + }), + ); + yield* harness.offerAndWait( + claudeSdkFrame({ + type: "system", + subtype: "init", + session_id: WAKE_NATIVE_SESSION, + plugins: [plugin("first")], + uuid: `00000000-0000-4000-8000-00000000080${ordinal}`, + }), + ); + yield* harness.offerAndWait( + makeResultFrame({ + uuid: `00000000-0000-4000-8000-00000000090${ordinal}`, + result: "Done.", + }), + ); + yield* Queue.take(harness.terminalReceipts); + }); + + yield* runTurn(1); + yield* runTurn(2); + assert.deepEqual({ reloads, rescans }, { reloads: 0, rescans: ["/workspace"] }); + + yield* fileSystem.makeDirectory(`${configDir}/plugins`); + yield* fileSystem.writeFileString(`${configDir}/plugins/installed_plugins.json`, "{}"); + reloadedPlugins = [plugin("first"), plugin("second")]; + yield* runTurn(3); + assert.deepEqual({ reloads, rescans }, { reloads: 1, rescans: ["/workspace"] }); + // The failed reload is retried on the next turn. + yield* runTurn(4); + assert.deepEqual({ reloads, rescans }, { reloads: 2, rescans: ["/workspace", "/workspace"] }); + + // A settings edit that leaves the plugins as they were reloads without a rescan. + yield* fileSystem.writeFileString(`${configDir}/settings.json`, "{}"); + yield* runTurn(5); + yield* runTurn(6); + assert.deepEqual({ reloads, rescans }, { reloads: 3, rescans: ["/workspace", "/workspace"] }); + }).pipe( + Effect.scoped, + Effect.provide( + Layer.mergeAll( + IdAllocator.layer, + McpProviderSessions.layer, + NodeServices.layer, + NodeCrypto.layer, + ), + ), + ), + ); + it.effect("resumes the session a /clear selected after the Claude process is replaced", () => Effect.gen(function* () { const harness = yield* makeWakeHarnessWithOptions({ @@ -13811,6 +13918,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.void, close: isFirstProcess @@ -14013,6 +14121,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.void, close: Queue.shutdown(sdkMessages), @@ -14225,6 +14334,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.void, close: Queue.shutdown(queue), @@ -17486,6 +17596,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { setPermissionMode: () => Effect.void, renameSession: () => Effect.void, backgroundTasks: () => Effect.succeed(false), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, mcpServerStatus: Effect.die("unexpected MCP server status"), readMcpResource: () => Effect.die("unexpected MCP resource read"), @@ -20786,6 +20897,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.void, close: Queue.shutdown(sdkMessages), @@ -20964,6 +21076,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.void, close: Queue.shutdown(sdkMessages), @@ -21142,6 +21255,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.void, close: Queue.shutdown(sdkMessages), @@ -21341,6 +21455,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.void, close: Effect.sync(() => { @@ -21488,6 +21603,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.void, close: Queue.shutdown(sdkMessages), @@ -21610,6 +21726,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.void, close: Queue.shutdown(sdkMessages), diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.testkit.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.testkit.ts index feac31a89af9..e9ea84cc1231 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.testkit.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.testkit.ts @@ -840,6 +840,7 @@ function makeReplayQueryRunner( }), // Recorded sessions already hold their title, and no replay asserts rename frames. renameSession: () => Effect.void, + reloadPlugins: Effect.succeed([]), stopTask: (taskId) => replayEffect(() => { assertNextOutboundFrame({ type: "query.stop_task", taskId }); diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index 5dcb77f7abdd..78c3f354a495 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -172,6 +172,7 @@ import { } from "../../provider/Drivers/ClaudeSkillDispatch.ts"; import { claudeLaunchArgDirectories, + claudePluginStatePaths, customClaudeApiEndpointHost, discoverClaudeSkills, readClaudeSettingsEnv, @@ -362,6 +363,8 @@ const CLAUDE_SCRIPT_EXTENSIONS = [".js", ".mjs", ".tsx", ".ts", ".jsx"]; // The SDK has no control-request deadline; the CLI waits up to 30 s per MCP server. const CLAUDE_MCP_REGISTRATION_TIMEOUT = "90 seconds"; const CLAUDE_BOOT_TIMEOUT = "5 minutes"; +// Bounds the wait a plugin reload adds before a turn's prompt; the turn proceeds without it. +const CLAUDE_PLUGIN_RELOAD_TIMEOUT = "30 seconds"; // Claude can consume a subagent result before the launching turn ends, leaving // its notification with no native wake turn to answer the continuation. const CLAUDE_WAKE_TURN_START_DEADLINE = "2 minutes"; @@ -674,6 +677,8 @@ export interface ClaudeAgentSdkQuerySession { mode: PermissionMode, ) => Effect.Effect; readonly renameSession: (title: string) => Effect.Effect; + /** Reloads plugins from disk and returns the plugins the session now has. */ + readonly reloadPlugins: Effect.Effect; readonly stopTask: (taskId: string) => Effect.Effect; readonly backgroundTasks: ( toolUseId: string, @@ -704,6 +709,26 @@ export interface ClaudeAgentSdkQuerySession { type ClaudeQueryStreamExit = Exit.Exit; +type ClaudeLoadedPlugins = Awaited>["plugins"]; + +const claudeLoadedPluginsKey = (plugins: ClaudeLoadedPlugins): string => + plugins + .map((plugin) => `${plugin.name}\0${plugin.path}\0${plugin.version ?? ""}`) + .sort() + .join("\n"); + +/** Stats only: compared on every reused turn, so it must not read file contents. */ +const readClaudePluginState = (fileSystem: FileSystem.FileSystem, paths: ReadonlyArray) => + Effect.forEach( + paths, + (filePath) => + fileSystem.stat(filePath).pipe( + Effect.map((info) => `${Option.getOrUndefined(info.mtime)?.getTime()}:${info.size}`), + Effect.orElseSucceed(() => "-"), + ), + { concurrency: "unbounded" }, + ).pipe(Effect.map((states) => states.join("|"))); + export class ClaudeAgentSdkQueryRunnerError extends Schema.TaggedError()( "ClaudeAgentSdkQueryRunnerError", { @@ -1100,6 +1125,11 @@ export type ClaudeAgentSdkProtocolLogEvent = readonly settings: ClaudeFlagSettings; }; } + | { + readonly direction: "outgoing"; + readonly stage: "decoded"; + readonly payload: { readonly type: "query.reload_plugins" }; + } | { readonly direction: "outgoing"; readonly stage: "decoded"; @@ -1836,6 +1866,19 @@ export const layerQueryRunner: Layer.Layer< }), ), ), + reloadPlugins: Effect.tryPromise({ + try: () => queryRuntime.reloadPlugins(), + catch: (cause) => queryRunnerError(cause, "reloadPlugins"), + }).pipe( + Effect.map((result) => result.plugins), + Effect.tap(() => + logProtocolEvent({ + direction: "outgoing", + stage: "decoded", + payload: { type: "query.reload_plugins" }, + }), + ), + ), stopTask: (taskId) => Effect.tryPromise({ try: () => queryRuntime.stopTask(taskId), @@ -5100,6 +5143,10 @@ interface ClaudeLiveQueryContext { // From system/init; feature-detects control requests such as MCP Apps. capabilities: ReadonlySet; claudeCodeVersion: string | undefined; + readonly pluginStatePaths: ReadonlyArray; + // Stats of pluginStatePaths when the session last loaded plugins. + pluginState: string; + loadedPlugins: ClaudeLoadedPlugins | undefined; permissionMode: PermissionMode; stopping: boolean; // A turn that had not attached when the CLI exited fails its start with this cause. @@ -5517,10 +5564,11 @@ export interface ClaudeAdapterV2Options { readonly scopedLimitNames?: Ref.Ref; readonly onUsageLimits?: ManagedServerProvider["applyUsageLimits"]; /** - * Called with the requested cwd on a process's first init message, after its synchronous - * SessionStart hooks have run, so cwd-keyed workspace scans can be refreshed. + * Called with the requested cwd when a session's skills may have changed, so cwd-keyed + * workspace scans can be refreshed: on a process's first init message, after its synchronous + * SessionStart hooks have run, and after a plugin reload changed the session's plugins. */ - readonly onSessionInit?: (cwd: string) => Effect.Effect; + readonly onWorkspaceSkillsChanged?: (cwd: string) => Effect.Effect; /** * Applies Claude Code's reported model ids for a turn's cwd, so turns send ids its backend * accepts. Defaults to the catalog unchanged. @@ -12603,6 +12651,36 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( live.selection = selection; }); + // The CLI loads plugins only at startup, so a live process misses ones installed since. + const reloadChangedPlugins = Effect.fn("ClaudeAdapterV2.reloadChangedPlugins")(function* ( + live: ClaudeLiveQueryContext, + cwd: string | null, + ) { + const state = yield* readClaudePluginState(fileSystem, live.pluginStatePaths); + if (state === live.pluginState) return; + const plugins = yield* live.query.reloadPlugins.pipe( + Effect.timeout(CLAUDE_PLUGIN_RELOAD_TIMEOUT), + Effect.tapError((cause) => + Effect.logWarning("orchestration-v2.claude-plugin-reload-failed", { + nativeThreadId: live.nativeThreadId, + cause, + }), + ), + Effect.option, + ); + // A failed reload keeps the old state, so the next turn retries it. + if (Option.isNone(plugins)) return; + live.pluginState = state; + const unchanged = + live.loadedPlugins !== undefined && + claudeLoadedPluginsKey(plugins.value) === claudeLoadedPluginsKey(live.loadedPlugins); + live.loadedPlugins = plugins.value; + if (unchanged) return; + if (cwd !== null && adapterOptions.onWorkspaceSkillsChanged) { + yield* adapterOptions.onWorkspaceSkillsChanged(cwd); + } + }); + const openQuery = Effect.fnUntraced(function* ( turnInput: ProviderAdapter.ProviderAdapterV2TurnInput, nativeThreadId: string, @@ -12697,6 +12775,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( }), ); } + yield* reloadChangedPlugins(existing, turnInput.runtimePolicy.cwd); return existing; } @@ -12801,6 +12880,20 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( const resolvedTurnCwd = yield* fileSystem .realPath(turnInput.runtimePolicy.cwd ?? ".") .pipe(Effect.orElseSucceed(() => turnInput.runtimePolicy.cwd)); + const pluginStatePaths = yield* Effect.gen(function* () { + const cwd = turnInput.runtimePolicy.cwd; + return yield* claudePluginStatePaths( + adapterOptions.settings, + cwd, + cwd === null ? null : yield* claudeLocalSettingsDirectory(cwd), + adapterOptions.environment, + ); + }).pipe( + Effect.provideService(FileSystem.FileSystem, fileSystem), + Effect.provideService(Path.Path, path), + ); + // Read before the CLI loads plugins, so a change during startup reloads on the next turn. + const pluginState = yield* readClaudePluginState(fileSystem, pluginStatePaths); const openQueryRuntime = queryRunner.open({ threadId: turnInput.threadId, providerSessionId: input.providerSessionId, @@ -12857,6 +12950,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( receivedInit: false, capabilities: new Set(), claudeCodeVersion: undefined, + pluginStatePaths, + pluginState, + loadedPlugins: undefined, permissionMode: queryOptions.permissionMode, stopping: false, exitCause: undefined, @@ -12901,6 +12997,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( context.receivedInit = true; context.capabilities = new Set(message.capabilities ?? []); context.claudeCodeVersion = message.claude_code_version; + context.loadedPlugins = message.plugins; } if ( message.type === "system" && @@ -12936,10 +13033,16 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( } const handled = handleSdkMessage({ query: querySession, message }); const reportedCwd = turnInput.runtimePolicy.cwd; - if (!firstInit || reportedCwd === null || !adapterOptions.onSessionInit) { + if ( + !firstInit || + reportedCwd === null || + !adapterOptions.onWorkspaceSkillsChanged + ) { return handled; } - return adapterOptions.onSessionInit(reportedCwd).pipe(Effect.andThen(handled)); + return adapterOptions + .onWorkspaceSkillsChanged(reportedCwd) + .pipe(Effect.andThen(handled)); }), ), ), @@ -14477,7 +14580,11 @@ export const createClaudeAdapterV2 = Effect.fn("ClaudeAdapterV2Driver.create")( input: ProviderAdapterDriverCreateInput, hooks: Pick< ClaudeAdapterV2Options, - "scopedLimitNames" | "onUsageLimits" | "onSessionInit" | "modelCatalog" | "routeModelCatalog" + | "scopedLimitNames" + | "onUsageLimits" + | "onWorkspaceSkillsChanged" + | "modelCatalog" + | "routeModelCatalog" > = {}, ) { const { instanceId, environment, enabled, config } = input; diff --git a/apps/server/src/orchestration-v2/ClaudeAutomaticDelivery.integration.test.ts b/apps/server/src/orchestration-v2/ClaudeAutomaticDelivery.integration.test.ts index 1fa7047aff42..acbe7024ec70 100644 --- a/apps/server/src/orchestration-v2/ClaudeAutomaticDelivery.integration.test.ts +++ b/apps/server/src/orchestration-v2/ClaudeAutomaticDelivery.integration.test.ts @@ -175,6 +175,7 @@ it.effect.each(deliveries)( readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.die("automatic delivery must never interrupt"), close: Effect.void, @@ -525,6 +526,7 @@ it.effect("applies an effort change to the running Claude query without waiting readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.die("an effort change must not interrupt the turn"), close: Effect.void, @@ -641,6 +643,7 @@ const renamedClaudeSessionTitles = (options: { readonly renameDuringStartup: boo readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.die("a rename must not interrupt the turn"), close: Effect.void, @@ -867,6 +870,7 @@ it.effect("offers a continuation for a later wake after a queued continuation is readMcpResource: () => Effect.die("unexpected MCP resource read"), callMcpTool: () => Effect.die("unexpected MCP tool call"), listPermissionRules: Effect.die("unexpected permission rules read"), + reloadPlugins: Effect.succeed([]), stopTask: () => Effect.void, interrupt: Effect.void, close: Effect.void, diff --git a/apps/server/src/provider/Drivers/ClaudeDriver.ts b/apps/server/src/provider/Drivers/ClaudeDriver.ts index 5bedffe9242b..847b121ef9fc 100644 --- a/apps/server/src/provider/Drivers/ClaudeDriver.ts +++ b/apps/server/src/provider/Drivers/ClaudeDriver.ts @@ -185,7 +185,7 @@ export const ClaudeDriver: ProviderDriver snapshot.applyUsageLimits(update), - onSessionInit: (cwd) => Queue.offer(workspaceRescans, cwd).pipe(Effect.asVoid), + onWorkspaceSkillsChanged: (cwd) => Queue.offer(workspaceRescans, cwd).pipe(Effect.asVoid), modelCatalog, routeModelCatalog: modelRoutes.route, }, diff --git a/apps/server/src/provider/Drivers/ClaudeSkills.ts b/apps/server/src/provider/Drivers/ClaudeSkills.ts index 4fdd3565d11b..018336fa935f 100644 --- a/apps/server/src/provider/Drivers/ClaudeSkills.ts +++ b/apps/server/src/provider/Drivers/ClaudeSkills.ts @@ -520,6 +520,44 @@ const discoverInlinePluginSkillRoots = Effect.fn("discoverInlinePluginSkillRoots return { roots, names }; }); +const installedPluginsPath = Effect.fnUntraced(function* ( + configDirPath: string, + cwd: string | undefined, + environment: NodeJS.ProcessEnv, +) { + const path = yield* Path.Path; + const pluginDirectory = environment.CLAUDE_CODE_PLUGIN_CACHE_DIR; + const pluginsPath = pluginDirectory + ? path.resolve(cwd ?? ".", expandHomePath(pluginDirectory, yield* HostProcess.HomeDirectory)) + : path.join(configDirPath, "plugins"); + return path.join(pluginsPath, "installed_plugins.json"); +}); + +/** + * Files whose change can alter which plugins a Claude session loads. `localSettingsDirectory` + * holds the `settings.local.json` Claude uses for the cwd, the main checkout for a worktree. + */ +export const claudePluginStatePaths = Effect.fn("claudePluginStatePaths")(function* ( + config: Pick, + cwd: string | null, + localSettingsDirectory: string | null, + environment: NodeJS.ProcessEnv, +): Effect.fn.Return, never, Path.Path> { + const workspace = cwd ?? undefined; + const configDirPath = yield* resolveClaudeConfigDirPath(config, environment, workspace); + return [ + yield* installedPluginsPath(configDirPath, workspace, environment), + ...claudeSettingsPaths( + yield* Path.Path, + configDirPath, + workspace, + yield* HostProcess.Platform, + environment, + localSettingsDirectory ?? undefined, + ), + ]; +}); + const discoverPluginSkillRoots = Effect.fn("discoverPluginSkillRoots")(function* ( configDirPath: string, cwd: string | undefined, @@ -530,13 +568,8 @@ const discoverPluginSkillRoots = Effect.fn("discoverPluginSkillRoots")(function* ) { const fileSystem = yield* FileSystem.FileSystem; const path = yield* Path.Path; - const home = yield* HostProcess.HomeDirectory; - const pluginDirectory = environment.CLAUDE_CODE_PLUGIN_CACHE_DIR; - const pluginsPath = pluginDirectory - ? path.resolve(cwd ?? ".", expandHomePath(pluginDirectory, home)) - : path.join(configDirPath, "plugins"); const installed = yield* fileSystem - .readFileString(path.join(pluginsPath, "installed_plugins.json")) + .readFileString(yield* installedPluginsPath(configDirPath, cwd, environment)) .pipe( Effect.flatMap(Schema.decodeUnknownEffect(InstalledPlugins)), Effect.orElseSucceed(() => undefined), diff --git a/docs/user/providers-claude.md b/docs/user/providers-claude.md index 5d4295a94263..920f5ba890a4 100644 --- a/docs/user/providers-claude.md +++ b/docs/user/providers-claude.md @@ -102,6 +102,9 @@ still be started by you. Invoke those one per message: Claude directly runs only the last named skill and may try to start earlier ones through its Skill tool, which refuses skills reserved for manual invocation. +A plugin you install, enable, or update while a thread is open loads with that +thread's next message, without restarting the session. + ## Task lists To show Claude task lists in the web and desktop apps, add