> AI agents: For documentation discovery and navigation, see [llms.txt](/llms.txt).

# Review and revert agent changes

When you work with an agent in Visual Studio Code, it can change multiple files in your project. This article explains how to inspect, revise, integrate, or discard these AI-generated changes.

> [!NOTE]
> You can review AI-generated changes in both the [Chat view](/docs/agents/run/chat-view.md) and the [Agents window](/docs/agents/run/agents-window.md). The review experience follows the same concepts, but the user interface differs between the two surfaces.

<div class="docs-action" data-show-in-doc="false" data-show-in-sidebar="true" title="Get started with agents">
Follow a hands-on tutorial to build an app with AI agents in VS Code.

* [Start agentic coding tutorial](/docs/agents/agents-tutorial.md)

</div>

## Review agent changes

In Agent Host sessions, the agent applies and saves edits directly in the session's folder or isolated Git worktree. These edits don't have a pending review state, so review them in a diff before you commit or integrate them. **Manual permissions** doesn't require confirmation for edits that your approval settings already allow. To require confirmation before specific files are edited, configure [sensitive-file approval](#edit-sensitive-files).

Older extension-host sessions save edits and then mark them as pending so you can keep or undo them. Expand **Review extension-host changes** below for that workflow.

Review agent changes as you would other workspace or branch changes through the diff view, Source Control, or pull request workflow.

