Skip to main content

Editing Files

Module: Core Features | Lesson: 3 of 7 | Time: ~10 minutes

What You Will Learn

  • How the Edit tool creates and modifies files
  • How to review proposed changes before accepting
  • How to accept or reject edits Claude suggests

Prerequisites

Why This Matters

Reading files is useful, but the real power of Claude Code comes when it can create and change files for you. Whether you need to write a brand new file from scratch or update a single line in an existing one, Claude has tools designed for exactly that. Understanding how these tools work -- and how to review what Claude proposes -- keeps you in full control.

Two Tools for Editing: Write and Edit

Claude has two different tools for working with files:

ToolWhat It DoesBest For
WriteCreates a brand new file, or completely replaces an existing fileNew files, full rewrites
EditMakes targeted changes to specific parts of an existing fileSmall fixes, line changes, insertions

Think of it this way: Write is like opening a blank document and typing the whole thing. Edit is like using Find and Replace to change just the parts that need updating.

The Write Tool

When Claude creates a new file or needs to rewrite an entire file, it uses the Write tool. You will see something like this:

 ─ Write file: shopping-list.txt

Created shopping-list.txt with the following contents:

1 Grocery Shopping List
2 - Eggs
3 - Milk
4 - Bread
5 - Butter

You can trigger this by asking Claude naturally:

> Create a file called shopping-list.txt with some common groceries
> Write a new HTML page called index.html with a basic template
> Make a new Python script that prints "Hello World"

The Edit Tool

When Claude needs to change just part of an existing file, it uses the Edit tool. This is more surgical -- it finds the exact text to change and replaces it. You will see something like:

 ─ Edit file: shopping-list.txt
Replace: "- Milk"
With: "- Oat Milk"

You can trigger this by asking:

> Change "Milk" to "Oat Milk" in shopping-list.txt
> Add "- Cheese" to the end of the shopping list
> Remove the line about Butter from shopping-list.txt
When Does Claude Use Which Tool?

You do not need to tell Claude which tool to use. Just describe what you want, and Claude picks the right one:

  • "Create a new file..." -- Claude uses Write
  • "Change line 5 to..." -- Claude uses Edit
  • "Rewrite the entire file..." -- Claude uses Write
  • "Add a line after..." -- Claude uses Edit

Permission Prompts

Before Claude modifies any file, it asks for your permission. You will see a prompt like this:

Claude wants to edit file: shopping-list.txt

Allow? (Y)es / (N)o / (A)lways allow Edit

You have three choices:

OptionWhat It Does
Y (Yes)Allow this one change. Claude will ask again next time.
N (No)Reject this change. The file stays untouched.
A (Always allow)Allow this tool for the rest of the session without asking again.
Choose "Always Allow" Carefully

The "Always allow" option is convenient but means Claude will not ask before making future edits in this session. If you are still learning, it is better to press Y each time so you can review every change.

Reviewing Diffs (What Changed)

When Claude edits an existing file, it shows you a diff -- a summary of what changed. A diff highlights exactly which lines were removed and which were added:

 ─ Edit file: shopping-list.txt

3 - Bread
- 4 - Milk
+ 4 - Oat Milk
5 - Butter

Here is how to read it:

  • Lines starting with - (often shown in red) are removed
  • Lines starting with + (often shown in green) are added
  • Lines with no prefix are unchanged context lines shown for reference

This makes it easy to see exactly what Claude plans to change before you approve it.

Accepting or Rejecting Changes

After reviewing the diff, you decide:

  • Press Y if the change looks correct. Claude applies it immediately.
  • Press N if something is wrong. Claude does not touch the file, and you can explain what you actually wanted.

If you reject a change, you can tell Claude what to do differently:

> No, don't change Milk to Oat Milk. Instead, add Almond Milk as a new item at the bottom.

Claude will propose a new edit based on your feedback.

You Are Always in Control

Claude never changes a file without your approval (unless you have chosen "Always allow" for that tool). If you are ever unsure about a proposed change, press N and ask Claude to explain what it wants to do and why.

Common Questions

Q: Can Claude create files in any folder? Yes, as long as Claude Code has access to that location. By default, Claude works within the folder where you launched it. If you need a file created elsewhere, provide the full path: "Create a file at C:\Users\MyName\Documents\notes.txt".

Q: What if I want to undo a change Claude made? If Claude just made the change, you can ask "Undo the last edit to shopping-list.txt." If you are using Git (a version control system you will learn about later), you can also revert changes through Git commands. For now, the safest approach is to review each change carefully before accepting.

Q: Can Claude create folders too? Claude cannot create folders directly with the Write tool, but it can run a command to create folders (using the Bash tool, covered in the next lesson). If you ask Claude to create a file in a folder that does not exist yet, it will often create the folder automatically or tell you it needs to.

Try It Yourself

Step 1: Create a Practice File

Start Claude Code in your practice folder and ask it to create a new file:

> Create a file called my-notes.txt with three lines:
> Line 1: Today's Tasks
> Line 2: - Learn about editing files
> Line 3: - Practice with Claude Code

Review the Write tool output and press Y to approve.

Step 2: Make a Small Edit

Now ask Claude to make a change:

> Add a new line at the end of my-notes.txt that says "- Take a break"

Look at the diff carefully. You should see the new line being added. Press Y to accept.

Step 3: Reject an Edit

Ask Claude for a change, but this time reject it:

> Change "Learn about editing files" to "Go grocery shopping" in my-notes.txt

When the permission prompt appears, press N. Then tell Claude:

> Actually, change it to "Master the editing tools" instead

Step 4: Verify the Final File

> Read my-notes.txt and show me the current contents

Confirm that your file has the changes you accepted and does not have the change you rejected.

Checkpoint

If you successfully created a file, edited it, rejected a change, and verified the final contents, you understand how Claude's file editing tools work.

What You Learned

  • Write tool: Creates new files or completely replaces existing ones
  • Edit tool: Makes targeted changes to specific parts of a file
  • Permission prompts: Claude always asks before changing a file (Yes / No / Always allow)
  • Diffs: Show exactly what will change with - for removals and + for additions
  • Rejecting changes: Press N and give Claude new instructions to try again
  • You stay in control: No file changes happen without your explicit approval

Help Us Improve

How was this lesson? Take 2 minutes to share your feedback — it helps us make the tutorials better for everyone.

Give Feedback →

Next Up

Next: Running Commands