# When should Claude Code use Edit instead of Write, and how can I avoid collateral changes?

Exam: CCAR-F — Claude Certified Architect - Foundations (CCAR-F)
Knowledge domain: Claude Code Configuration & Workflows
Updated: 2026-12-04T01:16:40.046412+00:00
HTML: https://learningpathx.com/faq/CCAR-F/ccarf-edit-versus-write.html

## Also asked as

- How do I make a small Claude Code file change without replacing unrelated content?
- What should I do when an Edit anchor is ambiguous or a file read is incomplete?

Use Edit for a targeted change to an existing file. Use Write when creating a file or supplying its complete replacement content. Before replacing existing content, obtain enough current evidence to preserve every unrelated part.

Edit matches exact `old_string` text, including whitespace and indentation. Choose an anchor that occurs once and includes enough surrounding context to identify the intended location. If `return 2` appears in both the active and preview functions, anchor the active function rather than replacing every occurrence. Set `replace_all` only when the approved change applies to all matches.

If the anchor fails or the file changed, inspect the current content and refine the change. A tool's ability to accept a matching edit does not prove that surrounding assumptions remain valid. Coordinate dependent writes and recheck changes made by another process.

Write supplies the entire new file; it does not append or merge unseen content. A truncated or partial read cannot support a replacement that assumes the missing tail is irrelevant. Retrieve the complete current file and preserve unrelated material before using a justified full replacement.

Claude Code's enforced read-before-edit and overwrite checks vary by model and file type. Current documentation requires a complete qualifying read for notebooks and files previously seen only in a partial view. An accepted operation still needs an adequate baseline and the right target authorization. Do not switch tools to evade an access denial.

Afterward, read the changed region, inspect the diff, and run proportionate checks. For the two-function example, verify that the active value changed and the preview value stayed the same. A successful edit or write confirms a file operation; the diff and checks establish whether it met the requested behavior.

[Claude Code Edit behavior](https://code.claude.com/docs/en/tools-reference#edit-tool-behavior) · [Write behavior](https://code.claude.com/docs/en/tools-reference#write-tool-behavior)

Source: [Select and apply built-in tools (Read, Write, Edit, Bash, Grep, Glob) effectively](https://learningpathx.com/material/CCAR-F/select-and-apply-built-in-tools-read-write-edit-bash-grep-glob-effectively.html)
