Enable VSCode Copilot Agent Mode for Automated Programming
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:
- Manually copy the code
- Switch to the target file
- Paste and adjust
- 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:
- Scan the
src/utilsdirectory - Find all files containing
getUserName - 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:
| Tool | Function |
|---|---|
readFile | Read file contents |
editFile | Edit files |
createFile | Create new files |
deleteFile | Delete files |
runInTerminal | Execute terminal commands |
listDirectory | List directory contents |
search | Search 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.