Copilotintermediate

How to Use Copilot CLI Slash Commands

Complete guide to GitHub Copilot CLI slash commands including session management, model selection, directory access, MCP configuration, and building automated workflows.

12 min readUpdated January 2025

Want us to handle this for you?

Get expert help →

GitHub Copilot CLI slash commands are special directives that give you precise control over your terminal AI assistant. Unlike natural language prompts that invoke the AI model, slash commands trigger predictable, repeatable actions for session management, configuration, and workflow automation.

Understanding Slash Commands

Slash commands are distinct from regular prompts:

  • Slash commands start with / and control system behavior
  • Natural language prompts are processed by the AI model
  • Shell commands start with ! and execute directly in your terminal
  • File references start with @ to include specific files in your context

All slash commands support TAB autocomplete and display argument hints in the input box.

Quick Reference

CommandPurpose
/clearReset session context
/usageView session statistics
/modelChange AI model
/cwdChange working directory
/add-dirGrant directory access
/list-dirsShow accessible directories
/delegatePush task to Copilot coding agent
/mcpManage MCP server configurations
/shareExport session to Markdown or Gist
/userManage authentication contexts
/loginAuthenticate with GitHub
/themeAdjust terminal display
/terminal-setupEnable multiline inputs
/exitEnd your session

Session Management Commands

/clear - Reset Session Context

The /clear command wipes your conversation timeline and resets session state while maintaining authentication and configuration settings:

copilot> /clear
Session context cleared. Starting fresh conversation.

Use /clear when:

  • Switching between different projects
  • Starting a new task after completing one
  • The AI seems confused by accumulated context
  • You want to reduce token usage from long conversations

/usage - View Session Statistics

Monitor your resource consumption with /usage:

copilot> /usage
Session Statistics:
  Duration: 45 minutes
  Premium requests used: 12
  Total prompts: 28
  Code changes: 7 files

This is particularly useful for tracking premium request usage on paid plans.

/session - View Session Metrics

Get detailed session information:

copilot> /session
Session ID: abc123...
Started: 2025-01-22 10:30:00
Duration: 1h 23m
Files modified: 5
Commands executed: 12

/exit - End Session

Cleanly terminate your Copilot CLI session:

copilot> /exit
Session ended. Goodbye!

Model Configuration Commands

/model - Change AI Model

The default model is Claude Sonnet 4.5. Switch between available models with /model:

copilot> /model

Available models:
  1. Claude Sonnet 4.5 (default)
  2. Claude Sonnet 4
  3. GPT-5
  4. GPT-5 mini (included, no premium requests)
  5. GPT-4.1 (included, no premium requests)

Select model [1-5]:

Cost optimization tip: GPT-5 mini and GPT-4.1 are included with your Copilot subscription and do not consume premium requests on paid plans.

The available models are filtered based on your Copilot subscription plan and geographic region.

/theme - Adjust Terminal Display

Customize the visual appearance of Copilot CLI:

copilot> /theme

Available themes:
  1. default
  2. dark
  3. light
  4. high-contrast

Select theme:

/terminal-setup - Enable Multiline Input

Enable multiline prompts for complex instructions:

copilot> /terminal-setup

Multiline input enabled. Use Ctrl+Enter to submit prompts.

This is useful when writing detailed specifications or multi-step instructions.

Directory and File Access Commands

/cwd - Change Working Directory

Change the current working directory context for file operations:

# Absolute path
copilot> /cwd ~/projects/my-app

# Relative path
copilot> /cwd ../sibling-project

# Explicit full path
copilot> /cwd /Users/developer/code/api

The working directory affects:

  • Where file operations are executed
  • Which files are accessible to the AI
  • The context for shell command execution

/add-dir - Grant Directory Access

Explicitly grant Copilot access to specific directories:

copilot> /add-dir ~/shared-libs
Added directory: /Users/developer/shared-libs

copilot> /add-dir /var/log/app
Added directory: /var/log/app

This is essential for:

  • Accessing files outside your current project
  • Working with monorepos and multiple packages
  • Teams with compliance requirements needing auditable trails

/list-dirs - Show Accessible Directories

View all directories Copilot can currently access:

copilot> /list-dirs

Accessible directories:
  /Users/developer/projects/my-app (cwd)
  /Users/developer/shared-libs
  /var/log/app

Authentication Commands

/login - Authenticate with GitHub

If you are not logged in, use /login to authenticate:

copilot> /login

Opening browser for authentication...
Please complete the sign-in process in your browser.
Waiting for authentication...

Authentication successful! Welcome, developer.

/user - Manage Authentication Contexts

When multiple GitHub accounts are available, manage them with /user:

# List all authenticated users
copilot> /user list

Authenticated users:
  1. [email protected] (active)
  2. [email protected]

# Show current user details
copilot> /user show

Current user: [email protected]
Auth method: OAuth
Copilot plan: Individual

# Switch between accounts
copilot> /user switch [email protected]
Switched to: [email protected]

The /user command supports both OAuth and Personal Access Token (PAT) authentication modes.

External Services and Integration

/delegate - Push to Copilot Coding Agent

The /delegate command sends tasks to the Copilot coding agent, an asynchronous, autonomous background agent:

copilot> /delegate complete the API integration tests and fix any failing edge cases

Delegating to Copilot coding agent...
Creating branch: copilot/api-tests-fix
Task submitted. View progress at: https://github.com/owner/repo/pull/123

When you delegate:

  1. Any unstaged changes are committed to a new branch
  2. The task runs asynchronously on GitHub
  3. A pull request is created for review
  4. You receive a link to track progress

Example workflows for /delegate:

# Refactoring
copilot> /delegate refactor the logging module for better performance

