VS Code 中的 Copilot
说明 VS Code Copilot 的 agents、Plan、Sessions、inline suggestions、inline chat、smart actions、customization 和安全边界。
VS Code 是 Copilot 能力最集中的入口之一。VS Code 官方文档把它描述为把 AI agents 带进编辑器:你描述要构建什么,agent 自己规划方法、写代码、验证结果;更小的改动则用 inline suggestions 和 chat 精确控制——一句话:大改用 agent,小改用 inline。
这意味着 VS Code 里的 Copilot 不是单一聊天框,而是一组工作面:agent session、Plan、inline suggestions、inline chat、smart actions、custom instructions、agent skills、custom agents、MCP、hooks。
阅读目标:读完本章,你应该能在 VS Code 中选择“Agent、Plan、inline suggestion、inline chat、smart action”中的合适入口,并知道如何验收。
1. VS Code 的能力地图
- Agents:自主完成 coding task,拆步骤、改文件、运行命令并自我修正;适合多步骤功能、bug 修复、迁移和测试验证。
- Plan agent:先分析代码库、提出计划和澄清问题,不直接写代码;适合商业项目、大改动和需求不清的任务。
- Sessions view:管理多个本地、后台、云端或第三方 agent sessions;适合并行任务、暂停恢复和交接。
- Inline suggestions:你打字时给代码建议,从单行到函数;适合局部补全和低风险小改。
- Inline chat:
Cmd/Ctrl+I在编辑器里发起局部改写;适合小范围重构、解释和快速修复。 - Smart actions:预置常见动作,例如 commit message、rename、fix errors、semantic search;适合高频小任务。
- Customization:instructions、skills、custom agents、MCP 和 hooks;适合团队规范、工具扩展和自动化策略。
flowchart TD
Work["VS Code 中的任务"] --> Small{"局部还是多步骤?"}
Small -->|局部补全| Inline["Inline suggestions"]
Small -->|局部改写| InlineChat["Inline chat"]
Small -->|多步骤| Plan{"需要先审计划?"}
Plan -->|是| Planner["Plan agent"]
Plan -->|否| Agent["Agent session"]
Agent --> Verify["review files / commands / tests"]
Planner --> Agent
Work --> Custom["instructions / skills / MCP / hooks"]
Custom --> Agent
style Planner fill:#dbeafe,stroke:#2563eb,stroke-width:2px
style Verify fill:#dcfce7,stroke:#16a34a,stroke-width:2px
2. 第一次设置
VS Code 官方页给出的入门步骤是:在 Status Bar 的 Copilot 图标上选择 Set up Copilot,选择登录方式并按提示操作。如果还没有 Copilot subscription,会注册到 Copilot Free plan。
第一轮不要直接让 agent 创建完整项目。更稳的顺序:
- 打开一个低风险仓库。
- 确认 Copilot 登录状态。
- 打开 Chat view。
- 先用 Ask/Chat 解释当前文件。
- 再用 inline suggestion 补一个小函数或测试。
- 最后尝试一个受控 Agent session。
3. Agent session 怎么用
VS Code 官方页说明,agent 会处理从单文件改动到完整 feature PR 的 coding task。它可以构建功能、调试 failing tests、重构/迁移代码库、通过 integrated browser 测试 web app,也可以通过 cloud agent 协作生成 PR。
但 agent 能做,不代表第一次就要放开。推荐 prompt:
用 agent 修复这个 failing test。
边界:
1. 先列计划,不要马上改文件
2. 只改 src/auth 和 tests/auth
3. 需要运行命令前先说明命令和原因
4. 完成后给出 diff 摘要和测试结果验收:
- Sessions view 里能看到当前任务状态。
- Working set 只包含预期文件。
- Terminal command 有人工确认。
- 测试、build 或浏览器验证真实运行。
- 需要交给 Cloud Agent 或 PR 时,保留可 review 的分支。
4. Plan before you build
官方 VS Code 文档明确写到:Plan agent 会在写代码前分析代码库、提出澄清问题并产出 step-by-step plan;计划正确后,可以交给 implementation agent 本地、后台或云端执行。
适合使用 Plan:
- 需求不清。
- 涉及多目录、多模块或迁移。
- 影响鉴权、支付、数据模型、部署。
- 需要团队 review 方案。
- 你不确定测试入口和回滚方式。
深读:为什么 VS Code 的 Plan 不等于普通聊天计划
普通聊天计划只是模型给出的文字建议。VS Code 的 Plan agent 处在编辑器和代码库上下文里,会围绕任务研究代码、提出开放问题、拆实施步骤,并能把计划交给后续 agent 执行。它仍然需要人工审查,但比“请给我一个方案”的普通对话更适合真实工程任务。
5. 小改动用 inline suggestions 和 inline chat
官方 VS Code 文档把 “AI assistance as you type” 单独列出来,因为很多任务不需要 agent:
- Inline suggestions:从单行补全到函数实现,适合你已经知道要写什么。
- Next edit suggestions:根据当前编辑预测下一处逻辑改动。
- Inline chat:
Cmd+I/Ctrl+I在编辑器中打开 prompt,适合局部解释、重构或修复。 - Smart actions:常见 AI 动作,例如生成 commit message、重命名、修错误、语义搜索。
判断标准很简单:如果你能明确指出“就改这几行”,不要启动大 agent;如果任务需要找文件、跑命令、迭代修复,再用 Agent。
6. Customization 是长期质量入口
VS Code 官方文档列出几类 customization:
- Custom instructions:项目级编码约定,让 AI 输出匹配代码库风格。
- Agent skills:跨 VS Code、Copilot CLI 和 Cloud Agent 复用专门能力。
- Custom agents:创建特定角色 agent,例如 code reviewer、documentation writer。
- MCP servers:通过 MCP server 或 Marketplace extension 扩展工具。
- Hooks:在特定事件执行命令,用于自动化和策略 enforcement。
这些能力是商业级团队落地 Copilot 的关键。没有 customization,agent 每次都需要重新猜项目约定;有了 customization,也要定期清理过期规则,避免把旧上下文注入所有任务。
7. 组织策略和价格状态
VS Code 官方页提示:你的组织可能禁用了 VS Code 中的 agents,需要联系管理员开启。页面还在 2026-05-06 核验时提示:从 2026-04-20 起,Copilot Pro、Copilot Pro+ 和 student plans 新注册临时暂停,并且 weekly usage limits 正在收紧。
因此:
- 团队教程不要写死某个 plan 永久可注册。
- Agent、模型、MCP、CLI、Cloud Agent 是否可用,要看管理员策略。
- 复杂任务启动前要知道是否会消耗 premium requests。
本章自检
完成本章后,用这 4 个问题检查:
- 当前任务应该用 inline suggestion、inline chat、Plan 还是 Agent?
- 如果使用 Agent,是否已经限定文件范围、命令权限和验证命令?
- 项目是否有 custom instructions、skills、MCP 或 hooks 需要注入?
- 组织是否允许 VS Code agents、模型切换和相关功能?
通过标准:你能在 VS Code 中让 Copilot 先规划、再受控修改、再用 diff/test/browser/PR 验收。
官方来源
- GitHub Copilot in VS Code —— VS Code 官方 Copilot 总览,覆盖 agents、Plan、sessions、inline suggestions、inline chat、smart actions、customization 和 pricing 提示。
- Asking GitHub Copilot questions in your IDE —— GitHub 官方 IDE Chat 文档,覆盖 Chat、keywords、MCP、models、Plan mode 和 Agent mode。
- Quickstart for GitHub Copilot —— GitHub 官方快速开始,用于核对账号、VS Code 前提和当前 plan 状态。