Edit Tool - Claude Code
Targeted edits to specific sections without rewriting entire files.
Edit is the workhorse for modifying existing files. It performs exact string replacements so you review a diff, not a whole new file.
What it does
Edit takes a file path, an old string, and a new string. It replaces the first occurrence - or all occurrences with replace_all - and leaves everything else untouched. Because it's a diff-style edit, the change is easy to review and less likely to introduce regressions than a full-file Write.
When to use it
- Fixing bugs in specific lines or blocks.
- Renaming variables or functions across a file with
replace_all. - Tweaking config values without rewriting config.
- Any change where the rest of the file should stay byte-identical.
Gotchas
- The
old_stringmust be unique in the file unless you usereplace_all. Include surrounding context to make it unique. - Indentation must match exactly - tabs versus spaces will break a match.
- Edit requires a prior Read of the file. Claude won't edit sight unseen.
Official docs: https://code.claude.com/docs/en/tools-reference.md
Technical content at the intersection of AI and development. Building with AI agents, Claude Code, and modern dev tools - then showing you exactly how it works.
Get the weekly deep dive
Tutorials on Claude Code, AI agents, and dev tools - delivered free every week.
Was this helpful?




