Copilotintermediate

How to Use Copilot CLI Agents for Specialized Tasks

Learn how to use built-in and custom agents in GitHub Copilot CLI. Master the Explore, Task, Plan, and Code-review agents plus create your own specialized agents for team workflows.

10 min readUpdated January 2025

Want us to handle this for you?

Get expert help →

GitHub Copilot CLI includes specialized agents that handle different types of development tasks. These agents run in parallel to accelerate your workflow - from exploring unfamiliar codebases to running tests and reviewing code changes.

Understanding Copilot CLI Agents

Copilot CLI operates as an AI agent that can use tools autonomously. As of January 2026, it includes four built-in specialized agents that handle common development tasks:

AgentPurposeBest For
ExploreFast codebase analysisUnderstanding unfamiliar code, finding patterns
TaskRun commands like tests and buildsCI tasks, test execution, build verification
PlanCreate implementation plansComplex changes requiring dependency analysis
Code-reviewEvaluate code modificationsPre-commit review, finding genuine issues

Copilot automatically delegates to these agents when it detects an appropriate task, and can run multiple agents in parallel for complex requests.

Using Built-in Agents

The Explore Agent

The Explore agent analyzes your codebase without cluttering your main conversation context. This is useful when you need to understand how something works before making changes.

# Start Copilot CLI
copilot

# Ask the Explore agent to analyze code structure
> How does the authentication system work in this codebase?

# Find specific patterns
> Show me all the API endpoints and their handlers

# Understand dependencies
> What packages does this project use for database access?

The Explore agent excels at:

  • Answering questions about code architecture
  • Finding where specific functionality is implemented
  • Tracing data flow through the application
  • Identifying patterns and conventions used in the project

The Task Agent

The Task agent runs commands like tests and builds. It provides brief summaries on success but delivers full output when failures occur, helping you focus on what matters.

# Run tests and get results
> Run the unit tests for the auth module

# Build the project
> Build the project and report any errors

# Execute specific commands
> Run npm audit and summarize any vulnerabilities

The Task agent automatically:

  • Captures command output
  • Summarizes successful runs concisely
  • Provides detailed error information when commands fail
  • Suggests fixes for common build/test failures

The Plan Agent

The Plan agent creates implementation plans for complex changes by analyzing dependencies and required modifications.

# Plan a feature implementation
> Plan how to add OAuth2 support to the login system

# Understand impact of changes
> What files need to change to add a new API endpoint for user profiles?

# Map out refactoring
> Plan the steps to migrate from REST to GraphQL

The Plan agent provides:

  • Step-by-step implementation guides
  • File-by-file change breakdowns
  • Dependency and impact analysis
  • Risk assessment for proposed changes

The Code-review Agent

The Code-review agent evaluates modifications with focus on surfacing genuine issues rather than style nitpicks.

# Review staged changes
> Review my staged changes before I commit

