如何在 VS Code 中无缝续接 GitHub Copilot 独立应用的会话任务
英文标题:How to continue a GitHub Copilot app session in VS Code
GitHub 宣布支持将 GitHub Copilot 独立客户端(Copilot app)中的 Agent 任务会话直接一键迁移至 VS Code 中继续进行。迁移过程中将完整保留原有的任务上下文、对话记录、代码 Diff 以及独立的 Git 工作树(worktree),无需重新输入 Prompt 或手动同步分支代码。开发者能够在本地编辑器中进行逐行审查、手动微调和本地测试验证,并将更改直接推送到关联的 Pull Request。这种衔接机制实现了“Agent 负责繁琐实现,开发者掌舵审查与调试”的无缝协同,有效消除了 AI 编程中的上下文断层。
66.7 KB
30.1 KB
79.6 KB
37.8 KB
74.6 KB
34.0 KB
134.3 KB
54.6 KB
69.7 KB
34.0 KB
62.7 KB
31.8 KB
72.1 KB
37.3 KB
198.0 KB
134.0 KB
11.0 KB
17.6 KB
111.4 KB
33.8 KB
中文
Agent 已经完成了大部分代码修改。现在你想检查某处具体的实现细节,手动微调几行代码,并在发布前在本地运行该项目。
但这些工作目前还停留在 GitHub Copilot app 中……而你的编辑器才是查看 diff 对比、调试代码以及做最终调整的地方。难道你必须在“留在会话中”和“在 Visual Studio Code 中从头开始”之间做选择吗?
完全不需要。你可以直接在 VS Code 中打开 Copilot app 会话,完整保留其对话历史、代码变更和工作上下文并继续工作。这意味着 Copilot 可以负责繁琐或耗时的开发任务,然后将控制权交还给你,以便进行更细致的代码审查、上手修改和本地测试。
在本教程中,你将学习如何:
- 在 VS Code 中打开 Copilot app 会话。
- 逐行审查 Agent 所做的修改。
- 在编辑器中继续进行同一段对话。
- 在本地修改并测试代码。
- 将你的更新推送到与该会话关联的 Pull Request。
前提条件
在开始之前,请确保你已具备:
- 已安装并登录 GitHub Copilot app。
- 已安装 Visual Studio Code 并连接到同一个 GitHub 账号。
- 拥有一个包含你想审查或继续操作的代码修改的 Copilot app 会话。
- 拥有对该会话所属代码仓库的工作与推送权限。
本教程假设你已熟悉 VS Code 的操作、在其集成终端中运行命令,以及使用 Git 分支和 Pull Request。
1. 从 Copilot app 会话开始
打开你想要继续的会话。在交接之前,稍作停留,回顾一下该任务以及 Copilot 已经完成的工作。
一个会话所包含的远不止一组被修改的文件。它还记录了任务目标、执行计划以及产生这些修改的对话过程。当你想要理解 Copilot 为何选择某种特定实现,或要求它修改部分工作时,这种上下文信息至关重要。
在转到 VS Code 之前,你不需要对历史记录做总结,也不需要将其复制到新的聊天中。
2. 在 VS Code 中打开会话
在会话中选择 Open in VS Code。如果该应用提供了多个支持的编辑器或 VS Code 安装版本,请选择你希望使用的那一个。
VS Code 会使用与该会话关联的工作树(worktree)打开项目,同时在 Copilot 侧边栏中显示现有的会话。
这将为你带来原始工作中相互关联的三大核心要素:
- 会话上下文(The session context): 任务、计划和对话依然完好可用。
- 差异比对(The diff): Agent 修改的文件和代码行已就绪,可供审查。
- 工作树(The worktree): VS Code 打开的是该会话所使用的同一个隔离工作树。
你是在继续现有的会话,而不是在新的编辑器窗口中重新构建它。
3. 审查 Agent 的修改
在开始编辑前,先在 VS Code 中检查 diff 差异。打开源代码管理(Source Control)视图查看已修改的文件,然后选择某个文件逐行审查其变动。
像审查其他人提交的修改一样审查这些代码实现。特别是要检查:
- 代码是否解决了所要求的问题。
- 代码实现是否遵循了仓库的代码规范。
- 错误状态与边界情况是否得到了妥善处理。
- 测试是否覆盖了变更的行为。
- 没有修改无关的文件或逻辑。
保留下来的对话有助于解释 Copilot 是如何得出该实现的。如果有任何不明确的地方,可以在侧边栏中继续向 Copilot 提问。例如:
Explain why you changed this function instead of adding a new helper. Identify any behavior this could affect.
你也可以要求 Copilot 进行另一项修改。因为会话和工作树保持连接状态,所以你无需从头开始重新描述任务。
4. 手动修改代码
理解了提议的变更后,即可直接在 VS Code 中编辑任何文件。
对于手动操作更快或更方便的微调,这种方式非常实用,例如:
- 优化文案标签或错误提示信息。
- 重命名变量以提高可读性。
- 调整布局或样式。
- 补充缺失的测试用例。
- 应用仓库特有的约定规范。
由于你是在编辑该会话现有的工作树,因此你的手动修改会直接建立在 Agent 的工作基础之上。你不需要在目录之间复制文件,也不需要手动重建分支。
5. 在本地运行并验证项目
使用 VS Code 的集成终端运行项目常规的验证工作流。具体命令取决于代码仓库,以常见 Web 应用为例,可能包括:
npm installnpm testnpm run lintnpm run dev
对待 Agent 生成的代码,要像对待人工编写的代码一样:运行相关测试,检查失败项,并亲自验证其运行行为。
如果开发服务器输出了 localhost 网址,请在浏览器中打开以测试修改。若你的 VS Code 环境支持,你也可以在 VS Code 内置浏览器中打开该 URL,无需离开编辑器即可查看效果。
对于 UI 界面修改,既要验证预期的目标功能,也要检查相关的周边状态。例如,在不同的视口尺寸下检查修改后的组件,并确认加载、空数据和错误状态均能正常工作。
6. 继续交由 Copilot 处理或自行编辑
在任何时候,你都可以选择最契合下一步操作的交互方式:
- 当修改需要全仓库级别的分析或重复性编辑时,向 Copilot 发送 Prompt。
- 当你清楚明确地知道想要做什么修改时,直接上手编辑。
- 在测试和完善实现的过程中,交替迭代使用这两种方法。
例如,在手动调整 UI 后,你可以向 Copilot 提出:
Add a test for the updated label and run the relevant test file. Do not modify unrelated components.
因为你仍处于原始会话中,Copilot 保留了解释“the updated label”(更新后的标签)所需的上下文。
7. 提交并推送最终修改
当代码实现就绪后,最后再检查一次完整的 diff。然后通过源代码管理视图或集成终端提交并推送变更:
git statusgit addgit commit -m "Refine session changes"git push
遵循仓库既有的分支、提交、审查和审批规范。因为 VS Code 打开的是与该会话关联的工作树和分支,推送该分支会直接更新已经在跟踪这项工作的 Pull Request。
无需将完成的文件复制到另一个 checkout 目录,也不需要手动重新连接到 Pull Request。
从 Agent 到编辑器的无缝工作流
在 VS Code 中打开 Copilot app 会话为你提供了清晰的分工边界,同时又不会割裂工作本身。Copilot 可以承担更大规模或重复性的实现工作,而你可以随时切换到编辑器进行细致审查、针对性修改、本地测试和最终打磨。
会话、Diff 和工作树会全程伴随你。你可以先在 Copilot app 中指导工作,随时切换到 VS Code 获得直接掌控权,并通过相同的 Pull Request 工作流推送最终成果。
准备好尝试了吗?下载 GitHub Copilot app,发起一个会话,并在准备好继续编码时在 VS Code 中打开它。
作者信息
Senior AI Developer Tools Advocate
English / 原文
The agent has finished the bulk of your change. Now you want to inspect one implementation detail, adjust a few lines by hand, and run the project locally before you ship it.
But the work is sitting in the GitHub Copilot app… and your editor is where you review diffs, debug code, and make final adjustments. Do you have to choose between staying in the session and starting over in Visual Studio Code?
You don’t. You can open the Copilot app session directly in VS Code and continue with its conversation, code changes, and working context intact. That means Copilot can handle the repetitive or time-consuming work, then hand control back to you for closer review, hands-on editing, and local testing.
In this tutorial, you’ll learn how to:
- Open a Copilot app session in VS Code.
- Review the agent’s changes line by line.
- Continue the same conversation from your editor.
- Modify and test the code locally.
- Push your updates to the pull request associated with the session.
Prerequisites
Before you begin, make sure you have:
- The GitHub Copilot app installed and signed in.
- Visual Studio Code installed and connected to the same GitHub account.
- A Copilot app session with code changes you want to review or continue.
- Permission to work in and push changes to the session’s repository.
This tutorial assumes you are already comfortable navigating VS Code, running commands in its integrated terminal, and working with Git branches and pull requests.
1. Start with a session in the Copilot app
Open the session you want to continue. Before handing it off, take a moment to review the task and the work Copilot completed.
A session contains more than a collection of modified files. It also records the task, the plan, and the conversation that produced those changes. That context is important when you want to understand why Copilot chose a particular implementation or ask it to revise part of the work.
You do not need to summarize that history or copy it into a new chat before moving to VS Code.
2. Open the session in VS Code
From the session, select Open in VS Code. If the app presents more than one supported editor or VS Code installation, choose the one you want to use.
VS Code opens the project using the worktree associated with the session. It also displays the existing session in the Copilot sidebar.
That gives you three connected pieces of the original work:
- The session context: The task, plan, and conversation remain available.
- The diff: The files and lines changed by the agent are ready for review.
- The worktree: VS Code opens the same isolated working tree the session used.
You are continuing the existing session, not reconstructing it in a new editor window.
3. Review the agent’s changes
Before editing, inspect the diff in VS Code. Open the Source Control view to see the changed files, then select a file to review its changes line by line.
Review the implementation as you would any other proposed change. In particular, check that:
- The code solves the requested problem.
- The implementation follows the repository’s conventions.
- Error states and edge cases are handled appropriately.
- Tests cover the behavior that changed.
- No unrelated files or behaviors were modified.
The preserved conversation can help explain how Copilot arrived at the implementation. If something is unclear, continue prompting Copilot in the sidebar. For example:
Explain why you changed this function instead of adding a new helper. Identify any behavior this could affect.
You can also ask Copilot to make another change. Because the session and worktree remain connected, you do not have to describe the task from the beginning.
4. Make a hands-on edit
Once you understand the proposed changes, edit any file directly in VS Code.
This is useful for adjustments that are faster or easier to make by hand, such as:
- Refining a label or error message.
- Renaming a variable for clarity.
- Adjusting layout or styling.
- Adding a missing test case.
- Applying a repository-specific convention.
You are editing the session’s existing worktree, so your manual changes build directly on the agent’s work. You do not need to copy files between directories or manually re-create the branch.
5. Run and verify the project locally
Use the VS Code integrated terminal to run the project’s normal validation workflow. The exact commands depend on the repository, but some web app examples may include:
npm installnpm testnpm run lintnpm run dev
Treat agent-generated changes the same way you would treat code written by a person: run the relevant tests, inspect failures, and verify the behavior yourself.
If the development server prints a localhost URL, open it to test the change in a browser. When supported by your VS Code setup, you can open the URL in VS Code’s integrated browser and inspect the result without leaving the editor.
For a user-interface change, verify both the requested behavior and nearby states. For example, check the modified component at different viewport sizes and confirm that loading, empty, and error states still work.
6. Continue with Copilot or keep editing yourself
At any point, you can choose the interaction that best fits the next step:
- Prompt Copilot when the change requires repository-wide analysis or repetitive edits.
- Edit directly when you know the exact change you want.
- Use both approaches iteratively as you test and refine the implementation.
For example, after making a manual UI adjustment, you might ask Copilot:
Add a test for the updated label and run the relevant test file. Do not modify unrelated components.
Because you are still in the original session, Copilot retains the context needed to interpret “the updated label.”
7. Commit and push the finished changes
When the implementation is ready, review the final diff one more time. Then commit and push the changes using the Source Control view or the integrated terminal:
git statusgit addgit commit -m "Refine session changes"git push
Use your repository’s normal branch, commit, review, and approval practices. Because VS Code opened the worktree and branch associated with the session, pushing the branch updates the pull request already tracking that work.
There is no need to copy the finished files into another checkout or reconnect the work to the pull request manually.
A continuous workflow from agent to editor
Opening a Copilot app session in VS Code gives you a clean division of labor without splitting the work itself. Copilot can take on a larger or repetitive implementation, while you can move into the editor for detailed review, targeted changes, local testing, and final polish.
The session, diff, and worktree move with you. Start by directing the work in the Copilot app, switch to VS Code whenever you want hands-on control, and push the finished result through the same pull request workflow.
Ready to try it? Download the GitHub Copilot app, start a session, and open it in VS Code when you are ready to continue coding.
Written by
Senior AI Developer Tools Advocate