Creating & Editing Files

45 min beginner Lesson 3

Learning Outcomes

  • Ask Claude to create files from scratch with clear specifications
  • Edit existing files with targeted instructions
  • Understand the permission model (approve/deny)
  • Perform bulk operations across multiple files
  • Undo changes confidently using git

Lesson Plan

Segment Duration Topic
Intro 3 min File operations are the core of vibe coding
Demo 10 min Creating files — from simple to complex
Explain 5 min The permission model
Demo 10 min Editing existing files
Demo 8 min Bulk operations
Demo 5 min Undoing changes
Wrap-up 4 min Key takeaways

Before You Begin

Pre-work:

  • Complete Lesson 2 (CLAUDE.md configured)
  • Have a project with at least a few existing files to edit
  • Ensure git is initialised (git init if not)

Shopping List:

  • Claude Code installed and authenticated
  • A project with git initialised
  • Familiarity with basic git commands (commit, diff, checkout)

1 Creating Files — Simple to Complex

Simple file creation:

> Create a .gitignore file for a Node.js project

Claude generates the file and shows you what it will create. You approve with y.

More specific creation:

> Create src/utils/formatDate.ts that exports a function to format 
> dates in "Jan 15, 2025" format. Use Intl.DateTimeFormat, not 
> external libraries. Include TypeScript types.

Complex file with requirements:

> Create src/components/DataTable.tsx:
> - Props: columns (array of {key, label, width}), data (array of objects), onSort
> - Sortable column headers (click to sort)
> - Zebra-striped rows
> - Use our existing Tailwind classes
> - Loading state with skeleton rows
> - Empty state with a message

The pattern: Be more specific for more complex files. Simple files need simple prompts.

TIP
Tip
For complex files, list your requirements as bullet points. Claude follows bulleted specs very accurately — it checks off each point as it implements.
WARNING
Watch Out
Always check the file path Claude proposes. If it wants to write to the wrong location, tell it: 'Put that in src/components/ not src/pages/'.

2 The Permission Model

Claude never modifies your filesystem without permission. Every file operation shows you what will happen:

Create: Shows the full file content before writing Edit: Shows a diff (what will change, what stays the same) Delete: Confirms what will be removed

Your options:

  • y (yes) — approve this change
  • n (no) — reject, Claude will try a different approach
  • e (edit) — modify the proposed change before applying
  • You can also type feedback: "Almost, but change X to Y"

Batch approvals: When Claude proposes multiple file changes, you can:

  • Approve all at once
  • Approve individually
  • Reject specific ones

Pre-approving operations (in .claude/settings.json):

{
  "permissions": {
    "allow": [
      "Edit(*)"
    ]
  }
}

Start restrictive (approve everything) and relax as you build trust.

NOTE
Key Insight
The permission model isn't friction — it's your review checkpoint. Every approval is a chance to verify Claude is doing what you intended. Don't blindly approve; actually read the diff.

3 Editing Existing Files

Editing is where Claude really shines. You describe what to change, Claude figures out how:

Targeted edits:

> In src/api/users.ts, add input validation to the createUser 
> function. Validate email format and ensure password is at least 
> 8 characters. Use zod for validation.

Refactoring:

> Refactor the handleSubmit function in LoginForm.tsx — it's too 
> long. Extract the API call into a separate async function and 
> the validation into its own function.

Adding to existing code:

> Add a "lastLogin" field to the User type in src/types/user.ts 
> and update all places that create a User object to include it.

Fixing issues:

> The loading spinner never disappears in Dashboard.tsx. The issue 
> is that setLoading(false) isn't called in the error path of the 
> fetch. Fix it.

Claude shows a diff for every edit — lines removed in red, lines added in green. Read the diff before approving.

TIP
Tip
Be specific about WHERE to make changes. 'Add validation' is vague. 'Add validation to the createUser function in src/api/users.ts' is precise and gets the right result.

4 Bulk Operations

