# Narrow the scope of a change

When Claude Code changed more than you asked for, keep the part you want and have it undo the rest, file by file, then show the remaining diff.

Paste into: **Claude Code**, started in your project folder

## Prompt template

How the builder on the page fills in this template, so you can do the same:

- `{{key}}` becomes the text entered for that field, exactly as typed. Empty text, or text that is only whitespace (spaces, tabs or line breaks), counts as empty: a required field then becomes `[fill in: <label>]` with its label, and an optional field becomes nothing.
- For a choice field, `{{key}}` becomes the text of the chosen option, or of the default when none is chosen.
- Text between `{{#key}}` and `{{/key}}` stays only when that field is not empty; a choice field always counts as filled. The markers themselves are removed, and a marker that stands alone on its line takes its line break with it.
- Each value is inserted once, as it is: `{{…}}` inside a value stays as typed.

```text
That is too much. Keep only the changes to {{scope}} and undo your other edits.
{{#reason}}
Why: {{reason}}
{{/reason}}

How to undo: {{undo}}.

Rules:
- Undo only edits you made in this session. Leave changes I made, and files you did not touch, exactly as they are.
- Revert file by file. Do not run commands that discard changes across the whole working tree, such as git reset --hard, git checkout . or git stash.
- If a change you are keeping depends on one you are removing, stop and tell me instead of deciding on your own.
- If it is unclear whether an edit falls inside the scope, ask me.
- Do not commit.

When you are done:
1. List the files you reverted and the files where changes remain.
2. Show the remaining diff.
3. Run the tests or build that cover the kept changes{{#check}} ({{check}}){{/check}}, and show the result.
```

## Fields

- `{{scope}}` (required): The changes to keep. Name a directory, file, function or behavior. Everything Claude changed outside it will be undone.
- `{{reason}}`: Why the rest should go. Optional. Helps Claude judge edge cases, such as a shared helper both parts use.
- `{{undo}}`: How to undo. Choose one:
  - list the edits you would undo and wait for my confirmation (default)
  - undo the other edits now
- `{{check}}`: Command to check the result. Optional. Tests or a build that should still pass after the cleanup.

This site doesn't run Claude or show model output. Results depend on your input and the model you use.

## When to use this template

- Claude Code went in the right direction but changed more than you asked for, such as refactoring nearby code or reformatting files during a small fix.
- You want to keep part of the work and lose the rest, which a full rewind to an earlier checkpoint cannot do.
- You are preparing a focused pull request and need the diff limited to one area before you review it.

## When not to use it

- You want to throw away all of Claude's work since a certain point. Press `Esc` twice or run `/rewind` and restore the code from that checkpoint instead. Checkpoints cover only edits made through Claude's file-editing tools, not changes made through Bash or outside Claude, so check those separately, for example with `git status`.
- The direction itself is wrong, not just the size. Use the course-correct template to name the constraint Claude missed.
- Your own uncommitted work is mixed into the same files and you have no copy of it. Commit or back up your changes first, so you can recover them if a revert goes wrong.

## Why this structure

- The required scope field is the boundary for everything else in the prompt: what is inside it stays, what is outside it is undone.
- The rule to revert only Claude's own edits, file by file, and to avoid commands that wipe the whole working tree is there to protect your uncommitted work in the same files.
- The undo choice lets you see the list before anything is reverted. The default waits for confirmation, which matters when the edits are spread over many files.
- The dependency rule covers the awkward case where a kept change relies on a removed one, such as a helper both parts use. Claude stops and asks instead of breaking the kept work.
- The report lists reverted and kept files, shows the remaining diff and runs a check, so you can confirm the result matches the scope and still works.

## Example input (fictional)

The changes to keep:

```
the validation logic in src/forms/
```

Why the rest should go:

```
the styling changes belong in a separate pull request
```

How to undo:

```
list the edits you would undo and wait for my confirmation
```

Command to check the result:

```
npm test -- src/forms
```

## Follow-ups to send Claude

- Save the edits you just removed as a patch file in /tmp so I can apply them later in a separate branch.
- From now on in this session, change only files under src/forms/ unless I say otherwise.
- Review the remaining diff for anything that still reaches outside the validation logic.

## Common mistakes

- Naming the scope loosely, such as "the important parts". Use a path, a function or a behavior Claude can check each edit against.
- Letting Claude run a repository-wide reset to save time. That can discard your own uncommitted changes along with Claude's.
- Skipping the check after the cleanup. Removing part of a change can break the part you kept, so run the tests before you move on.

## Related templates

- [Course-correct a wrong approach](https://awesomeclaudeprompts.com/prompts/course-correct-claude/): When Claude Code heads the wrong way, name the constraint it missed and ask for a different approach, with a check that shows the retry meets it.
- [Plan a code change before editing](https://awesomeclaudeprompts.com/prompts/plan-code-change/): Have Claude Code read the relevant code and propose a file-by-file plan for a multi-file change, without editing anything until you approve it.
- [Review your changes before you commit](https://awesomeclaudeprompts.com/prompts/review-before-commit/): Have Claude Code review uncommitted changes against their intent and flag risks by severity, asking before any check that could change files.

## Sources

- [Claude Code docs: Prompt library](https://code.claude.com/docs/en/prompt-library) (Anthropic documentation)
- [Claude Code best practices: Course-correct early and often](https://code.claude.com/docs/en/best-practices#course-correct-early-and-often) (Anthropic documentation)
- [Claude Code best practices: Rewind with checkpoints](https://code.claude.com/docs/en/best-practices#rewind-with-checkpoints) (Anthropic documentation)

---

Awesome Claude Prompts is an independent project. It is not affiliated with, endorsed by, or sponsored by Anthropic. Claude is a trademark of Anthropic, PBC.
