# Edit Tool

> The tool that swaps one exact piece of text in a file.

**Field:** Artificial Intelligence  
**Category:** Claude Code  
**Also known as:** Edit, Claude Code Edit tool, old_string new_string

## Think of it like

It is like rubbing out one word and writing a new one.

## Definition

The Edit tool changes one part of a file. It takes a piece of old text and the new text to put in its place. The old text must match the file exactly, down to the spaces. It must also appear only once, unless Claude asks to replace every copy. Edit does not use patterns or guess. An Edit rule with a path also covers Write and NotebookEdit.

## Example

Jack asks Claude to rename one setting. Claude uses Edit to swap that one line, and the rest of the file stays as it was.

## Example code

```json
{"permissions": {"allow": ["Edit(./src/**)"]}}
```

Let Claude change files in src and not ask.

## Why it matters

Small, exact changes are easy to review and hard to get wrong.

## Common mistake

Expecting a near match to work. One space off and the edit fails, so Claude reads the file first.

## Three principles

- **Old text, new text.** An exact swap.
- **Must be unique.** Or replace all.
- **No guessing.** No patterns.

## Related terms

- [Write Tool](https://learn.benibix.com/term/ai/write-tool)
- [Read Tool](https://learn.benibix.com/term/ai/read-tool)
- [NotebookEdit Tool](https://learn.benibix.com/term/ai/notebook-edit-tool)
- [Claude Code Checkpoint](https://learn.benibix.com/term/ai/claude-code-checkpoint)

## Told apart from

- [Edit vs Write](https://learn.benibix.com/compare/edit-tool-vs-write-tool): People often think Write can change part of a file. It cannot. Write puts in a whole new file and throws the old text away. Edit swaps one exact piece of text and leaves the rest alone. So Claude uses Write for a new file and Edit for a small fix. A rule for Edit on a folder covers Write there too.

## Taught in

- [Claude Code File Tools](https://learn.benibix.com/learn/ai-claude-code/claude-code-file-tools): Claude Code, 9/16

![Glob finds files by name, Grep finds lines inside them, Read opens one, then Edit changes a part or Write replaces it all.](https://learn.benibix.com/diagrams/ct-file-tools.svg)

---

Source: https://learn.benibix.com/term/ai/edit-tool
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