# Documentation
copilot> /delegate add JSDoc comments to all public functions in src/api/

# Bug fixes
copilot> /delegate fix the race condition in the payment processing module

# Testing
copilot> /delegate write comprehensive unit tests for the authentication service

/mcp - Manage Model Context Protocol Servers

The /mcp command manages MCP server configurations for extended functionality:

# Show current MCP configuration
copilot> /mcp show

MCP Servers:
  github (built-in): active
  Config file: ~/.copilot/mcp-config.json

# Add a new MCP server
copilot> /mcp add

Enter server name: serena
Enter server type (local/remote): local
Enter command: uvx
Enter args: --from git+https://github.com/oraios/serena serena start-mcp-server

Server 'serena' added successfully.

Copilot CLI comes with the GitHub MCP server already configured, allowing you to interact with GitHub resources like merging pull requests directly from the CLI.

MCP Configuration File

MCP settings are stored in ~/.copilot/mcp-config.json:

{
  "mcpServers": {
    "serena": {
      "type": "local",
      "command": "uvx",
      "tools": ["*"],
      "args": [
        "--from", "git+https://github.com/oraios/serena",
        "serena", "start-mcp-server", "--context", "ide-assistant"
      ],
      "env": {}
    }
  }
}

Advanced options:

  • --additional-mcp-config: Temporarily override MCP configuration for a single session
  • --enable-all-github-mcp-tools: Enable the full set of GitHub MCP tools (conserves context window by default)

/share - Export Sessions

Export your session for documentation or collaboration:

# Export to Markdown file
copilot> /share markdown

Session exported to: ~/copilot-session-2025-01-22.md

# Export to GitHub Gist
copilot> /share gist

Creating Gist...
Gist created: https://gist.github.com/developer/abc123

This is ideal for:

  • Async handoffs to team members
  • Documenting problem-solving approaches
  • Creating tutorials from real sessions

Building Automated Workflows

Custom Agents

While you cannot create custom slash commands, you can build custom agents that provide similar functionality. Custom agents are specialized versions of Copilot tailored to your workflows.

Create an agent file at .github/agents/k8s.agent.md:

# Kubernetes Agent

You are a Kubernetes specialist. When asked about Kubernetes:

1. Always validate YAML syntax before suggesting changes
2. Follow security best practices for pod configurations
3. Suggest resource limits and requests
4. Consider multi-tenancy implications

Available tools:
- kubectl
- helm
- kustomize

Default namespace: production

Invoke your custom agent:

copilot --agent=k8s "generate a deployment for my Node.js API with 3 replicas"

Programmatic Mode for Scripts

Use programmatic mode for CI/CD pipelines and automation:

# Single prompt execution
copilot -p "generate a commit message for staged changes"

# Piping output
copilot -p "explain this error" < error.log > analysis.txt

# In CI/CD scripts
COMMIT_MSG=$(copilot -p "write a conventional commit message for these changes: $(git diff --staged)")
git commit -m "$COMMIT_MSG"

CI/CD Authentication

For automated pipelines, set the GITHUB_ASKPASS environment variable:

export GITHUB_ASKPASS=/path/to/credential-helper
copilot -p "run security scan and report findings"

Or use environment variables for token-based auth:

export GH_TOKEN="your-fine-grained-pat"
copilot -p "generate release notes from recent commits"

Platform-Specific Notes

macOS

  • Homebrew is the recommended installation method
  • Use brew upgrade copilot-cli to update
  • Terminal.app and iTerm2 are fully supported

Windows

  • WSL provides the best experience
  • Native PowerShell support is experimental
  • Requires PowerShell v6 or higher for native Windows
  • WinGet is the easiest native installation method

Linux

  • Install via the install script or npm
  • Most terminal emulators are supported
  • Works in headless environments with token authentication

Best Practices

1. Use /clear Between Projects

Reset context when switching tasks to avoid confusion:

# Finishing project A
copilot> /clear

# Starting project B
copilot> /cwd ~/projects/project-b
copilot> explain the architecture of this codebase

2. Monitor Usage with /usage

Regularly check your premium request consumption:

copilot> /usage
# Review statistics before starting intensive work

3. Leverage Models Strategically

Use included models (GPT-5 mini, GPT-4.1) for routine tasks:

copilot> /model
# Select GPT-5 mini for simple queries
# Reserve Claude Sonnet 4.5 for complex analysis

4. Export Important Sessions

Document valuable problem-solving sessions:

copilot> /share gist
# Creates shareable reference for team

5. Security Considerations

When using Copilot CLI:

  • Review all suggested commands before approval
  • Never expose passwords, API keys, or tokens to prompts
  • Use environment variables for sensitive data
  • Keep secrets in secure credential managers

Troubleshooting

Slash Command Not Recognized

If a slash command is not working:

  1. Check spelling (commands are case-sensitive)
  2. Ensure you are in an interactive session
  3. Update to the latest version: npm install -g @github/copilot@latest

MCP Server Not Loading

If MCP servers are not available:

  1. Verify your configuration file syntax
  2. Check that the MCP server binary/script exists
  3. Run /mcp show to see current status
  4. For organization users, verify the MCP policy is enabled

/delegate Not Working

If delegation fails:

  1. Ensure you have write access to the repository
  2. Check that Copilot coding agent is enabled for your organization
  3. Verify there are no merge conflicts in your local branch

Next Steps

Frequently Asked Questions

Find answers to common questions

Slash commands (prefixed with /) are special directives that control session state, model configuration, and system settings. They execute predictable, repeatable actions without invoking the AI model, while regular prompts are natural language requests processed by the LLM.

Need Professional IT & Security Help?

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