keepcalculator

06 Numbers and Powers

Claude Code Focused Changes: Step-by-Step Guide

Card No. 06·68413 · Updated · Standard formula, shown below

This guide shows you how to get Claude Code to make smaller, more targeted changes to your codebase, reducing the risk of unintended edits and making reviews easier. You’ll learn how to frame requests, scope tasks, and use the tool’s features to keep Claude’s attention on exactly what you want changed.

What You’ll Need

  • Claude Code installed and authenticated (you can run claude in your terminal)
  • A project you’re comfortable letting Claude edit (use a branch or a test copy first)
  • Basic familiarity with the command line and your project’s structure

Step-by-Step

  1. Start with a clear, single-purpose request. Instead of “fix the login flow,” say “change the password reset function to send a confirmation email after the token is validated.” The more specific you are about the file, function, and expected behavior, the less room Claude has to wander.
  2. Specify the exact files or directories. Use Claude’s file-path hints in your prompt. For example: “In src/auth/reset.js, modify the sendResetEmail function to include the user’s first name.” If you’re not sure of the path, ask Claude to locate it first, then confirm before editing.
  3. Define the scope of the change. Tell Claude what NOT to touch. Say “Only change the function body; do not modify imports, exports, or other functions in the file.” This is especially important in large files or when you’re working on a shared codebase.
  4. Use the --edit flag with a precise description. When you want Claude to edit a file, use the --edit flag followed by a brief, focused instruction. For example: claude --edit "src/utils/format.js" "Change the date format from MM/DD/YYYY to YYYY-MM-DD in the formatDate function." This limits the edit to that file.
  5. Ask for a plan before making changes. If your request is even moderately complex, ask Claude to “first outline the steps you’ll take, then wait for my approval before editing.” This lets you catch scope creep before it happens.
  6. Request a diff review. After Claude makes changes, ask it to “show me a diff of what you changed and explain why each change is necessary.” This forces Claude to justify every edit, which often reveals unnecessary ones.
  7. Use the --diff flag to see changes before applying. In some versions, you can ask Claude to show a diff without applying it. If that’s not available, you can always use git diff after the edit to review and revert if needed.
  8. Break large tasks into smaller, sequential requests. Instead of asking for a whole feature, ask for one small piece at a time. For example: “First, add a new function to calculate tax. Then, in the same file, wire it into the checkout function.” This keeps each change focused and easier to verify.
  9. Provide context with comments or examples. If you have a specific style or pattern you want followed, paste a short example in the prompt. For instance: “Follow the same error-handling pattern as in src/db.js.”
  10. After the edit, run tests and review. Use git diff to see exactly what changed. If Claude modified something you didn’t ask for, revert that part and add a note in your next prompt: “Do not change X.”

Common Mistakes

  • Vague requests. “Improve the code” is an invitation for Claude to rewrite half your project. Always be concrete.
  • Not specifying files. If you don’t say which file, Claude may guess and edit multiple files.
  • Allowing Claude to “fix” things you didn’t mention. Claude may proactively fix a bug it spots. If you don’t want that, explicitly say “Do not fix anything else.”
  • Giving too many tasks at once. Even if you list them clearly, Claude might treat them as one big task and make sweeping changes.
  • Not reviewing the diff. Trusting Claude blindly can lead to unwanted changes. Always review.

Tips

  • Use the --permission-mode flag to control what Claude can do. For example, --permission-mode acceptEdits allows edits but asks before running commands.
  • Create a branch before letting Claude edit. This gives you a safety net to revert everything if needed.
  • Use Claude’s memory features. If you have a preferred style, tell Claude once and it can remember it for future sessions (if you have that feature enabled).
  • Be explicit about the language and framework. For example: “Use Python 3.11 and follow PEP 8.”
  • After a successful focused edit, save the prompt as a template. This helps you replicate the precision next time.

Troubleshooting

  • Claude still makes broad changes. If Claude ignores your scope, stop the session, revert the changes, and rephrase your request with even stricter constraints. You can say: “I will only accept changes to src/utils/format.js. Do not edit any other file. If you need to edit another file, ask me first.”
  • Claude doesn’t understand the file path. Run claude --list-files or ask Claude to show you the project structure first. Then use the exact path in your prompt.
  • Claude makes changes but they’re incorrect. Review the diff, identify the error, and ask Claude to fix it with a very specific instruction. For example: “In the formatDate function, the month is off by one. Change it to use getMonth() + 1.”
  • Claude refuses to make any changes. This might be due to permission settings. Check your --permission-mode and ensure you’ve allowed edits.
  • The change is too large even after scoping. If the function is huge, ask Claude to split it into smaller functions first, then modify only the part you need.

Frequently Asked Questions

  1. Can I make Claude only edit a specific line or function? Yes, you can say “Only change the calculateTotal function in src/cart.js.” Claude will focus on that function, but always review the diff to ensure it didn’t touch anything else.
  2. What if Claude changes a file I didn’t mention? If you see an unexpected file in the diff, revert that file and tell Claude “You changed src/other.js which I didn’t ask for. Please revert it and only edit the files I specify.”
  3. How do I prevent Claude from running commands like tests or installs? Use --permission-mode acceptEdits which allows edits but asks before running shell commands. You can also say “Do not run any commands.”
  4. Is it better to give a very detailed prompt or a short one? For focused changes, detail is your friend. A short prompt like “fix the bug” is too vague. But a long prompt with irrelevant details can also confuse. Stick to the essential: file, function, desired behavior, and what not to touch.
  5. Can I use Claude Code to review my own changes? Yes, you can ask “Review the diff of my last commit and suggest only necessary changes.” This is a good way to get focused feedback without Claude making edits.
  6. What if Claude’s edit breaks something? If you’re on a branch, you can revert with git checkout -- . or git reset --hard. Then re-run Claude with a more careful prompt. Always test after edits.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →