Using agents in Visual Studio Code

An agent is an AI assistant that works autonomously to complete a coding task. Give it a high-level goal, and it breaks the goal into steps, edits files across your project, runs commands, and self-corrects when something goes wrong. For example, instead of suggesting a fix for a failing test, an agent identifies the root cause across files, updates the code, reruns the tests, and commits the changes.

Agents handle tasks end-to-end. Use them to build features across multiple files, debug and fix failing tests, refactor between frameworks, test web apps with the integrated browser, or ship a pull request for team review.

This article walks through the choices you make when working with agents: which agent type to use, which agent to give the task to, how much autonomy to grant, and where to do the work.

How agents work

Understand the agent loop, how agents plan and execute tasks, and how memory and subagents work.

Screenshot of an agent session in VS Code showing code changes and chat interaction.

Tip

Enable agents in your VS Code settings ( chat.agent.enabled Open in VS Code Open in VS Code Insiders This setting is managed at the organization level. Contact your administrator to change it.). Your organization might also disable agents - contact your admin to enable this functionality.

Key choices when working with agents

Working with agents comes down to a few decisions. You can adjust each one per task and change your mind at any time:

  • Choose where to work: work in the editor window or the dedicated Agents window.
  • Choose an agent type: decide where and how the agent runs, on your machine, in the background, in the cloud, or through a third-party provider.
  • Choose an agent: pick the agent persona that matches the task, such as building, planning, or answering questions, and the language model that fits.
  • Choose a permission level: decide how much autonomy the agent has to run tools and commands.

You can also hand off a session from one agent to another to take advantage of their different strengths.

Where to work with agents

VS Code gives you different surfaces for working with agents, and you can pick the one that matches your workflow or move freely between them:

  • Agents window (agent-first, Preview): a dedicated window for working across multiple projects from a single place. Chat and the sessions list are the primary interface, where you prompt agents and describe the functional tasks you want accomplished. Best when your primary workflow is thinking in prompts and orchestrating agents across workspaces.

  • Chat view (code-first): chat lives alongside your editor tabs in the main VS Code window, with full access to debugging, notebooks, the extension ecosystem, and remote development. AI assists your coding through chat, inline suggestions, and agent sessions. Best when you're primarily writing and editing code in a single workspace.

Both surfaces share agent sessions and VS Code configuration like settings and keybindings, making transitions smooth. Open the Agents window with the Open in Agents button in the title bar. Learn more about the Agents window.

Types of agents

Agents run in different environments depending on when you need results and how much oversight you want. Learn more about the agent types and how they work.

  • Local: use the VS Code agent loop to run the agent interactively in the editor with full access to your workspace, tools, and models.
  • Copilot CLI: use the Copilot CLI to run in the background on your machine, optionally using Git worktrees for isolation.
  • Cloud: use GitHub Copilot to run remotely and integrate with GitHub pull requests for team collaboration.
  • Third-party: use the third-party agent harness and SDK from Anthropic and OpenAI to run either locally on your machine or in the cloud.

Select the agent type from the agent target dropdown in the Chat view.

Screenshot showing agent target dropdown in the Chat view.

You can also run agent sessions on a remote machine you own and monitor them from anywhere, whether from the Agents window, a browser, or your phone. Sessions keep running on the remote even when you disconnect, so you can close your laptop and check back later. Learn more about remote agent sessions.

Which agent type should I use?

Use the following table to find the right agent type for your task:

I want to... Use
Iterate interactively, get answers about my codebase, plan, or fix issues that need editor context like test failures and debug output Local agent
Implement a well-defined task or explore proof of concepts while I keep working Copilot CLI or Cloud agent
Create a PR for team review or assign a GitHub issue to an agent Cloud agent
Use a specific AI provider, such as Anthropic or OpenAI Third-party agent

Choose an agent

If the agent type is where the agent runs, the agent determines how to perform the task based on its role or persona. For example, an agent with a code reviewer persona focuses on reviewing code changes for quality and style and providing feedback, instead of making code changes. The agent's definition determines which tools it can use, how it executes tasks, and potential handoff points to other agents.

Select an agent from the agents dropdown in the Chat view. You can switch between agents at any time during a session.

Screenshot showing the agent picker in the Chat view.

VS Code has three built-in agents:

  • Agent: autonomously plans and implements changes across files, runs terminal commands, and invokes tools.
  • Plan: creates a structured, step-by-step implementation plan before writing any code. Hands the plan off to an implementation agent when it looks right.
  • Ask: answers questions about coding concepts, your codebase, or VS Code itself without making file changes.

For more specialized workflows, create your own custom agents that define a specific role, available tools, and a language model.

Within a session, you can also pick the language model that best fits the task. Use a fast model for quick edits and questions, or a model with stronger reasoning for complex, multi-step work. Switch models at any time from the model picker in the Chat view. Learn more about language models.

Choose a permission level

Agents perform tasks autonomously, but you can control how much autonomy they have for invoking tools and terminal commands. Giving agents more autonomy can increase efficiency but may reduce oversight. The permissions picker in the Chat view lets you choose a permission level for each session, from approving every tool call to letting the agent work fully on its own.

Permission level Description
Default Approvals Uses the approvals as specified in VS Code settings. By default, only read-only and safe tools don't require explicit approval.
Bypass Approvals Auto-approves all tool calls without confirmation dialogs. The agent might ask clarifying questions as it works.
Autopilot (Preview) Auto-approves all tool calls, auto-responds to questions, and the agent continues working autonomously until the task is complete.

To persist your preferred permission level across sessions, configure the chat.permissions.default Open in VS Code Open in VS Code Insiders setting.

Learn more about permission levels and Autopilot.

Hand off a session to another agent

You can hand off an existing task from one agent to another agent to take advantage of their unique strengths. For example, create a plan with a local agent, hand off to Copilot CLI for proof of concepts, and then continue with a cloud agent to submit a pull request for team review.

To hand off a local agent session, select a different agent type from the session type dropdown in the chat input box. VS Code creates a new session, carrying over the full conversation history and context. The original session is archived after handoff.

Screenshot showing the session type dropdown for handing off to another agent.

In a Copilot CLI session, delegate to a cloud agent by entering the /delegate command in the chat input box. You can provide additional instructions after the /delegate command.