Skip to main content

Using GitHub Copilot Chat Modes

1. Using Ask Mode

Mode Description Use Case
Ask Mode Interactive chat interface for natural language queries about code, debugging, and development tasks. Quick questions or explanations without writing code directly.

Example: Asking for Code Explanation


What does this code do?

Example: Requesting a Code Fix


Fix the bug in this function.
Note: Ask Mode works best with clear, specific prompts. Vague queries may return less accurate results.

2. Using Edit Mode

Feature Description Usage
Edit Mode Allows users to request code modifications or completions directly within the editor. Initiate with /edit command or by selecting "Edit" from context menu.
Code Generation Generates new code snippets or modifies existing code based on natural language prompts. Enter a prompt like "Add error handling to this function" and select the desired code block.
Context Awareness Uses surrounding code context to understand the intended modification. Copilot analyzes the current file and related code to provide context-aware suggestions.

Example: Adding Error Handling

function fetchData(url) {
    const response = await fetch(url);
    return response.json();
}
function fetchData(url) {
    try {
        const response = await fetch(url);
        return response.json();
    } catch (error) {
        console.error("Failed to fetch data:", error);
        throw error;
    }
}
Note: Edit Mode works best when the prompt is specific and includes relevant context such as desired output format or error handling requirements.

3. Using Agent Mode

Example: Configuring Agent Mode in GitHub Copilot

# .copilot/config.yaml
agent:
  enabled: true
  model: gpt-4
  max_tokens: 2048
  temperature: 0.7
Configuration Option Description Default Value Notes
agent.enabled Enables or disables Agent Mode false Set to true to activate Agent Mode
agent.model AI model used for Agent Mode gpt-3.5-turbo Supports gpt-4, claude-3
agent.max_tokens Maximum tokens in response 1024 Higher values allow longer responses
agent.temperature Controls randomness of output 0.5 Range: 0.0 (deterministic) to 1.0 (creative)
Note: Agent Mode is designed for complex multi-step tasks and can handle up to 1000 tokens per response.
Warning: Agent Mode may consume more API credits than regular chat due to its multi-turn nature.

Agent Mode Capabilities

  • Multi-turn conversation with memory
  • Task decomposition and execution planning
  • Integration with external tools (e.g., GitHub API)
  • Code generation and refactoring assistance

4. Switching Between Chat Modes

Mode Description Use Case
Chat Default mode for natural language conversations with Copilot. Ask questions, get explanations, or request help with code understanding.
Explain Focuses on explaining code or concepts in detail. Helps understand complex logic or unfamiliar libraries.
Fix Identifies and fixes issues in code. Debugging or resolving errors in existing code.
Review Reviews code for best practices and potential improvements. Code quality checks and refactoring suggestions.
Generate Generates new code snippets based on descriptions. Quickly scaffold functions, classes, or components from natural language.

Example: Switching Chat Modes in GitHub Copilot


# In the Copilot Chat window, use the mode selector dropdown:
# - Select "Explain" to explain a selected code snippet
# - Choose "Fix" to resolve an error in your code
# - Pick "Review" to get feedback on code quality

5. Using Inline Chat

Example: Using Inline Chat in VS Code

// Open the Copilot Chat panel in VS Code
// Type a natural language query like:
// "Explain how this React component works"

// The AI will respond with explanations and suggestions
// You can also ask it to generate code:
// "Generate a useEffect hook that fetches user data"

// Inline chat allows real-time interaction with Copilot
// No need to switch between panels or windows
Feature Description Availability
Inline Chat Panel Integrated chat interface within the IDE NEW GitHub Copilot v1.12+
Natural Language Queries Ask questions in plain English about code Available in all Copilot plans
Code Generation Generate code snippets from natural language Available in all Copilot plans
Context Awareness Understands current file and project context Available in all Copilot plans
Note: Inline Chat works best when you're actively working in an open file. It can understand and respond to queries about the current code context.
Warning: Inline Chat responses are generated by AI and should be reviewed before use. Always validate code suggestions in your development environment.

