Skip to main content
πŸŽ“ Claude Code Masterclass Learn AI-assisted development on Udemy β€” plus the companion book on Leanpub & Amazon. Start Learning
GitHub Copilot Agent Mode in VS Code: Full Guide (2026)
AI

GitHub Copilot Agent Mode in VS Code: Full Guide (2026)

Enable and master GitHub Copilot Agent Mode in VS Code. Multi-file editing, terminal commands, autonomous coding workflows, and advanced configuration.

LB
Luca Berton
Β· 3 min read

What Is Agent Mode?

GitHub Copilot Agent Mode transforms VS Code from an autocomplete tool into an autonomous coding partner. Instead of suggesting single lines, Agent Mode:

  • Plans multi-step changes across files
  • Creates, edits, and deletes files autonomously
  • Runs terminal commands (build, test, lint)
  • Iterates on errors until tests pass
  • Understands your full workspace context

Enabling Agent Mode

Prerequisites

  • VS Code 1.99+ (April 2026 or later)
  • GitHub Copilot subscription (Individual, Business, or Enterprise)
  • GitHub Copilot extension v1.250+

Activation

  1. Open the Chat panel (Ctrl+Shift+I or Cmd+Shift+I)
  2. Click the mode selector dropdown (top of chat)
  3. Select β€œAgent” mode

Or use the keyboard shortcut: Ctrl+Shift+P β†’ β€œChat: Switch to Agent Mode”

Core Capabilities

1. Multi-File Editing

Agent Mode understands your entire workspace. Ask it to refactor across files:

Prompt: "Refactor the authentication module to use JWT tokens instead of sessions.
Update all route handlers, middleware, and tests."

Agent Mode will:

  1. Analyze existing auth code
  2. Propose a plan
  3. Edit auth middleware, route files, test files
  4. Run tests to verify

2. Terminal Integration

Agent Mode can run shell commands with your approval:

Prompt: "Set up a new Express.js API with TypeScript, ESLint, Prettier, and Jest.
Initialize the project, install dependencies, and create the folder structure."

It will run npm init, npm install, create tsconfig.json, configure ESLint, etc.

3. Autonomous Error Resolution

When Agent Mode encounters errors, it iterates automatically:

  1. Makes code change
  2. Runs build/test
  3. Sees error output
  4. Fixes the error
  5. Re-runs until success

4. Context-Aware Planning

Agent Mode reads:

  • Open files and workspace structure
  • package.json, tsconfig.json, config files
  • Git history and branch context
  • Terminal output from previous commands
  • Your instructions in .github/copilot-instructions.md

Configuration

Workspace Instructions

Create .github/copilot-instructions.md:

# Project Conventions

- Use TypeScript strict mode
- Follow functional programming patterns
- Tests in __tests__/ directories with .test.ts extension
- Use pnpm as package manager
- API routes follow REST conventions
- Error handling uses Result<T, E> pattern

Settings

// .vscode/settings.json
{
  "github.copilot.chat.agent.enabled": true,
  "github.copilot.chat.agent.maxIterations": 10,
  "github.copilot.chat.agent.autoApproveTerminal": false,
  "github.copilot.chat.agent.autoApproveFileChanges": false
}

Security Controls (Enterprise)

// For GitHub Copilot Business/Enterprise
{
  "github.copilot.chat.agent.terminalCommands.blocklist": [
    "rm -rf",
    "sudo",
    "curl | sh",
    "wget | bash"
  ]
}

Agent Mode vs Edit Mode vs Chat

FeatureChatEditAgent
Answers questionsβœ…βŒβœ…
Edits current fileβŒβœ…βœ…
Multi-file editsβŒβŒβœ…
Runs terminalβŒβŒβœ…
Iterates on errorsβŒβŒβœ…
Plans autonomouslyβŒβŒβœ…
Uses MCP toolsβŒβŒβœ…

MCP Server Integration

Agent Mode supports Model Context Protocol servers for extended capabilities:

// .vscode/mcp.json
{
  "servers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@anthropic/mcp-filesystem", "/workspace"]
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@anthropic/mcp-github"],
      "env": {
        "GITHUB_TOKEN": "${env:GITHUB_TOKEN}"
      }
    }
  }
}

Best Practices

Effective Prompts

Good:

Add pagination to the /api/products endpoint.
Use cursor-based pagination with 20 items per page.
Include total count in response headers.
Add tests for edge cases (empty results, last page, invalid cursor).

Bad:

Fix the API

Iteration Control

  • Review each step before approving
  • Use @workspace to provide full context
  • Break large tasks into focused sub-tasks
  • Check the β€œChanges” tab to review all modifications before accepting

Token Optimization (Cost Control)

{
  "github.copilot.chat.agent.contextWindow": "medium",
  "github.copilot.chat.agent.includeTests": true,
  "github.copilot.chat.agent.maxFilesInContext": 20
}

Troubleshooting

Agent Mode Not Available

  1. Verify VS Code version: code --version (need 1.99+)
  2. Check extension: GitHub Copilot Chat v0.24+
  3. Verify subscription: Settings β†’ GitHub Copilot β†’ Account status
  4. Restart VS Code after updates

Agent Gets Stuck in Loop

  • Click β€œStop” to halt iteration
  • Provide clearer constraints in your prompt
  • Break the task into smaller steps
  • Check if the error is environmental (missing dependency, wrong Node version)

Terminal Commands Fail

  • Ensure your workspace terminal profile is correct
  • Agent uses the default shell β€” verify with echo $SHELL
  • Grant terminal access when prompted (don’t auto-approve blindly)

Token Billing (June 2026 Changes)

GitHub Copilot moved to token-based billing:

PlanMonthly TokensAgent Mode
Individual ($10/mo)2,000 premiumIncluded
Business ($19/mo)5,000 premiumIncluded
Enterprise ($39/mo)10,000 premiumIncluded + Admin controls

Agent Mode uses 5-20x more tokens than Chat mode due to multi-turn reasoning. Monitor usage in GitHub Settings β†’ Copilot β†’ Usage.

Free 30-min AI & Cloud consultation

Book Now