# Check specific files
> Review the changes in src/auth/*.ts

# Get feedback on implementation
> Does this implementation handle edge cases properly?

The Code-review agent looks for:

  • Logic errors and bugs
  • Security vulnerabilities
  • Missing error handling
  • Performance concerns
  • Incomplete implementations

Parallel Agent Execution

One of Copilot CLI's powerful features is running multiple agents simultaneously. When you submit a complex request, Copilot orchestrates agents in parallel.

For example, when debugging an authentication issue:

> Debug why user login is failing with error code 403

Copilot may simultaneously:

  1. Use Explore to analyze the auth code
  2. Use Task to run auth-related tests
  3. Use Code-review to check recent changes to auth files

This parallel execution can reduce what would take 90 seconds sequentially down to 30 seconds.

Custom Agents

Custom agents let you define specialized configurations for your team's workflows and conventions.

Creating a Custom Agent

Custom agents are defined as Markdown files with YAML frontmatter. Create your agent file with a .agent.md extension.

macOS/Linux:

mkdir -p ~/.copilot/agents
touch ~/.copilot/agents/frontend-expert.agent.md

Windows (PowerShell):

New-Item -ItemType Directory -Force -Path "$HOME\.copilot\agents"
New-Item -ItemType File -Path "$HOME\.copilot\agents\frontend-expert.agent.md"

Agent Profile Format

A basic agent profile includes a name, description, and optional tool configuration:

---
name: frontend-expert
description: A React and TypeScript specialist following our team conventions
tools: ['read_file', 'write_file', 'run_terminal_cmd']
---

You are a frontend development expert specializing in:
- React 18+ with TypeScript
- Tailwind CSS for styling
- Testing with Vitest and React Testing Library

When reviewing or writing code:
- Use functional components with hooks
- Prefer composition over inheritance
- Write tests for all new components
- Follow our naming convention: PascalCase for components, camelCase for utilities

Advanced Agent with MCP Servers

You can extend agents with Model Context Protocol (MCP) servers for additional capabilities:

---
name: devops-agent
description: Infrastructure and deployment specialist
tools: ['read_file', 'run_terminal_cmd', 'docker-mcp/list-containers', 'docker-mcp/build']
mcp-servers:
  docker-mcp:
    type: 'local'
    command: 'docker-mcp'
    args: ['--socket', '/var/run/docker.sock']
---

You are a DevOps specialist focused on:
- Docker container management
- CI/CD pipeline configuration
- Infrastructure as Code (Terraform, Pulumi)
- Kubernetes deployments

Always verify container health after deployments.

Agent Storage Locations

Custom agents can be stored in three locations with different scopes:

LocationScopeUse Case
~/.copilot/agents/Global (your machine)Personal productivity agents
.github/agents/RepositoryProject-specific conventions
{org}/.github/agents/OrganizationTeam-wide standards

Using Custom Agents

Interactive Mode

Use the /agent slash command to invoke a custom agent:

copilot

> /agent frontend-expert
> Review this React component for best practices

Non-interactive Mode

Pass the agent directly on the command line:

copilot --agent=frontend-expert --prompt "Create a new Button component with loading state"

The /delegate Command

For larger tasks, you can delegate work to the Copilot coding agent on GitHub. This creates a pull request and works asynchronously.

copilot

> /delegate Add comprehensive error handling to all API endpoints

When you delegate:

  1. Copilot commits any unstaged changes to a new branch (prefixed with copilot/)
  2. Opens a draft pull request on GitHub
  3. The coding agent makes changes in the background
  4. You receive a link to monitor progress
  5. The agent requests your review when finished

Limitations of delegated tasks:

  • Can only work within a single repository
  • Creates exactly one pull request per task
  • Cannot push to branches without the copilot/ prefix
  • Cannot mark PRs as ready for review or merge them

Context Management

Copilot CLI includes features to manage conversation context effectively:

Auto-compaction

When approaching 95% of the token limit, Copilot automatically compresses your conversation history to prevent context overflow.

Manual Commands

CommandPurpose
/compactManually compress conversation history
/contextView current token usage
/clearStart fresh with empty context
/add-dir <path>Grant access to a directory
/list-dirsShow directories Copilot can access

Session Resume

Resume previous sessions with tab completion:

copilot --resume
# Press TAB to cycle through recent sessions

Platform-Specific Notes

macOS

  • Full support for all agents and features
  • Use Homebrew for easiest installation and updates
  • Terminal.app and iTerm2 both work well

Windows

  • WSL (Recommended): Best experience, full feature parity with macOS/Linux
  • Native PowerShell: Experimental support, requires PowerShell 6+
  • Some MCP servers may require WSL for proper operation

Linux

  • Full support across major distributions
  • Install via npm or the install script
  • Works in any terminal emulator

Best Practices

1. Let Copilot Choose the Agent

For most tasks, simply describe what you want. Copilot automatically selects the appropriate agent:

# Good - let Copilot decide
> Why is the checkout process slow?

# Also fine - be explicit when needed
> Use the explore agent to trace the checkout data flow

2. Trust Directories Carefully

Only run Copilot CLI in directories you trust. Before executing any command that modifies files, Copilot asks for approval.

3. Use Custom Agents for Team Standards

Create shared agents in .github/agents/ to encode your team's:

  • Code style preferences
  • Review checklist items
  • Common patterns and anti-patterns
  • Domain-specific terminology

4. Monitor Token Usage

Use /usage to track:

  • Premium requests consumed
  • Session duration
  • Lines of code edited
  • Token breakdown per model

Troubleshooting

Agent Not Found

If a custom agent is not recognized:

  1. Verify the file has .agent.md extension
  2. Check the YAML frontmatter is valid
  3. Confirm the file is in a recognized location
  4. Restart Copilot CLI after adding new agents

Parallel Execution Issues

If agents seem to run sequentially:

  1. Check you have the latest Copilot CLI version
  2. Verify your subscription supports parallel execution
  3. Some complex tasks may require sequential processing

MCP Server Connection Failed

For custom agents using MCP servers:

  1. Verify the MCP server is installed and accessible
  2. Check the command path is correct
  3. Ensure required permissions are granted
  4. Review server logs for specific errors

Next Steps

Frequently Asked Questions

Find answers to common questions

Copilot CLI agents (Explore, Task, Plan, Code-review) run locally in your terminal for real-time assistance. The Copilot coding agent runs asynchronously on GitHub's servers and can be invoked via the /delegate command to handle larger tasks in the background, creating pull requests automatically.

Need Professional IT & Security Help?

Our team of experts is ready to help protect and optimize your technology infrastructure.