File Operations¶
Learn how Claude Code CLI reads, creates, and modifies files directly on your filesystem.
What You'll Learn¶
- How Claude CLI reads files from disk
- Creating new files in your terminal session
- Editing existing files directly
- Working with multiple files
- Understanding the permission system
How the CLI Accesses Files¶
Unlike the Claude web interface where you copy/paste code, Claude Code CLI has direct filesystem access in your working directory. It uses specialized tools internally:
| Tool | Purpose |
|---|---|
| Read | View file contents |
| Write | Create new files |
| Edit | Modify existing files |
| Glob | Find files by pattern |
| Grep | Search file contents |
You don't call these directly - just describe what you want.
Reading Files¶
Single File¶
Claude reads and displays the file.
Claude reads the file and explains it.
Multiple Files¶
Claude reads both and shows differences.
Claude finds and summarizes test files.
Partial Reading¶
For large files:
Claude can focus on specific sections.
Creating Files¶
Simple Creation¶
Claude will: 1. Show you the proposed file content 2. Ask for permission to create it 3. Create the file
With Specifications¶
> Create a React component called Button with these props:
- label (string)
- onClick (function)
- disabled (boolean, optional)
Claude generates appropriate code based on context.
Multiple Files¶
> Create a basic Express server with:
- index.js (main server)
- routes/api.js (API routes)
- middleware/auth.js (auth middleware)
Claude creates the structure and files.
Editing Files¶
Direct Edits¶
Claude finds the line and makes the change.
Descriptive Edits¶
Claude understands the function and adds appropriate try/catch.
Refactoring¶
Claude updates all occurrences.
Adding to Files¶
Claude finds the class and adds the method.
The Permission System¶
Claude asks before modifying your filesystem:
Claude wants to create file: src/utils/helpers.js
--- Proposed content ---
export function formatDate(date) {
return date.toISOString().split('T')[0];
}
------------------------
Allow? (y/n/e)
Options:
- y - Yes, make the change
- n - No, don't make it
- e - Edit the proposed change first
Trust Modes¶
For experienced users, you can adjust permissions:
Practical Patterns¶
Pattern 1: Explore Then Edit¶
Read first to understand context.
Pattern 2: Batch Operations¶
Claude processes multiple files.
Pattern 3: Find and Replace¶
Claude searches and replaces across files.
Pattern 4: Template Creation¶
Claude reads the template and creates a similar file.
Working with Different File Types¶
Code Files¶
Configuration¶
Documentation¶
Data Files¶
Try It Yourself¶
Exercise: File Operations Practice¶
-
Create a practice directory:
-
Create some files:
-
Read and understand:
-
Make edits:
-
Create related files:
-
Verify your work:
Exercise: Refactoring¶
-
Ask Claude to create a messy file:
-
Refactor it:
-
Compare:
Best Practices¶
Be Specific¶
# Vague
> Fix the file
# Specific
> In auth.js, the validateToken function returns undefined when
the token is expired. It should throw an ExpiredTokenError instead.
Provide Context¶
> I'm using Express.js and MongoDB. Create a user registration
endpoint that hashes passwords with bcrypt.
Verify Changes¶
Use Relative Paths¶
Claude understands your project structure.
What's Next?¶
Now that you can work with files, learn how to prompt Claude effectively in 04-asking-questions.
Summary: - Claude reads files automatically when you reference them - Ask to create files, and Claude shows you what it'll write before doing it - Edit by describing what you want changed - no need for exact syntax - The permission system protects you from unwanted changes - Be specific about what files you mean and what changes you want
Learning Resources¶
Featured Video¶
NetworkChuck: AI in the Terminal - File Operations (3.6M subscribers)
Learn how Claude Code reads, creates, and modifies files directly on your filesystem with permission handling.
Additional Resources¶
| Type | Resource | Description |
|---|---|---|
| 🎬 Video | Claude Code File Editing Guide | All About AI - File operations deep dive |
| 📚 Official Docs | Security & Permissions | File access controls documentation |
| 📖 Tutorial | DataCamp File Operations | Refactoring and file editing examples |
| 🎓 Free Course | Anthropic Academy | Official free courses |
| 💼 Commercial | GitHub Copilot Course | AI file editing patterns |