Key Benefits of Inline Chat

  • Contextual Understanding - AI understands your current file and project structure
  • Real-time Interaction - No need to switch between panels or windows
  • Natural Language Processing - Ask questions in plain English
  • Code Generation - Generate code snippets from natural language descriptions

6. Referencing Files with # Syntax

GitHub Copilot Chat allows you to reference files in your project using the # syntax. This feature helps you quickly navigate to and discuss specific files or sections within your codebase.

Reference Type Syntax Description
#filename #src/main.js References a file by its path relative to the project root.
#filename:line #src/main.js:10 References a specific line in a file.
#filename:line1-line2 #src/main.js:5-15 References a range of lines in a file.

Example: Referencing a File

#src/main.js

Example: Referencing a Line Range

#src/main.js:1-20
Note: The file reference must be within the current project context for Copilot to resolve it correctly.

7. Referencing Symbols with @ Syntax

Symbol Type Reference Syntax Description Example
Function @functionName References a function definition in the current file or project @handleClick
Variable @variableName References a variable or constant in scope @userInput
Class @ClassName References a class definition @UserModel
Module @modulePath References a module or file path @utils/helpers

Example: Using @ to reference a function

function calculateTotal(items) {
  return items.reduce((sum, item) => sum + item.price, 0);
}

// In Copilot Chat:
// "Summarize the calculateTotal function"
Note: The @ syntax works best when the symbol is clearly defined and has a unique name within the project context.

8. Using #selection and #editor Variables

Variable Description Usage Example
#selection Refers to the currently selected text in the editor
// Example: Using #selection to generate documentation
function calculateTotal(items) {
    // Select the function body and use #selection
    // to generate JSDoc comments based on the code
}
#editor Represents the entire content of the current file
// Example: Using #editor to refactor code
// Paste the entire file content into the chat and request
// a specific refactoring pattern across the whole document

Example: Using #selection to generate documentation

function processData(data) {
    // Select this function body and use #selection
    // to generate JSDoc comments based on the code
    return data.map(item => item * 2);
}

Example: Using #editor to refactor code

// Paste the entire file content into the chat and request
// a specific refactoring pattern across the whole document
// Example: Replace all instances of 'var' with 'let'
// in the entire editor content

9. Reviewing Chat History

Command Description Usage
/history Displays the chat history in the Copilot Chat window /history command in the chat input field
/history clear Clears the current chat history /history clear to reset conversation
/history export Exports chat history to a file /history export to save conversation

Example: Exporting Chat History

/history export
Note: Chat history is stored locally in the Copilot extension and can be accessed via the command palette or chat window.

10. Exporting Chat Sessions

Example: Exporting a Chat Session

github copilot chat export --session-id <session-id> --format markdown
Option Values Description
--session-id <session-id> Unique identifier for the chat session to export
--format markdown, html, txt Export format for the chat session
--output <file-path> Path to the output file (optional)
Note: The session ID can be found in the Copilot Chat window or via the CLI command github copilot chat list.
Warning: Exported sessions may contain sensitive code or information. Review before sharing.

11. Configuring Chat Response Length

Setting Values Description
copilot.chat.responseLength "short", "medium", "long" Controls the length of responses from GitHub Copilot Chat

Example: Setting Response Length

{
  "copilot.chat.responseLength": "medium"
}
Note: The response length setting affects how much context and detail Copilot includes in its replies. Short responses are concise, while long responses provide more comprehensive explanations.

12. Creating Custom Chat Modes with .chatmode.md

Example: Creating a custom chat mode configuration

# .chatmode.md
name: "Custom AI Assistant"
description: "A custom mode for AI-assisted development with specific rules"
rules:
  - type: "language"
    value: "javascript"
  - type: "style"
    value: "concise"
  - type: "output"
    value: "code"
Field Description Values
name Name of the chat mode string
description Short description of the chat mode purpose string
rules List of rules to apply in this mode array
Note: The .chatmode.md file must be placed in the root of your project to be recognized by GitHub Copilot.

Configuration Options

  • name: Unique identifier for the chat mode
  • description: Human-readable description of the mode's purpose
  • rules: Array of rule objects that define behavior

Was this article helpful?