Lesson 6Tools
File Operations
Read, Write, Edit
Read
Reads files, images, PDFs and notebooks
Write
Creates new files or completely replaces
Edit
Precise string replacements in existing files
Read — File Reading
The Read tool reads file contents and can handle various formats:
Text files.ts, .js, .py, .md, etc.
Images.png, .jpg, .gif, .webp
PDF.pdf
Jupyter Notebooks.ipynb
JSON/YAML.json, .yaml, .yml
# Usage examples:
> Read the file src/auth.ts
> Show me the screenshot error.png
> Analyze the PDF document
📖 Read can read up to 2000 lines by default. For larger files, use offset and limit.
Edit — Precise Editing
Edit replaces specific strings in a file. Requires exact text match:
# Claude executes:
Edit file: src/utils.ts
- old_string: "return null;"
+ new_string: "return data ?? null;"
When to use
- • Fixing bugs
- • Adding imports
- • Refactoring functions
- • Updating constants
Limitations
- • old_string must be unique
- • File must exist
- • Requires prior Read
Write — File Creation
Write creates a new file or completely overwrites an existing one:
> Create a new Button component
Write file: src/components/Button.tsx
import React from 'react';
export const Button = ({ children }) => {
return <button>{children}</button>;
};
⚠️ Write completely replaces file contents. Use Edit for modifying existing files.
Edit vs Write: When to Use Which
Edit
Precise changes in existing file
Examples:
- • Fix bug in function
- • Add import
- • Rename variable
✓ Shows diff, Safe, Preserves formatting
✗ Only for existing files
Write
Creating new file or complete replacement
Examples:
- • Create new component
- • Generate config
- • Write test from scratch
✓ For new files, Full control
✗ Overwrites everything, Need to be careful
Best Practices
- 1.Claude always reads file before editing — this ensures accuracy
- 2.Prefer Edit for existing files — it's safer and shows diff
- 3.Use Write only for new files or complete regeneration
- 4.For large files, specify particular lines or functions
This lesson is part of a structured LLM course.
My Learning Path