@@ -99,6 +99,7 @@ WINDOWS NOTES:
9999- File paths should use forward slashes (/) for cross-platform compatibility
100100- On Windows, absolute paths start with drive letters (C:/) but forward slashes work throughout
101101- File permissions are handled automatically by the Go runtime
102+- Always assumes \n for line endings. The tool will handle \r\n conversion automatically if needed.
102103
103104Remember: when making multiple file edits in a row to the same file, you should prefer to send all edits in a single message with multiple calls to this tool, rather than multiple messages with a single call each.`
104105)
@@ -299,7 +300,7 @@ func (e *editTool) deleteContent(ctx context.Context, filePath, oldString string
299300 return ToolResponse{}, fmt.Errorf("failed to read file: %w", err)
300301 }
301302
302− oldContent := string(content)
303+ oldContent, isCrlf := fsext.ToUnixLineEndings(string(content))
303304
304305 var newContent string
305306 var deletionCount int
@@ -356,6 +357,10 @@ func (e *editTool) deleteContent(ctx context.Context, filePath, oldString string
356357 return ToolResponse{}, permission.ErrorPermissionDenied
357358 }
358359
360+ if isCrlf {
361+ newContent, _ = fsext.ToWindowsLineEndings(newContent)
362+ }
363+
359364 err = os.WriteFile(filePath, []byte(newContent), 0o644)
360365 if err != nil {
361366 return ToolResponse{}, fmt.Errorf("failed to write file: %w", err)
@@ -428,7 +433,7 @@ func (e *editTool) replaceContent(ctx context.Context, filePath, oldString, newS
428433 return ToolResponse{}, fmt.Errorf("failed to read file: %w", err)
429434 }
430435
431− oldContent := string(content)
436+ oldContent, isCrlf := fsext.ToUnixLineEndings(string(content))
432437
433438 var newContent string
434439 var replacementCount int
@@ -487,6 +492,10 @@ func (e *editTool) replaceContent(ctx context.Context, filePath, oldString, newS
487492 return ToolResponse{}, permission.ErrorPermissionDenied
488493 }
489494
495+ if isCrlf {
496+ newContent, _ = fsext.ToWindowsLineEndings(newContent)
497+ }
498+
490499 err = os.WriteFile(filePath, []byte(newContent), 0o644)
491500 if err != nil {
492501 return ToolResponse{}, fmt.Errorf("failed to write file: %w", err)