diff --git a/src/plugin-handlers/config-handler.ts b/src/plugin-handlers/config-handler.ts index 0b0eb9d3..41adbaf2 100644 --- a/src/plugin-handlers/config-handler.ts +++ b/src/plugin-handlers/config-handler.ts @@ -120,15 +120,19 @@ export function createConfigHandler(deps: ConfigHandlerDeps) { if (pluginsEnabled) { const timeoutMs = pluginConfig.experimental?.plugin_load_timeout_ms ?? 10000; try { - const timeoutPromise = new Promise((_, reject) => - setTimeout(() => reject(new Error(`Plugin loading timed out after ${timeoutMs}ms`)), timeoutMs) - ); + let timeoutId: ReturnType; + const timeoutPromise = new Promise((_, reject) => { + timeoutId = setTimeout( + () => reject(new Error(`Plugin loading timed out after ${timeoutMs}ms`)), + timeoutMs, + ); + }); pluginComponents = await Promise.race([ loadAllPluginComponents({ enabledPluginsOverride: pluginConfig.claude_code?.plugins_override, }), timeoutPromise, - ]); + ]).finally(() => clearTimeout(timeoutId)); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); log("[config-handler] Plugin loading failed", { error: errorMessage });