File tree Expand file tree Collapse file tree
packages/agent/src/adapters/claude Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -226,11 +226,19 @@ export function toolInfoFromToolUse(
226226 : undefined ;
227227 const contentStr = input ?. content ? String ( input . content ) : undefined ;
228228 if ( writeFilePath ) {
229- const oldContent =
229+ let oldContent : string | null = null ;
230+ if (
230231 options ?. cachedFileContent &&
231232 writeFilePath in options . cachedFileContent
232- ? options . cachedFileContent [ writeFilePath ]
233- : null ;
233+ ) {
234+ oldContent = options . cachedFileContent [ writeFilePath ] ;
235+ } else {
236+ try {
237+ oldContent = fs . readFileSync ( writeFilePath , "utf-8" ) ;
238+ } catch {
239+ // File doesn't exist — genuinely a new file
240+ }
241+ }
234242 contentResult = toolContent ( )
235243 . diff ( writeFilePath , oldContent , contentStr ?? "" )
236244 . build ( ) ;
Original file line number Diff line number Diff line change @@ -338,7 +338,10 @@ async function handleDefaultPermissionFlow(
338338 suggestions,
339339 } = context ;
340340
341- const toolInfo = toolInfoFromToolUse ( { name : toolName , input : toolInput } ) ;
341+ const toolInfo = toolInfoFromToolUse (
342+ { name : toolName , input : toolInput } ,
343+ { cachedFileContent : context . fileContentCache , cwd : session ?. cwd } ,
344+ ) ;
342345
343346 const options = buildPermissionOptions (
344347 toolName ,
You can’t perform that action at this time.
0 commit comments