×

注意!页面内容来自https://code.visualstudio.com/docs/copilot/agents/copilot-cli,本站不储存任何内容,为了更好的阅读体验进行在线解析,若有广告出现,请及时反馈。若您觉得侵犯了您的利益,请通知我们进行删除,然后访问 原网页

Copilot CLI sessions in Visual Studio Code

Visual Studio Code supports running agent sessions in the background by using GitHub Copilot CLI. You can startmonitorand manage your Copilot CLI sessions from the unified Chat view in VS Codewhile the agents run autonomously on your local machine while you continue other work in the editor. Run multiple Copilot CLI sessions in parallel to tackle independent tasks simultaneously.

To start a Copilot CLI sessionyou can either create a new session or hand off a local agent session to Copilot CLIpassing on existing context.

This article covers the key features of Copilot CLI agentsand how to start and manage background sessions from Copilot CLI.

Screenshot of Copilot CLI session as a chat editor in VS Code.

Tip

If you primarily work with agents across multiple projectsyou can also manage your Copilot CLI sessions in the Agents windowan agent-first surface that shares sessions with the main VS Code window.

Tip

Third-party providers like OpenAI Codex also offer background capabilities. Learn more about third-party agents.

What are Copilot CLI sessions?

Copilot CLI sessions run independently in the background on your local machine and use the Copilot CLI agent harness. VS Code integrates with these agents by using the Copilot SDK to startstopand monitor progress of your background sessions. VS Code automatically installs and configures the Copilot CLI for you.

Copilot SDK sessions run outside of VS Code and continue to run in the background when you close your VS Code window. This behavior is unlike local agents that use the VS Code agent harness inside the editor and stop running when VS Code stops.

You can interact with Copilot CLI sessions from the unified Chat view. When a background session requires your input or needs permissions to perform an actionyou can do so from within chat. The agent status indicator also provides hints when a session needs input.

Because Copilot CLI sessions run in the backgroundthey are well-suited for tasks that have a well-defined scopehave all necessary contextand don't require frequent user interaction. Examples include implementing a feature from a plancreating multiple variants of a proof of conceptor implementing clearly defined fixes or features.

Copilot CLI supports slash commands in chatincluding reusable promptsagent skillshooks/compact to manage long conversationsand /yolo or /autoApprove to toggle auto-approval of tools. Type / in the chat input of a Copilot CLI session to see available commands.

Isolation modes

Copilot CLI supports two types of isolation modes to manage how changes from the agent are applied to your codebase: Worktree and Workspace isolation. You can choose the isolation mode when you create a new Copilot CLI session.

To isolate changes from the Copilot CLI agent and prevent interference with your active workuse Worktree isolation. In this modeVS Code creates a Git worktree in a separate folder for the Copilot CLI session. All changes made by the agent are applied to the worktreekeeping them separate from your main workspace until you're ready to review and apply them.

If you want the changes from the Copilot CLI session to be applied directly to your current workspaceyou can choose Workspace isolation. In this modethe agent operates directly in your current workspaceand changes are applied in place.

Note

To use Git worktrees and worktree isolationyour workspace needs to be a Git repository.

Permissions and approvals

Copilot CLI sessions support the same permission levels as local agents. The available permission levels depend on the isolation mode you choose:

  • Worktree isolation: the permission level is automatically set to Bypass Approvals and can't be changed. Because the agent operates on an isolated copy of your codebase (Git worktree)all tool calls are auto-approved without confirmation dialogs.
  • Workspace isolation: all three permission levels are available (Default ApprovalsBypass Approvalsand Autopilot)just like local agent sessions. Select a level from the permissions picker in the chat input area.

Create a Copilot CLI session

To create a new Copilot CLI session in VS Code:

  1. Create a new session using either of these options

    • Open the Chat view (⌃⌘I (WindowsLinux Ctrl+Alt+I)) and select Copilot CLI from the Session Target dropdown

    • Select the New Chat icon at the topand select New Copilot CLI Session

    • Run the Chat: New Copilot CLI command from the Command Palette (⇧⌘P (WindowsLinux Ctrl+Shift+P))

  2. Choose between workspace or worktree isolation mode

    If you use worktree isolationthe agent automatically commits changes to the worktree at the end of each turnso the session history stays aligned with the commit history.

    Tip

    You can open the worktree of a session by right-clicking it in the session list and selecting Open Worktree in New Window. You can also view the worktree in the Source Control view repository explorer (scm.repositories.explorer).

  3. Submit your prompt to start the agent. Optionallyadd extra context or choose a specific language model and custom agent.

  4. Track the session status in the Chat view.

Tip

You can create multiple Copilot CLI sessions to work on different tasks in parallel.

Hand off a local session to Copilot CLI

For complex tasksit can be helpful to first interact with a local agent in VS Code to clarify requirementsand then hand off the task to Copilot CLI for autonomous execution in the background. This can be useful when using the Plan agent to create a plan and then hand off the implementation of that plan to Copilot CLI.

When you hand off a local agent conversation to a Copilot CLI sessionthe full conversation history and context is passed to the background session.

