Skip to main content

One post tagged with "Copilot"

View all tags

Enable VSCode Copilot Agent Mode for Automated Programming

ยท 3 min read

TL;DRโ€‹

VSCode Copilot Agent Mode is an experimental feature that lets AI automatically execute multi-step tasks (including editing files and running terminal commands). Enable it by adding "github.copilot.chat.agent.enabled": true to your settings.json. Perfect for repetitive refactoring and batch file modifications.

Problemโ€‹

Traditional Copilot Chat only suggests code snippets, requiring you to:

  1. Manually copy the code
  2. Switch to the target file
  3. Paste and adjust
  4. Repeat for each change

This workflow becomes extremely inefficient when modifying multiple files.

Root Causeโ€‹

Copilot's Ask Mode is designed as a "suggester": it outputs code but doesn't execute actions. This is a safety feature, but for developers who trust AI, it adds significant manual overhead.

Agent Mode acts as an "executor": AI can directly edit files and run commands, enabling true automated programming.

Solutionโ€‹

1. Enable Agent Modeโ€‹

Add to VSCode settings.json:

{
"github.copilot.chat.agent.enabled": true
}

Or search for @id:github.copilot.chat.agent.enabled in Settings and check the box.

2. Switch to Agent Modeโ€‹

In the Copilot Chat panel, click the mode dropdown and switch from "Ask" to "Agent":

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Ask โ–ผ โ”‚ Agent โ–ผ โ”‚ Edit โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

3. Usage Examplesโ€‹

Scenario: Batch Rename Function

Rename getUserName to fetchUserProfile in all files under src/utils

Agent Mode will automatically:

  1. Scan the src/utils directory
  2. Find all files containing getUserName
  3. Modify each file and save

Scenario: Add TypeScript Types

Add return type annotations to all exported functions in src/api/*.ts

4. Tool Permission Controlโ€‹

Agent Mode requests confirmation before executing sensitive operations. Adjust in settings:

{
"github.copilot.chat.agent.autoToolConfirmation": {
"readFile": true, // Auto-allow file reading
"editFile": false, // Require confirmation for edits
"runInTerminal": false // Require confirmation for commands
}
}

5. Available Toolsโ€‹

Agent Mode can call these tools:

ToolFunction
readFileRead file contents
editFileEdit files
createFileCreate new files
deleteFileDelete files
runInTerminalExecute terminal commands
listDirectoryList directory contents
searchSearch code

FAQโ€‹

Q: What's the difference between Agent Mode and Ask Mode?โ€‹

Ask Mode only suggests code, requiring manual copy-paste; Agent Mode can directly execute file edits and terminal commands for automation.

Q: Is Agent Mode safe?โ€‹

Agent Mode requests confirmation before sensitive operations (like deleting files or running commands). Always use it in version-controlled repositories for easy rollback.

Q: Why can't I find the Agent Mode option?โ€‹

Ensure you have the latest Copilot Chat extension (v0.15+) and enable github.copilot.chat.agent.enabled in settings.

Q: What terminal commands can Agent Mode execute?โ€‹

Theoretically any command, but stick to safe development commands (like npm install, npm run build). Avoid high-risk operations like deletions or deployments.