Working with Files
Claude Code interacts with your filesystem through a set of specialized tools for reading, editing, writing, and searching files. Understanding how these tools work helps you collaborate with Claude more effectively and maintain full control over changes to your codebase.
File Tools Overview
Claude Code uses four primary tools for file operations:
Read
The Read tool opens a file and loads its contents into context. Claude uses this to understand existing code before making changes.
Read /src/components/Header.tsx
Claude will read files automatically when it needs context, but you can also ask it to read specific files by mentioning them in your prompt.
Edit
The Edit tool applies targeted changes to an existing file using a diff-based approach. Instead of rewriting the entire file, Claude specifies the exact lines to change.
Edit /src/components/Header.tsx
- Old line content
+ New line content
This produces a clear diff that you can review before approving. Only the modified sections are changed while the rest of the file remains untouched.
Write
The Write tool creates a new file or completely replaces the contents of an existing file. Claude uses this for new files or when a file needs substantial restructuring.
Write /src/components/Footer.tsx
(entire file content)
Glob and Grep
Claude can search your project using two tools:
- Glob finds files by name pattern. For example,
*.tsxfinds all TypeScript React files. - Grep searches file contents for matching text or patterns, similar to running grep on the command line.
These tools help Claude locate relevant files before reading or editing them.
The Approval Flow
When Claude wants to modify a file, it presents the proposed change and waits for your approval. The flow works like this:
- Claude proposes an edit or write operation with a diff preview.
- You review the changes shown in the terminal.
- You approve, reject, or ask for modifications.
This keeps you in control. No file is changed without your explicit consent unless you have configured auto-approval for certain operations.
Asking Claude to Modify Files
Be specific when asking Claude to work with files. Good prompts include file paths and clear descriptions of what you want:
Add a loading spinner to /src/components/Dashboard.tsx
that shows while the data query is pending.
Refactor /src/utils/api.ts to use async/await
instead of .then() chains.
Create a new component at /src/components/ErrorBanner.tsx
that accepts a message prop and displays it in a red alert box.
Tips for File Operations
- Mention file paths explicitly so Claude does not have to search for them.
- Review diffs carefully before approving, especially for large changes.
- Use git to track changes. If something goes wrong, you can always revert.
- Break large changes into steps. Ask Claude to modify one file at a time for easier review.
- Let Claude search. If you are unsure where something is, ask Claude to find it using Glob or Grep rather than hunting for it yourself.