To hand off a local agent session to Copilot CLI:

  1. Open the Chat view (⌃⌘I (WindowsLinux Ctrl+Alt+I))

  2. Interact with a local agent until you're ready to hand off the task

  3. To hand off to Copilot CLIyou have the following options:

    • Open the Session Target dropdown and then select Copilot CLI

      Screenshot showing the Session Target dropdown in VS Code chat interface.

    • If you're using the Plan agentselect the Start Implementation dropdown and the select Continue in Copilot CLI to run the implementation in a Copilot CLI session

      Screenshot showing the "Start Implementation" button in VS Code chat interface.

The Copilot CLI session starts automaticallycarrying over the full conversation history and context.

Remote control Copilot CLI sessions (Experimental)

The "/remote on" command lets you remote control a Copilot CLI session from github.com or the GitHub Mobile app. With remote controlyou can monitor and steer your ongoing Copilot CLI sessions from anywheregiving you more flexibility to keep work moving without being tied to your machine. You keep the full session context and history in sync across both VS Code and GitHub.

When remote control is enabledVS Code streams the session historytool activityand status updates to the linked GitHub task page in real time. Actions you take in one place are reflected in the other. If the session requires approval for a tool call or input for a questionthe prompt is shown in both places and you can respond from either location.

To use remote control for a Copilot CLI session:

  1. Start or resume a Copilot CLI session from the Chat view.

  2. Enter "/remote on" in the chat input to enable remote control and create the linked GitHub task page.

  3. Select Open on GitHub to open the linked task page or scan the QR code to open it on your mobile device.

Run "/remote" at any time to check the current remote-control status. The "/remote" command only shows status and does not enable or disable remote control.

To stop mirroring the session to GitHubenter "/remote off" in the chat input.

To disable remote control support for Copilot CLI sessions in VS Codedisable the github.copilot.chat.cli.remote.enabled Open in VS Code Open in VS Code Insiders setting.

Note

Remote control requires GitHub authentication in VS Code and a workspace that maps to a GitHub repository. If additional GitHub permissions are neededVS Code prompts you to grant them before remote control is enabled.

Use Copilot CLI from the terminal

In addition to starting Copilot CLI sessions from the Chat viewyou can use Copilot CLI directly from the VS Code terminal.

Screenshot showing the Copilot CLI session inside VS Code.

Open a Copilot CLI terminal

VS Code registers a GitHub Copilot CLI terminal profile that you can use to open a dedicated Copilot CLI terminal. You can open a Copilot CLI terminal in several ways:

  • Select the dropdown next to the + button in the Terminal panel and select GitHub Copilot CLI

  • Run the Chat: New Copilot CLI Session command from the Command Palette to open a Copilot CLI terminal in the panelor run Chat: New CLI Session to the Side to open it in an editor tab beside your current editor

  • Run the Terminal: Create New Terminal (With Profile) command from the Command Palette (⇧⌘P (WindowsLinux Ctrl+Shift+P)) and select GitHub Copilot CLI

  • Type copilot in any VS Code integrated terminal to start the Copilot CLI directly

The Copilot CLI terminal supports the following shells:

  • bash and zsh on macOS and Linux
  • PowerShell and Command Prompt on Windows

Start and resume sessions from the terminal

When you start a new session from the Copilot CLI terminalVS Code automatically detects the session and displays it in the Chat view sessions list. You can then track progresssend follow-up promptsor review changes from either the terminal or the Chat view.

To resume an existing Copilot CLI session in the terminalright-click the session in the sessions list and select Resume in Terminal.

VS Code automatically handles authentication for the Copilot CLI terminalso you don't need to sign in separately.

Multi-repository workspaces

If your workspace contains multiple Git repositoriesVS Code displays a repository picker in the chat input when you start a Copilot CLI session. Use this picker to select which repository the worktree should be created in.

After the session startsthe repository picker becomes disabled for that session. The worktree appears under the selected repository in the Worktrees node in the Source Control Repositories view.

Tip

To view all repositories in your workspaceenable the scm.repositories.explorer Open in VS Code Open in VS Code Insiders setting and open the Source Control view.

Use custom agents with Copilot CLI

Custom agents let you define custom personas and roles for agents in VS Code. For exampleyou might create a custom agent for performing code reviews. Custom agents can define specific instructions and behaviors.

When you create a Copilot CLI sessionyou can select a custom agent to handle the task. The custom agent operates according to the defined behavior.

To use custom agents with Copilot CLI:

  1. Enable custom agents for Copilot CLI with the github.copilot.chat.cli.customAgents.enabled Open in VS Code Open in VS Code Insiders setting

  2. Create a custom agent in your workspace with the Chat: New Custom Agent command from the Command Palette (⇧⌘P (WindowsLinux Ctrl+Shift+P))

  3. Create a new Copilot CLI session and select the custom agent from the Agents dropdown

    Screenshot showing custom agent selection in VS Code chat interface.

  4. Enter a prompt and notice that the custom agent is used to handle the task

Note

Currentlyonly custom agents defined in the workspace are available for Copilot CLI sessions. Learn more about creating a custom agent.

Limitations of Copilot CLI sessions

  • Copilot CLI sessions can't access all VS Code built-in tools. You can explicitly add context in the chat input.

  • Don't have access to extension-provided tools and are limited to the models available via the CLI tool.

  • Can currently only access local MCP servers that don't require authentication.