Working with Files

Master reading, creating, and editing files through natural conversation. Claude Code works with your real files—every change is immediate and visible in your editor.

Reading Files

The simplest and most common operation is asking Claude to read and explain a file. You do not need to copy-paste code into the chat—Claude can read files directly from your project.

Asking Claude to Read and Explain

Simply reference a file in your message. Claude will locate it, read the contents, and respond based on what it finds.

> Explain what src/utils/auth.ts does

> What does the package.json say about our dependencies?

> Read the README and tell me what this project is about

> What's in the .env.example file?

Claude intelligently handles this. If you say "read the auth file," Claude will search your project for files related to authentication, read the most relevant one, and explain its contents. You do not need to know the exact file path.

Reading Multiple Files

Claude can read several files at once and synthesize information across them. This is extremely useful for understanding how pieces of your project connect.

> Read all the API route files and summarize what endpoints we have

> Compare the types in types.ts with how they're used in the components

> Look at our database schema and the API routes — are there any mismatches?

Creating New Files

Ask Claude to create files and it will write them directly to your project. The files appear on disk immediately—you will see them in your editor's file explorer and they are ready to use.

Simple File Creation

> Create a new React component called UserProfile in src/components/

> Add a .gitignore file with standard Node.js ignores

> Create a TypeScript interface for our User model in src/types/user.ts

Claude will ask for permission before writing to disk (depending on your permission mode). You will see exactly what content Claude wants to write before it is saved.

Creating Files with Context

Claude can study your existing code and create new files that match your project's patterns and conventions. This is where it really shines.

> Look at the existing components in src/components and create a new
  UserSettings component that follows the same patterns

> We have API routes for users and posts. Create a similar one for comments.

> Generate a test file for src/utils/validators.ts following our
  existing test conventions
Tip
The more context Claude has about your project, the better the files it creates. If your project has a CLAUDE.md with coding conventions, Claude will follow those conventions automatically when creating new files.

Editing Existing Files

Editing is where Claude Code becomes a true productivity multiplier. Rather than making changes yourself line by line, you describe what you want and Claude modifies the file.

Targeted Edits

Ask Claude to make specific changes. Claude will read the file, apply only the necessary edits, and leave the rest of the file untouched.

> Add error handling to the login function in src/auth.ts

> Change the background color of the header from blue to indigo

> Add a "createdAt" field to the User interface

> Fix the typo in the footer — "copywrite" should be "copyright"

Refactoring

Claude excels at refactoring tasks that would take you significant time to do manually.

> Convert this class component to a functional component with hooks

> Replace all var declarations with const or let

> Extract the validation logic from this 200-line function into
  separate helper functions

> Rename the "data" variable to something more descriptive everywhere
  it's used in this file

Multi-File Edits

Claude can make coordinated changes across multiple files. This is especially useful when a change in one file requires corresponding changes elsewhere.

> Rename the "UserData" type to "UserProfile" everywhere it's used

> Add a "phone" field to the User type, the database schema,
  the API handler, and the registration form

> Move the utility functions from utils.ts into separate files
  by category and update all the imports

Real Example: Organize a Messy Folder

Let's walk through a realistic scenario. You have a src/utils folder that has grown messy over time—20 files with no organization, inconsistent naming, and some duplicate logic.

1

Assess the situation

Start by asking Claude to understand what you have:

> Look at all the files in src/utils and give me a summary
  of what each one does. Are there any duplicates or files
  that should be combined?

Claude reads every file, identifies patterns, and reports back with a clear analysis.

2

Plan the reorganization

Ask Claude to propose a structure before making changes:

> Propose a new organization for these utils. Group related
  functions together and suggest folder names. Don't make
  changes yet — just show me the plan.

Claude will propose something like grouping files into utils/string/,utils/date/, utils/validation/, and so on.

3

Execute the plan

Once you approve the plan, let Claude do the work:

> Go ahead with that plan. Move the files, merge any
  duplicates, and update all imports across the project.

Claude will create the new folder structure, move files, merge duplicate functions, create proper index files, and update every import statement across your codebase.

4

Verify the result

Ask Claude to confirm everything is clean:

> Run the TypeScript compiler and tests to make sure nothing
  broke during the reorganization.

File Permissions and What Claude Can't Do

Claude Code operates within the same permission system as your user account on your computer. There are some important boundaries to understand.

What Claude Can Do

  • Read, create, edit, and delete files within your project directory
  • Create new directories and nested folder structures
  • Run terminal commands (build tools, test runners, git, etc.)
  • Install packages via npm, pip, or other package managers
  • Execute scripts and programs

What Claude Cannot Do

  • Access files you do not have permission to access (respects OS-level permissions)
  • Interact with GUI applications (cannot click buttons, cannot open browser tabs)
  • Access the internet to download files or call APIs (unless it runs a CLI command that does)
  • Run commands that require interactive input (like a password prompt mid-command)
  • Operate outside your terminal session (cannot access other users' files)

Permission Prompts

By default, Claude Code asks for your permission before writing files or running commands. You will see a prompt like:

Claude wants to edit src/components/Header.tsx

Allow? (y/n/always)

This gives you a chance to review what Claude is about to do before it happens. You can type y to allow, n to deny, or always to allow all similar operations for the rest of the session.

Warning
Be cautious with file operations on important files. While Claude is very accurate, it is always a good idea to use Git so you can revert changes if something goes wrong. If your project is not using Git yet, now is a great time to start.

Tips for Effective File Work

  • Be specific about locations: "Create it in src/components/" is better than "create a component."
  • Reference existing patterns: "Follow the same pattern as UserList.tsx" gives Claude a template.
  • Ask before big changes: For large refactors, ask Claude to describe the plan first.
  • Verify with tests: After edits, ask Claude to run tests or the type checker.
  • Use Git as your safety net: Commit before large operations so you can always revert.
  • Start small: If you are unsure, start with a read operation before jumping to edits.