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,