Copilotintermediate

How to Use the Delegate Command in GitHub Copilot CLI

Learn to use GitHub Copilot CLI's /delegate command to hand off complex tasks for autonomous execution. Understand when delegation works best and how to provide effective task descriptions.

7 min readUpdated January 2025

Want us to handle this for you?

Get expert help →

The /delegate command in GitHub Copilot CLI lets you hand off complex tasks to Copilot for autonomous execution. Instead of working through problems step by step, delegation allows Copilot to work independently, creating branches, making changes, and opening pull requests on your behalf.

Understanding the Delegate Command

When you use /delegate, you are invoking the Copilot coding agent - a more powerful mode that operates asynchronously on GitHub's servers. Unlike interactive mode where you guide each step, delegation gives Copilot autonomy to complete a task from start to finish.

The coding agent can:

  • Create new branches (prefixed with copilot/)
  • Make multiple file changes
  • Run tests to verify changes
  • Open draft pull requests
  • Request your review when finished

This makes delegation ideal for tasks that are well-defined but tedious to execute manually.

Syntax and Basic Usage

Start a Copilot CLI session and use the /delegate command followed by your task description:

copilot

> /delegate Add input validation to all form fields in the checkout module

After delegation:

  1. Copilot commits any unstaged changes to a new branch
  2. Opens a draft pull request on GitHub
  3. The coding agent works in the background
  4. You receive a link to monitor progress
  5. Copilot requests your review when complete

You can continue working locally while the delegated task runs on GitHub.

When to Use Delegation vs Interactive Mode

Use Delegation For

Task TypeExample
Bulk changes"Add JSDoc comments to all exported functions"
Test coverage"Write unit tests for the payment processing module"
Refactoring"Convert all class components to functional components"
Code cleanup"Fix all ESLint errors in the src directory"
Documentation"Add README files to each package in the monorepo"

Use Interactive Mode For

ScenarioWhy
Exploratory workYou need to learn about the code first
Ambiguous requirementsThe task needs clarification
Critical changesYou want to review each step
Quick fixesSingle-file changes are faster interactively

Writing Effective Delegation Tasks

The quality of your delegation results depends heavily on how you describe the task.

Poor Task Descriptions

# Too vague - what bugs? where?
> /delegate Fix bugs

# No success criteria
> /delegate Improve the code

# Unclear scope
> /delegate Add tests

Effective Task Descriptions

# Specific goal, clear scope
> /delegate Fix the authentication bug where users receive 403 errors
  after password reset. The issue is in src/auth/token-refresh.ts

# Clear requirements and constraints
> /delegate Add unit tests for the UserService class covering all public
  methods. Use Jest and aim for 80% coverage. Follow existing test patterns
  in __tests__/

# Well-defined success criteria
> /delegate Convert the Dashboard component from class to functional using
  React hooks. Preserve all existing functionality and ensure existing tests
  pass

Task Description Checklist

Include these elements for best results:

  • What: The specific change or outcome needed
  • Where: Files, directories, or modules to focus on
  • How: Patterns, conventions, or approaches to follow
  • Constraints: Requirements that must be met
  • Success criteria: How to know when the task is complete

Monitoring Delegated Tasks

After delegation, Copilot provides a link to the draft pull request. From there you can:

On GitHub

  • View commits as they are made
  • Read the PR description summarizing the approach
  • Check the conversation thread for agent status updates
  • Review file changes in real-time

Checking Status

The pull request will show:

  • Current status (working, waiting for review, blocked)
  • Changes made so far
  • Any errors or issues encountered
  • Test results if tests were run

Interrupting and Controlling Delegated Tasks

Interrupt Locally

Press Ctrl+C during the initial delegation handoff to cancel before the task starts on GitHub.

On GitHub

Once the task is running on GitHub:

  1. Navigate to the draft pull request
  2. Close the pull request to stop the agent
  3. Delete the copilot/ branch if you want to start fresh

Modify Direction

You can add comments to the pull request to guide the agent:

@copilot Please also add error handling for network failures

The agent monitors PR comments and can adjust its approach based on feedback.

Reviewing Changes After Delegation

When the agent completes its work:

  1. Review the pull request diff on GitHub
  2. Run tests locally by checking out the branch
  3. Request changes via PR comments if needed
  4. Mark as ready for review when satisfied
  5. Merge using your normal workflow
# Checkout the delegated branch locally
git fetch origin
git checkout copilot/add-validation-to-forms

# Run tests
npm test

# Review changes
git diff main

Common Delegation Patterns

Pattern 1: Test Generation

> /delegate Generate unit tests for the OrderService class in
  src/services/order.ts. Cover success cases, error handling, and edge
  cases. Use the testing patterns from tests/services/user.test.ts as
  a reference

Pattern 2: Refactoring

> /delegate Refactor the legacy PaymentProcessor class to use async/await
  instead of callbacks. Update all callers in src/checkout/. Ensure all
  existing tests pass

Pattern 3: Documentation

> /delegate Add TypeScript JSDoc comments to all exported functions in
  the lib/ directory. Include @param, @returns, and @example tags where
  appropriate

Pattern 4: Migration

> /delegate Migrate all styled-components in src/components/ to Tailwind
  CSS. Follow the class naming conventions in our existing Button and
  Card components

Limitations and When Delegation Is Not Appropriate

Technical Limitations

LimitationImplication
Single repository onlyCannot coordinate changes across repos
One PR per delegationComplex multi-PR work needs manual coordination
Branch prefix requiredCan only push to copilot/* branches
Cannot merge PRsYou must complete the merge manually
Cannot mark PR readyYou must change from draft to ready

When Not to Delegate

  • Security-sensitive code: Manual review is essential for auth, encryption, or access control
  • Architecture decisions: Major structural changes need human judgment
  • Breaking changes: API changes affecting consumers need careful coordination
  • Production hotfixes: Critical fixes need immediate, controlled deployment
  • Cross-repo dependencies: Changes spanning multiple repositories

Best Practices

Start Small

Test delegation with low-risk tasks before delegating critical work:

# Good first delegation
> /delegate Add type annotations to the utility functions in lib/helpers.ts

Be Specific About Conventions

Reference existing code as examples:

> /delegate Add error boundaries to all page components following the
  pattern in src/pages/Dashboard.tsx

Set Clear Boundaries

Specify what should not be changed:

> /delegate Optimize the image loading in the Gallery component. Do not
  modify the public API or change how images are fetched from the server

Review Thoroughly

Delegated code still needs human review. Check for:

  • Logical correctness
  • Edge cases
  • Performance implications
  • Security considerations
  • Consistency with codebase conventions

Next Steps

Frequently Asked Questions

Find answers to common questions

The /delegate command hands off a task to Copilot for autonomous execution. Instead of interactive back-and-forth, Copilot works through the entire task independently, using tools and making decisions to complete the goal.

Need Professional IT & Security Help?

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