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.
What It Does
Section titled “What It Does”- 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
When It’s Used
Section titled “When It’s Used”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
Example
Section titled “Example”“Fix the bug in the
parseDatefunction insrc/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.
How It Differs from Write
Section titled “How It Differs from Write”| Tool | Use case |
|---|---|
| Edit | Targeted replacement of a specific piece of text |
| Write | Create 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