0% found this document useful (0 votes)
55 views15 pages

07-Copilot Edits

Copilot Edits is a feature in VS Code that allows users to initiate AI-powered code editing sessions using natural language prompts. It operates in two modes: Edit mode, where users specify files and context for code suggestions, and Agent mode, which autonomously determines the necessary edits and commands. Users can manage a working set of files, review suggested edits, and utilize various tools for efficient code iteration and management.

Uploaded by

nicobar14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views15 pages

07-Copilot Edits

Copilot Edits is a feature in VS Code that allows users to initiate AI-powered code editing sessions using natural language prompts. It operates in two modes: Edit mode, where users specify files and context for code suggestions, and Agent mode, which autonomously determines the necessary edits and commands. Users can manage a working set of files, review suggested edits, and utilize various tools for efficient code iteration and management.

Uploaded by

nicobar14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Copilot Edits https://code.visualstudio.

com/docs/copilot/copilot-edits

🚀 Get GitHub Copilot Free (vscode://github.copilot-chat?referrer=vscode-updatebanner) in VS Code! ×

TOPICS Copilot Edits

IN THIS ARTICLE Start a Copilot Edits session

Copilot Edits (https://vscode.dev/github/microsoft/vscode-docs/blob/main/docs/copilot/copilot-edits.md)

Use Copilot Edits to start an AI-powered code editing session and iterate quickly on code changes across multiple files by using
natural language. Copilot Edits applies the edits directly in the editor, where you can review them in-place, with the full context of
the surrounding code.

Copilot Edits can function in two modes:

• Edit mode: select which files to edit, provide the relevant context and prompt, and Copilot will suggest code edits.
• Agent mode (preview): let Copilot autonomously plan the tasks and relevant files that are needed to implement the request.
Copilot will apply code edits and suggest terminal commands, and will continuously iterate to resolve any issues that arise.

Note
Agent mode is currently in preview and is only available in VS Code Insiders (https://code.visualstudio.com/insiders). Provide
feedback and report issues in the Copilot repository (https://github.com/microsoft/vscode-copilot-release/issues).

Important
If you're using notebooks, Copilot Edits support is currently limited. We recommend that you use Copilot Chat (/docs/copilot/
copilot-chat) or Inline Chat (/docs/copilot/copilot-chat#_inline-chat) with notebooks in VS Code.

The following video demonstrates how to use Copilot Edits to extend a basic Express app, such as adding a new page, navigation
bar, and theme switcher.

1 sur 15 19/02/2025 17:44


Copilot Edits https://code.visualstudio.com/docs/copilot/copilot-edits

0:00 / 1:06

Tip
If you don't yet have a Copilot subscription, you can use Copilot for free by signing up for the Copilot Free plan (https://
github.com/github-copilot/signup) and get a monthly limit of completions and chat interactions.

Start a Copilot Edits session

You access Copilot Edits through the Copilot Edits view, where you can enter natural language prompts for getting edit
suggestions. By default, the Copilot Edits view is available in the Secondary Side Bar.

2 sur 15 19/02/2025 17:44


Copilot Edits https://code.visualstudio.com/docs/copilot/copilot-edits

To access the Copilot Edits view:

• Use the ⇧⌘I keyboard shortcut

• Open the Copilot menu in the VS Code title bar, and then select Open Copilot Edits

• Use the View: Toggle Copilot Edits or Copilot Edits: Focus on Copilot Edits View command in the Command Palette
( ⇧⌘P )

Because making code changes can be an iterative process, an edit session in Copilot Edits can consist of a sequence of requests
(or turns). You can send as many requests as you need to get the code to where you want it.

Use edit mode

In edit mode, you select which files to edit and provide the relevant context and prompt. Copilot will suggest code edits based on
your prompt.

1 Open the Copilot Edits view ( ⇧⌘I )

2 Select Edit from the mode dropdown

3 sur 15 19/02/2025 17:44


Copilot Edits https://code.visualstudio.com/docs/copilot/copilot-edits

3 Use Add Files to add files to the working set

The working set indicates which files in the workspace can be edited by Copilot Edits.

4 Enter a prompt to request code edits. Be specific and precise about the changes you want, and decompose larger tasks into
smaller tasks.

Copilot Edits streams the edits in the editor. In the working set, files that were edited by Copilot are marked in bold.

Tip
Let Copilot find the right files automatically by adding #codebase in your prompt. Make sure to enable the
! (vscode://settings/github.copilot.chat.edits.codesearch.enabled)github.copilot.chat.edits.codesearch.enabled
(preview) setting to get the best results.

5 Review the suggested edits and accept or discard the suggested edits

6 Iterate on the code changes

If you're not entirely happy with the edits, you can ask follow-up questions, such as "don't include the phone number", or
"use jest instead of vitest". Or you can incrementally edit your code further. For example, when building a web app, use a
series of prompts such as "add a navigation bar", "add a theme switcher", "store order items in JSON format in MongoDB".

Use agent mode (preview)

In agent mode, Copilot Edits operates in a more autonomous and dynamic manner to achieve the desired outcome. To process a
request, Copilot loops over the following steps and iterates multiple times as needed:

• Determines the relevant context and files to edit autonomously.


• Offers both code changes and terminal commands to complete the task. For example, Copilot might compile code, install
packages, run tests, and more.
• Monitors the correctness of code edits and terminal command output and iterates to remediate issues.

Copilot Edits agent mode uses a set of tools to accomplish these tasks. These tools can run in parallel to accomplish the
requested task.

To use agent mode in Copilot Edits:

1 Enable agent mode in by setting the ! (vscode://settings/chat.agent.enabled)chat.agent.enabled setting to true .

2 Open the Copilot Edits view ( ⇧⌘I )

3 Select Agent from the mode dropdown

4 sur 15 19/02/2025 17:44


Copilot Edits https://code.visualstudio.com/docs/copilot/copilot-edits

4 Enter a prompt to request code edits.

You don't have to specify the working set. In agent mode, Copilot Edits determines the relevant context and files to edit
autonomously.

Copilot Edits streams the edits in the editor and updates the working set. In addition, Copilot can suggest terminal
commands to run.

5 Review the suggested code edits, and confirm if Copilot can run the proposed terminal commands

As a user, you stay in control of the changes that are made to your project and can review the generated edits and need to
confirm the terminal commands to run.

5 sur 15 19/02/2025 17:44


Copilot Edits https://code.visualstudio.com/docs/copilot/copilot-edits

6 Copilot Edits detects issues and problems in code edits and terminal commands, and will iterate and perform additional
actions to resolve them.

Note
The ! (vscode://settings/chat.agent.maxRequests)chat.agent.maxRequests setting controls the maximum number of
requests that Copilot Edits can make in agent mode.

7 Continue to ask follow-up questions and iterate on the code changes that Copilot Edits provides.

Note
Agent mode for Copilot Edits is currently only available in VS Code Insiders (https://code.visualstudio.com/insiders).

Manage the working set

The working set is the set of files that you want Copilot Edits to work on for your edit session. Copilot Edits does not make
changes outside the working set, except when suggesting to create a new file. When you use agent mode, Copilot autonomously
determines which files to edit and adds them to the working set.

6 sur 15 19/02/2025 17:44


Copilot Edits https://code.visualstudio.com/docs/copilot/copilot-edits

Important
The working set is currently limited to 10 files.

Copilot Edits automatically adds the active editor to the working set. If you have multiple editor groups (/docs/getstarted/
userinterface#_editor-groups), the active editor for each group is added to the working set. To add all open editors, select Add
Files..., and then choose Open Editors from the Files Quick Pick.

You have many options to add files to the working set:

• Select Add Files... or use the Attach " icon ( ⌘/ ), and then select files in the Quick Pick.

Tip
To quickly select multiple items from a Quick Pick, use the Up and Down keys to navigate the list, use the Right key
to add the item as context, and then repeat this for other items.

• Let Copilot find the right files automatically by adding #codebase in your prompt.

Make sure to enable the


! (vscode://settings/github.copilot.chat.edits.codesearch.enabled)github.copilot.chat.edits.codesearch.enabled
(preview) setting to get the best results.

• Drag and drop editor tabs, or files or folders from the Explorer view, Search view, or editor breadcrumb onto the Copilot
Edits view.

When you drop a folder onto the Copilot Edits view, all files in that folder are added to the working set.

• Right-click on a file in the Explorer view or Search view and select Add File to Copilot Edits.

• Select a suggested file. When you add one or more files to the working set, Copilot Edits proposes other relevant files based
on the Git history.

7 sur 15 19/02/2025 17:44


Copilot Edits https://code.visualstudio.com/docs/copilot/copilot-edits

If you don't want to see these suggestions, you can disable them with the
! (vscode://settings/
github.copilot.chat.edits.suggestRelatedFilesFromGitHistory)github.copilot.chat.edits.suggestRelatedFilesFromGitHistory
setting.

When Copilot Edits generates edits for your project, it visually indicates which files in the working set are edited. Select a file in the
working set to open it and view the proposed edits in the editor.

8 sur 15 19/02/2025 17:44


Copilot Edits https://code.visualstudio.com/docs/copilot/copilot-edits

Accept or discard edits

Copilot Edits gives you a code review flow where you can accept or discard each of the AI-generated edits. If you discard the
edits, the modified files are restored to their previously accepted state.

With the editor overlay controls, you can navigate between the suggested edits by using the # and $ controls. Use the Accept
or Discard button to accept or reject the edits for a given file.

To accept or discard a specific edit within a file, hover over the code edit and use the Accept or Discard controls for that edit.

Alternatively, you can also accept or discard the changes from the working set in the Copilot Edits view:

• Select Accept ( ⌘Enter ) or Discard ( ⌘Backspace ) in the working set title bar to accept or discard all edits in the working
set

• Select the Accept or Discard icon on an individual working set file to apply the action to that specific file

With the ! (vscode://settings/chat.editing.autoAcceptDelay)chat.editing.autoAcceptDelay setting, you can configure a delay


after which the suggested edits are automatically accepted. Hover over the editor overlay controls to cancel the auto-accept

9 sur 15 19/02/2025 17:44


Copilot Edits https://code.visualstudio.com/docs/copilot/copilot-edits

countdown.

When you close VS Code, the status of the pending edits is remembered. When you reopen VS Code, the pending edits are
restored and you can still accept or discard the edits.

Note
In agent mode, edits are automatically saved to disk, regardless if Auto Save (
! (vscode://settings/files.autoSave)files.autoSave ) is enabled. You can still review the edits and choose to discard them if
needed.

Undo edits

As you're sending requests to make edits to your code, you might want to roll back some of these changes, for example because
you want to use another implementation strategy.

You can use the Undo Last Edit control in the Copilot Edits view title bar to revert the last edits and return to the state before
sending the last request. After you perform an undo of the last edits, you can redo those edits again by using the Redo Last Edit
control in the Copilot Edits view title bar.

You can also use the Undo Edits (Delete) control when hovering over a request in the Copilot Edits view to revert all edits that
were made from that request onwards.

Tip
Sometimes Copilot starts walking down the wrong path when generating edits. Once that happens, it can be hard to convince

10 sur 15 19/02/2025 17:44


Copilot Edits https://code.visualstudio.com/docs/copilot/copilot-edits

it about another approach by adding to the conversation. In that case, use Undo Last Edit to the point where you agree with
Copilot's responses. Then restart from there with a refined prompt.

Send a chat request to Copilot Edits

Copilot Chat is great for asking questions and exploring ideas about your project or technology topics in general. Rather than
applying each code block from Copilot Chat to your code, you can transfer the chat session to Copilot Edits. Copilot Edits is
optimized for code editing and can apply code suggestions directly in your code, across multiple files simultaneously.

In the Chat view, select the Edit with Copilot button at the bottom of the chat conversation to apply the suggested code changes
with Copilot Edits. If you have multiple chat requests in the chat session, you can select which requests you want to transfer to
Copilot Edits.

After moving a chat request to Copilot Edits, the chat request is removed from the chat conversation in the Chat view.

Agent mode tools

To complete a request, Copilot Edits uses a set of tools to accomplish the individual tasks. Consider these tools as specialized
utilities that Copilot can use to perform a specific task. Examples of such tasks are listing the files in a directory, editing a file in
your workspace, running a terminal command, getting the output from the terminal, and more.

Based on the outcome of a tool, Copilot might invoke other tools to accomplish the overall request. For example, if a code edit
results in syntax errors in the file, Copilot might explore another approach and suggest different code changes.

11 sur 15 19/02/2025 17:44


Copilot Edits https://code.visualstudio.com/docs/copilot/copilot-edits

Although agent mode can operate in an autonomous manner, you maintain control over the generated edits and the terminal
commands that are run.

Settings

The following list contains the settings related to Copilot Edits. You can configure settings through the Setting editor ( ⌘, ).

• ! (vscode://settings/chat.editing.confirmEditRequestRemoval)chat.editing.confirmEditRequestRemoval - ask for


confirmation before undoing an edit (default: true )
• ! (vscode://settings/chat.editing.confirmEditRequestRetry)chat.editing.confirmEditRequestRetry - ask for confirmation
before performing a redo of the last edit (default: true )
• ! (vscode://settings/chat.editing.alwaysSaveWithGeneratedChanges)chat.editing.alwaysSaveWithGeneratedChanges -
automatically save generated changes from Copilot Edits to disk (default: false )
• ! (vscode://settings/chat.agent.enabled)chat.agent.enabled % - enable or disable agent mode in Copilot Edits (default:
false )
• ! (vscode://settings/chat.editing.autoAcceptDelay)chat.editing.autoAcceptDelay - configure a delay after which
suggested edits are automatically accepted, use zero to disable auto-accept (default: 0)
• ! (vscode://settings/github.copilot.chat.edits.codesearch.enabled)github.copilot.chat.edits.codesearch.enabled
(preview) - let Copilot find the right files by adding #codebase to your prompt, similar to how agent mode works (default:
false )
• ! (vscode://settings/chat.agent.maxRequests)chat.agent.maxRequests - maximum number of requests that Copilot Edits
can make in agent mode (default: 5 for Copilot Free users, 15 for other users)

Keyboard shortcuts

The following list contains the default keyboard shortcuts related to Copilot Edits. You can modify any of the default keyboard
shortcuts by using the Keyboard Shortcuts editor ( ⌘K ⌘S ).

• ⇧⌘I - Open the Copilot Edits view


• ⌥⌘Enter - Send a prompt from the Chat view to Copilot Edits
• ⌘/ - Attach context to your prompt
• unassigned - Save all edited files to disk
• ⌘Enter - Accept all edits
• ⌘Backspace - Discard all edits
• ⇧⌥F5 - Navigate to the previous edit within a file
• ⌥F5 - Navigate to the next edit within a file

Tip
If you want to change a keyboard shortcut for an action that's specific to the Copilot Edits view, you need to include the
following condition in the when clause: chatLocation == 'editing-session' .

Limitations

• Multiple simultaneous edit sessions are not supported yet.


• The use of @workspace /new to scaffold a new project is not supported yet in an Edit session. For now, use Copilot Chat for
the initial scaffolding.
• Although #codebase is great at finding relevant context for your query, subsequent generated edits are of widely varying
quality. Experiment with the

12 sur 15 19/02/2025 17:44


Copilot Edits https://code.visualstudio.com/docs/copilot/copilot-edits

! (vscode://settings/github.copilot.chat.edits.codesearch.enabled)github.copilot.chat.edits.codesearch.enabled
(preview) setting for an improved, agentic experience to find files, or explicitly add files to your working set to create better
results.
• Support for Jupyter notebooks, other custom text formats, and binary file formats is absent or untested.
• The working set is currently limited to 10 files.
• Copilot Edits is limited to 7 editing requests per 10 minutes.

Frequently asked questions

How is Copilot Edits different from Copilot Chat?


Both Copilot Chat (/docs/copilot/copilot-chat) and Copilot Edits use a conversational interface, where you can use natural
language prompts to get AI-powered suggestions. There are several distinct differences between Copilot Edits and Copilot Chat.

Copilot Edits puts you in the context of code editing, where you start an edit session and use prompts for making changes to your
codebase. Copilot Edits can generate and apply code changes directly across multiple files in your codebase. You can
immediately preview the generated edits within the context of your code.

The Chat view (/docs/copilot/copilot-chat#_chat-view) gives you a more general-purpose chat interface for asking questions
about your code or technology topics in general. Copilot can also provide code suggestions and generate code blocks as part of
the chat conversation. You need to manually apply each code block to the different files in your project to evaluate their validity.

Inline Chat (/docs/copilot/copilot-chat#_inline-chat) keeps you in the coding flow by providing a chat interface in the editor, where
you can preview the generated code suggestions directly in the context of your code. The scope of Inline Chat is limited to the
editor in which it's started, so it can only provide code suggestions for a single file. You can also use Inline Chat to ask general-
purpose questions.

Copilot Edits also provides you a code review flow where you can easily review generated edits and decide to accept or discard
them. Copilot Chat does not have this code review mechanism. In addition, you can undo past edits and roll back changes to a
previous accepted state.

The following table shows a comparison of the capabilities of each experience.

Capability Copilot Edits Chat view Inline Chat Quick Chat

Multi-file edits ✅ ✅* ✅*

Preview code edits ✅ ✅

Code review flow ✅

Roll back changes ✅

Attach context ✅ ✅ ✅ ✅

Use participants & commands ✅ ✅

Generate shell commands ✅ ✅

General-purpose chat ✅ ✅ ✅

* code blocks are included in the chat conversation and need to be applied to the right file manually

Can I change the location of the Copilot Edits view?


You can drag and drop the Copilot Edits view into the Activity Bar to show it in the Primary Side Bar. You can also move it to the

13 sur 15 19/02/2025 17:44


Copilot Edits https://code.visualstudio.com/docs/copilot/copilot-edits

Secondary Side Bar. Learn more about custom layouts (/docs/editor/custom-layout#_workbench) in VS Code.

Why would I use edit mode instead of agent mode?


Consider the following criteria to choose between edit mode and agent mode:

• Edit scope: you might use edit mode if your request involves only code edits and you know the precise scope and working
set for the changes.
• Preview feature: agent mode is still in preview and might not work for all scenarios.
• Duration: agent mode involves multiple steps to process a request, so it might take longer to get a response. For example,
to determine the relevant context and files to edit, determine the plan of action, and more.
• Non-deterministic: agent mode evaluates the outcome of the generated edits and might iterate multiple times. As a result,
agent mode can be more non-deterministic than edit mode.
• Request quota: in agent mode, depending on the complexity of the task, one prompt might result in many requests to the
backend.

Can I use Copilot Edits with notebooks?

Copilot Edits support is limited when you're using notebooks. For example, agent mode is not available for working with notebooks
in VS Code.

We recommend that you use Copilot Chat (/docs/copilot/copilot-chat) or Inline Chat (/docs/copilot/copilot-chat#_inline-chat) with
notebooks in VS Code instead.

Related content

• Get a quick overview of the Copilot features in VS Code (/docs/copilot/copilot-vscode-features)


• Use Copilot Chat for AI chat conversations (/docs/copilot/copilot-chat)

Was this documentation helpful?

Yes No

02/06/2025

Subscribe(/feed.xml) Ask questions(https://stackoverflow.com/questions/tagged/vscode)

Follow @code(https://go.microsoft.com/fwlink/?LinkID=533687)

Request features(https://go.microsoft.com/fwlink/?LinkID=533482)

Report issues(https://www.github.com/Microsoft/vscode/issues)

Watch videos(https://www.youtube.com/channel/UCs5Y5_7XK8HLDX0SLNwkd3w)

14 sur 15 19/02/2025 17:44


Copilot Edits https://code.visualstudio.com/docs/copilot/copilot-edits

(https://
www.microsoft.com)

(https://go.microsoft.com/fwlink/?LinkID=533687)
(https://github.com/microsoft/vscode) (https://www.youtube.com/@code)

Support (https://support.serviceshub.microsoft.com/supportforbusiness/create?sapId=d66407ed-3967-b000-4cfb-2c318cad363d)
Privacy (https://go.microsoft.com/fwlink/?LinkId=521839) Terms of Use (https://www.microsoft.com/legal/terms-of-use)
License (/License)

15 sur 15 19/02/2025 17:44

You might also like