Edit existing code
Make surgical changes to your project
⏱ Est. ~7 min
01 · Read
Creating new files is great, but most real-world dev is editing existing code. Adding features to apps, fixing bugs, updating designs, refactoring functions.
This is where Claude Code really shines. Because it can read your whole project, it understands context. Ask it to add a footer and it knows what HTML structure exists. Ask it to change styling and it knows which CSS file to edit.
Claude doesn't start from scratch — it makes surgical edits to exactly what needs changing, and leaves the rest alone.
💡 Picture thisImagine asking a contractor to add a room to your house. A bad contractor might knock down random walls. A good contractor studies the blueprints, understands the structure, and adds the room exactly where it belongs. Claude Code is the good contractor.
02 · Prompt template
Ask Claude to add a footer to the HTML you made in the last lesson. Be specific about what goes in it.
Add a footer to index.html with a copyright 2024 notice and a link to GitHub
03 · Prompt template
Now ask Claude to change the CSS. This is a precise edit — Claude should only update the relevant style rules.
Make the nav bar sticky so it stays at the top when you scroll
04 · Real-machine exercise
Now use the tool you learned in Level 4 — git diff. It shows exactly what Claude changed. Green is added, red is removed.
git diff
05 · Read
Here's the key habit: always review changes before committing. Claude is powerful but not perfect. You should always: - Read the diff to understand what changed - Test the change in the browser or by running the code - Commit only when you're happy
git diff is your best friend. It tells you, line by line, what was added, removed, and changed.
Key points
- Always review changes before committing
- git diff tells you what Claude changed
- Green (+) = added, red (-) = removed
- Claude makes surgical edits — only changes what's needed
06 · Quiz
After Claude edits your code, what command tells you exactly what changed?
- git status
- git log
- git diff
- git show
07 · Fill in the blank
Before committing, to see the exact lines Claude changed, run git ___.
Other lessons in this chapter
⚠ The full interactive experience needs JavaScript. Please enable it and reload.
※ This is an independent Traditional Chinese teaching project — not an official Anthropic product. Claude™ is a trademark of Anthropic, PBC.