From 4b8f8a8b1f82134382a74252e8aa943288ccab5c Mon Sep 17 00:00:00 2001 From: Charles Vien Date: Tue, 7 Apr 2026 11:35:50 -0700 Subject: [PATCH] Show "edit" instead of "create" in permission prompt for existing files --- .../adapters/claude/conversion/tool-use-to-acp.ts | 14 +++++++++++--- .../claude/permissions/permission-handlers.ts | 5 ++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/agent/src/adapters/claude/conversion/tool-use-to-acp.ts b/packages/agent/src/adapters/claude/conversion/tool-use-to-acp.ts index f22292b14..c66017a3f 100644 --- a/packages/agent/src/adapters/claude/conversion/tool-use-to-acp.ts +++ b/packages/agent/src/adapters/claude/conversion/tool-use-to-acp.ts @@ -226,11 +226,19 @@ export function toolInfoFromToolUse( : undefined; const contentStr = input?.content ? String(input.content) : undefined; if (writeFilePath) { - const oldContent = + let oldContent: string | null = null; + if ( options?.cachedFileContent && writeFilePath in options.cachedFileContent - ? options.cachedFileContent[writeFilePath] - : null; + ) { + oldContent = options.cachedFileContent[writeFilePath]; + } else { + try { + oldContent = fs.readFileSync(writeFilePath, "utf-8"); + } catch { + // File doesn't exist — genuinely a new file + } + } contentResult = toolContent() .diff(writeFilePath, oldContent, contentStr ?? "") .build(); diff --git a/packages/agent/src/adapters/claude/permissions/permission-handlers.ts b/packages/agent/src/adapters/claude/permissions/permission-handlers.ts index 0013679f6..d8cabb956 100644 --- a/packages/agent/src/adapters/claude/permissions/permission-handlers.ts +++ b/packages/agent/src/adapters/claude/permissions/permission-handlers.ts @@ -338,7 +338,10 @@ async function handleDefaultPermissionFlow( suggestions, } = context; - const toolInfo = toolInfoFromToolUse({ name: toolName, input: toolInput }); + const toolInfo = toolInfoFromToolUse( + { name: toolName, input: toolInput }, + { cachedFileContent: context.fileContentCache, cwd: session?.cwd }, + ); const options = buildPermissionOptions( toolName,