Claude handles multi-file changes naturally:

Rename across codebase:

> Rename the "getUserData" function to "fetchUserProfile" everywhere 
> it's used in the project. Update all imports and references.

Add a pattern to multiple files:

> Add error boundary wrapping to all page components in src/app/. 
> Use our ErrorBoundary component from src/components/ErrorBoundary.tsx

Consistent formatting:

> All API route handlers in src/api/ should return responses in the 
> format { data, error, meta }. Update any that don't match this shape.

Project scaffolding:

> Create a new feature module for "notifications":
> - src/components/notifications/NotificationList.tsx
> - src/components/notifications/NotificationItem.tsx
> - src/api/notifications.ts
> - src/types/notification.ts
> - src/hooks/useNotifications.ts
> Follow the same patterns as the existing "messages" feature.

Claude will propose all files and let you approve them as a batch or individually.

WARNING
Watch Out
For very large bulk operations (20+ files), consider breaking into smaller batches. Claude may lose track of earlier files in a massive multi-file change.

5 Undoing Changes

Things go wrong. Here's how to recover:

Undo the last change (before committing):

> Undo the last edit you made

Claude can revert its own changes within the session.

Using git to undo (most reliable):

# See what changed
git diff

# Undo all uncommitted changes
git checkout -- .

# Undo changes to a specific file
git checkout -- src/api/users.ts

Best practice: commit before big changes:

> Before we start, commit the current state with message "checkpoint before refactor"

Then if things go wrong:

git reset --hard HEAD  # Go back to the checkpoint

The "oops" workflow:

  1. Ask Claude to make a change
  2. Approve it
  3. Realise it's wrong
  4. Option A: Tell Claude "That's not right, revert it and try X instead"
  5. Option B: git checkout -- . to discard all changes
TIP
Tip
Make small commits frequently when working with Claude. Each commit is a checkpoint you can return to. Think of it like saving in a game before a boss fight.

6 Effective File Operation Patterns

Pattern: Show an example, then replicate

> Here's how our UserCard component is structured:
> [paste existing component]
> Create a ProjectCard component following the same pattern but for 
> project data.

Pattern: Describe the interface first

> First, create the TypeScript interface for a Notification in 
> src/types/notification.ts. Then create the API functions that 
> return that type. Then create the component that displays it.

Pattern: Edit by describing the problem

> The checkout page crashes when the cart is empty. Find and fix 
> the component that renders the cart items — it needs a check for 
> empty arrays.

Anti-patterns to avoid:

  • "Edit everything" — too vague, Claude doesn't know what to change
  • "Make it better" — better how? Be specific.
  • "Rewrite the file" — usually you want targeted edits, not a full rewrite
  • Editing files you haven't committed — always commit your good state first

Questions & Answers

Q: Can Claude create binary files (images, PDFs)?
No — Claude works with text files only. It can create SVGs (which are text-based), configuration files, code, and documentation. For binary assets, you need other tools.
Q: What happens if Claude edits the wrong file?
If you haven't approved yet, just say no. If you already approved, use `git checkout -- [file]` to revert. This is why frequent commits matter.
Q: Is there a limit to how many files Claude can edit at once?
No hard limit, but quality degrades with very large changes. For operations touching 10+ files, consider breaking into batches or using a more structured approach (lesson 4 covers this).
Q: Can I edit the proposed change before accepting?
Yes — when Claude shows a proposed edit, you can provide feedback ("change X to Y in that diff") and Claude will adjust before you approve.

Key Takeaways

  1. Be specific — file path + what to change + how = best results
  2. Permission model is your friend — read diffs before approving
  3. Bullet-point specs work best for complex file creation
  4. Commit before big changes — git is your safety net
  5. Show examples — Claude replicates patterns excellently
  6. Batch carefully — smaller changes are easier to review and revert

Next Steps: In Lesson 4 — Multi-File Projects, you'll learn how Claude navigates and modifies large codebases with many interconnected files.