Skip to content

Edit

The Edit tool makes precise, targeted text replacements in local files. Unlike overwriting a file entirely, Edit replaces only the exact text you specify — leaving everything else untouched.

  • Finds a specific string or block of text in a file
  • Replaces it with new content
  • Leaves the rest of the file unchanged
  • Returns confirmation of the edit

The AI uses Edit when:

  • You ask it to change a specific function, variable, or block of code
  • A targeted fix is needed without rewriting the entire file
  • It has already read a file and identified exactly what needs to change

“Fix the bug in the parseDate function in src/utils.ts — it’s not handling null input.”

The AI will Read the file to locate the function, then use Edit to replace just the affected lines with the corrected implementation.

ToolUse case
EditTargeted replacement of a specific piece of text
WriteCreate a new file or completely overwrite an existing one

Edit is preferred when modifying existing files — it’s safer and more precise, reducing the risk of accidentally overwriting unrelated content.

  • For best results, the AI will typically Read the file first to confirm the exact text before editing
  • Edit works on any text-based file format
  • If the target text appears more than once, the AI will use enough surrounding context to uniquely identify the right occurrence