diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 0164952d4c..a118b71f95 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -775,6 +775,7 @@ export class Config implements McpContext, AgentLoopContext { private mcpServers: Record | undefined; private readonly mcpEnablementCallbacks?: McpEnablementCallbacks; private activeExtensionContext?: string; + private initializedPlanDirs = new Set(); private readonly extensionPlanDirs: Record; private userMemory: string | HierarchicalMemory; private geminiMdFileCount: number; @@ -2249,6 +2250,11 @@ export class Config implements McpContext, AgentLoopContext { getPlansDir(): string { const plansDir = this.storage.getPlansDir(this.getActiveExtensionPlanDir()); + + if (this.initializedPlanDirs.has(plansDir)) { + return plansDir; + } + try { if (!fs.existsSync(plansDir)) { fs.mkdirSync(plansDir, { recursive: true }); @@ -2264,6 +2270,7 @@ export class Config implements McpContext, AgentLoopContext { // Ignore failures in mock environments } this.workspaceContext.addDirectory(realPlansDir); + this.initializedPlanDirs.add(plansDir); } catch (e: unknown) { const errorMessage = e instanceof Error ? e.message : String(e); throw new Error(