For keyboard and screen reader access to a diff, use the [Accessible Diff Viewer](/docs/configure/accessibility/accessibility.md#diff-editor-accessibility), which presents changes in a unified patch format.

{% tabs id="chat-surface" %}
{% tab label="Chat view" %}

1. Select a changed file in the agent's response to open its diff or select it from the Source Control view.

1. To see a summary after each completed request, set `setting(chat.checkpoints.showFileChanges)` to `true`. Expand the changed-files summary to see the files and diff statistics, or select **View All File Changes** to open a multi-file diff.

1. If you want to make further changes, send a follow-up prompt or edit the files directly. To revert a request and all later changes, [restore a checkpoint](#restore-a-checkpoint).

1. Run tests and use the debugger or other editor tools to validate the result.

1. When you're satisfied with the changes:

    * For folder-isolated sessions, stage and commit the changes with Source Control.

    * For worktree-isolated sessions, apply or merge the worktree changes into your main workspace.

    * For cloud sessions, review the pull request or check out its branch locally.

{% /tab %}
{% tab label="Agents window" %}

By default, the Agents window shows these views in a side panel:

* **Files**: a file explorer for the session workspace.
* **Changes**: files that the agent changed, added, or deleted. Use the **Branch Changes** dropdown to choose which changeset to review.

The **Changes** view groups edits outside the workspace under **Other Files**. These files, such as plans in the session-state folder, aren't committed with workspace changes. The list includes files changed through file-edit tools, but not files that the agent only reads or changes through terminal commands.

### Configure word wrap in diff editors

`feature(agents-window-word-wrap)`

Control how diff editors in the **Changes** view wrap long lines with `setting(sessions.diffEditor.wordWrap)`. This setting has the following values:

* `inherit` (default): Follow the `setting(editor.wordWrap)` setting.
* `on`: Wrap lines at the editor viewport width.
* `off`: Never wrap lines.

This setting only affects diff editors and doesn't affect code editors in the Agents window. To configure word wrapping in code editors, see [Configure word wrap for code editors](/docs/agents/run/agents-window-configuration.md#configure-word-wrap-for-code-editors).

To change this setting from a diff editor, select **More Actions** (**...**) > **Word Wrap**. This action updates `setting(sessions.diffEditor.wordWrap)` independently of the code editor setting.

To review and integrate the changes:

1. Select a file in the **Changes** view to open a diff view of the agent's edits.

    ![Screenshot showing the Changes panel in the Agents window, highlighting the list of edited files and the diff view.](../images/review-code-edits/agents-window-diff-view.png)

    By default, selecting a file opens a multi-file diff editor with all the session changes. To open a focused single-file diff, enable `setting(sessions.changes.openSingleFileDiff)`.

    Use the diff toolbar to show the editor side by side with chat or in a modal window.

    To change the diff layout, select **More Actions** (**...**) > **Diff View**, and then select **Inline**, **Side by Side**, or **Automatic**. With **Automatic**, the Changes editor shows files side by side when there is enough space and switches to inline when the editor is narrow.

1. Select a range of code in a changed file, select **Add Feedback**, and enter a comment that describes the change you want. Add more comments on other selections or files, and then select **Submit Feedback** to send them to the agent.

    ![Screenshot showing the Add Feedback button in the Changes diff view.](../images/review-code-edits/agents-window-add-feedback.png)

    Markdown files follow the same feedback flow. Open a workspace file from the **Changes** tab and use **Locked** mode in the Markdown editor to add range-based feedback. Feedback stays in sync if you reopen the file in the text editor.

    The agent reads your comments, makes the requested edits, and resolves each comment. Resolved comments disappear from the diff view.

1. Select **Mark as Reviewed** in a file's toolbar to track files you've reviewed in the **Branch Changes** changeset. The reviewed state clears if you or the agent changes the file again.

1. Use the **Commit**, **Merge**, **Checkout**, or **Discard** actions to act on the edits.

When you create a session, use the sync button in the **Files** panel to pull upstream changes from the base branch before the agent starts. Starting from the latest branch state reduces merge conflicts when you integrate the result.

### Add pull request review comments

`feature(agents-window-pr-comments)`

For an Agent Host session associated with an open GitHub pull request, you can add a review comment to the pull request directly from the **Changes** view. This is different from agent feedback, which asks the agent to revise its changes.

1. Enable the `setting(chat.experimental.agentsWindowPRComments)` setting.
1. Open a changed file from the **Changes** view and select a range of code.
1. Select **Add Feedback** and enter your comment.
1. Select **Add PR Comment** to add the review comment to the pull request. If the session is associated with multiple pull requests, the action identifies the target as `owner/repository#number`.

The selected range must contain only lines that are part of the pull request diff. If the range isn't eligible, VS Code reports that a pull request comment can't be added to the line.

**Add PR Comment** adds the comment to GitHub and doesn't send it to the agent. To ask the agent to change the code instead, add the comment as feedback and select **Submit Feedback**.

### Review changes in the single-pane layout (Experimental)

When you enable the [experimental single-pane editor panel](/docs/agents/run/agents-window-configuration.md#use-the-single-pane-editor-panel-experimental), the **Changes** view and diff editor share one docked pane.

Use **Expand All Diffs** or **Collapse All Diffs** to control all files at once. The `kb(toggle.diff.renderSideBySide)` keybinding toggles the preferred diff view in the Agents window.

The Changes editor restores each file's expanded or collapsed state when you switch sessions or reload the window. The editor tab title shows the next integration action, such as **Create Pull Request**, and switches to an icon when space is limited.

{% /tab %}
{% /tabs %}

## Integrate worktree changes

A worktree session keeps the agent's branch and working files separate from your primary worktree. After you review and validate the result, choose how to continue:

* **Apply or migrate the changes**: transfer the worktree changes into your current workspace for further editing and commit them with your existing work.
* **Commit or merge the branch**: preserve the work on the session branch and merge it into the destination branch.
* **Check out the branch**: open the session branch in an editor window to continue working on it manually.
* **Discard the changes**: remove changes that you don't want to keep.

Before you apply or merge changes:

1. Confirm the session's base branch and the destination branch in your primary workspace.
1. Commit or stash unrelated changes in the destination workspace.
1. Review all changed files, including untracked files, and run the relevant tests.
1. Select the integration action and resolve any merge conflicts.
1. Test the integrated result before you archive or delete the session.

The available actions and labels depend on the session harness and whether you use the Chat view or Agents window. Keep the session until you verify that the changes are present on the intended destination branch.

For a walkthrough of reviewing two results separately, integrating them one at a time, and testing the combined change, follow [Delegate two tasks without mixing their changes](/docs/agents/guides/delegate-two-tasks.md).

## Edit requests and restore checkpoints

For help deciding whether to revise a request, restore changes, or start fresh, see [Get an agent back on track](/docs/agents/guides/get-agent-back-on-track.md#choose-a-recovery-action).

Use request editing and checkpoints to revise or undo a batch of changes:

* **Edit a previous request**: modify a prompt you already sent. VS Code reverts changes made by that request and all subsequent requests, then resends the edited prompt.
* **Restore a checkpoint**: roll back all file changes to a specific point in the conversation without changing the prompt.

### Edit a previous chat request

Each request in your conversation history is editable. When you edit a previous request, VS Code reverts file changes made by the original request and subsequent requests, and then sends the updated request to the language model.

Select the request in the conversation, modify it, and resend it. Configure or turn off request editing with `setting(chat.editRequests)`.

<video src="../images/chat-checkpoints/chat-edit-request.mp4" title="Video showing the editing of a previous chat request in the Chat view." loop controls muted></video>

### Restore a checkpoint

Checkpoints are enabled by default for supported chat sessions. Before processing each request, VS Code creates a snapshot of affected workspace files. Set `setting(chat.checkpoints.enabled)` to control checkpoints.

To restore your workspace to an earlier checkpoint:

1. Navigate to a previous request in the conversation.

1. Hover over the request and select **Restore Checkpoint**.

    ![Screenshot showing the Restore Checkpoint action in the Chat view.](../images/chat-checkpoints/chat-restore-checkpoint.png)

1. Confirm that you want to restore the checkpoint.

VS Code removes subsequent requests from the conversation history and restores the workspace files to their state at the checkpoint.

> [!IMPORTANT]
> A checkpoint restores affected workspace files and chat history. It doesn't reverse completed terminal commands, network requests, deployments, or changes that tools made to external services. Use Git and the external service's recovery controls for those effects.

#### Redo after restoring

After restoring a checkpoint, select **Redo** to recover the changes that were undone.

![Screenshot showing the Redo button after restoring a checkpoint.](../images/chat-checkpoints/chat-redo-checkpoint.png)

#### View file changes in checkpoints

Set `setting(chat.checkpoints.showFileChanges)` to show the files changed by each request and the number of lines added or removed. Use this summary to understand the effect of a request before restoring its checkpoint.

![Screenshot showing file changes associated with a chat checkpoint.](../images/chat-checkpoints/chat-checkpoint-changed-files.png)

#### Fork from a checkpoint

Hover over a request and select **Fork Conversation** to create an independent session that includes the conversation up to that checkpoint. Learn more about [forking agent sessions](/docs/agents/run/sessions/manage-sessions.md#fork-a-chat-session).

> [!NOTE]
> Checkpoints are temporary and don't replace Git version control. Use Git for permanent version history and collaboration.

<details>
<summary>Review extension-host changes</summary>

If [Agent Host](/docs/agents/concepts/agent-host.md) is not enabled or you are working with an older session, the agent uses the extension host to make edits, which has a different workflow for reviewing changes.

After the agent edits and saves a file, VS Code marks the edits as pending. Pending means that you can keep or undo the saved edit. It doesn't mean that the edit is waiting to be written to disk. Files with pending edits have a squared-dot indicator in the Explorer view and editor tabs. The pending state is restored when you reopen VS Code.

![Screenshot showing the Chat view, highlighting the changed files list and the indicator in the Explorer view and editor tabs.](../images/review-code-edits/copilot-edits-changed-files-full.png)

To review pending edits:

1. Open a file from the changed-files list in the Chat view or from the Explorer view.

    ![Screenshot showing the Editor with proposed changes, highlighting the review controls in the editor overlay controls.](../images/review-code-edits/copilot-edits-file-review-controls.png)

1. Use the `kbstyle(Up)` and `kbstyle(Down)` controls in the editor overlay to navigate between edits.

1. For each edit, choose one of the following actions:

    * Select **Keep** to accept the edit.
    * Select **Undo** to reject the edit and revert the change.
    * Hover over an inline change to accept or reject that specific change without affecting other edits in the file.

You can also accept or reject all pending edits from the Chat view. When you resolve an edit, the editor automatically opens the next file with pending edits. To stay in the current file, set `setting(chat.editing.revealNextChangeOnResolve)` to `false`.

### Source Control integration

If you stage your changes in the Source Control view, any pending edits are automatically accepted. If you discard your changes, any pending edits are also discarded.

### Auto-accept edits

Use `setting(chat.editing.autoAcceptDelay)` to automatically accept pending edits after a configurable delay. Hover over the editor overlay controls to stop the countdown.

> [!IMPORTANT]
> If you automatically accept all edits, review the changes before you commit them in source control. Learn more about the [security considerations of using AI in VS Code](/docs/agents/run/security.md).

</details>

## Edit sensitive files

Sensitive-file approval is separate from reviewing changes after the agent saves them. To prevent inadvertent edits to files such as workspace configuration or environment settings, VS Code can show a diff and ask you to approve or reject the edit before it is applied.

Use the `setting(chat.tools.edits.autoApprove)` setting to configure which files require approval. The setting uses glob patterns to match file paths in your workspace.

The following example configuration automatically allows edits to all files except for JSON files in the `.vscode` folder and files named `.env`, which you are prompted to approve:

```json
"chat.tools.edits.autoApprove": {
  "**/*": true,
  "**/.vscode/*.json": false,
  "**/.env": false
}
```

## Review changes from the sessions list

When a session completes and makes code changes to your project, the [sessions list](/docs/agents/run/sessions/manage-sessions.md#sessions-list) shows the file change statistics for that session. To review the changes, select the session from the list to open the session details.

![Screenshot of the file changes diff editor in an agent session.](../images/agents-overview/agent-file-changes-v2.png)

Depending on the agent harness and isolation mode, you can apply or merge changes into your local workspace, or check out the branch from a cloud session.

## Related resources

* [Use chat in VS Code](/docs/chat/chat-overview.md)
* [Agent sessions](/docs/agents/run/sessions/manage-sessions.md)
* [Security considerations for using AI in VS Code](/docs/agents/run/security.md)
