AI Workflows

How to Use GitHub Copilot Custom Instructions in VS Code

Learn to set up and use GitHub Copilot custom instructions in VS Code for tailored code assistance.

3 min read

Learn how to set up GitHub Copilot custom instructions in VS Code to fine-tune Copilot’s responses, maintain coding standards, and enhance team collaboration. With custom instructions, you can not only tailor code generation but also control commit messages and other aspects of the development workflow.

Prerequisites

Before getting started, ensure the following:

prerequisites

  • Install Visual Studio Code on your system.
  • Verify GitHub Copilot is enabled and available in your VS Code.
  • Confirm access to the project's directory where custom instructions will be added.

Creating the Custom Instructions File

To customize GitHub Copilot's behavior, you can create a dedicated file containing context-specific instructions.

steps

  1. Open a terminal or file explorer and navigate to your project directory.

  2. Create a new folder named .github (if it doesn’t already exist).

    bash
    mkdir .github
  3. Inside the .github folder, create a new file named copilot-instructions.md.

    bash
    touch .github/copilot-instructions.md
  4. Edit copilot-instructions.md and include your preferred code style and contextual instructions. For example:

    markdown
    # Custom Instructions for Copilot
    - Use camelCase for variable names.
    - Prefer single quotes for strings.
    - Ensure JavaScript code uses 2 spaces for indentation.
    - All functions must include JSDoc comments.

Configuring Copilot to Use Custom Instructions

Once the custom instructions file is created, you need to configure Visual Studio Code to reference the file.

steps

  1. Open Visual Studio Code and navigate to your workspace or project settings.

  2. Edit the settings.json file. You can access it by:

    • Pressing Ctrl+, (or Cmd+, on macOS) and searching for "settings.json".
  3. Add or update the following configuration in settings.json to integrate the custom instructions:

    json
    {
        "github.copilot.enableCustomInstructions": true,
        "github.copilot.customInstructionsPath": ".github/copilot-instructions.md"
    }
  4. Save the settings.json file. This ensures that GitHub Copilot uses your custom instructions during its operations.

Benefits of Custom Instructions

Using GitHub Copilot custom instructions provides several advantages:

Enhancements Beyond Standard Usage

To further optimize GitHub Copilot’s capabilities, you can:

  • Use markdown files to provide additional context for tests, schemas, or documentation generation.
  • Specify tone, humor, or other preferences to tailor Copilot’s responses to particular use cases or audiences.
  • Incorporate references to shared assets such as database schemas or sprint specs for advanced code generation.

By extending custom instructions, Copilot can meet a broader range of technical needs.

FAQ

Can I use multiple custom instruction files for different contexts?

No, GitHub Copilot does not currently support multiple instruction files within a single workspace. However, you can modify the contents of the single custom instructions file based on specific project requirements.

What formats are supported for the custom instructions file?

The custom instructions file should be in Markdown (.md) format. This allows you to use a structured yet human-readable format for coding guidelines and preferences.

Do custom instructions override Copilot's default behavior?

Yes, when custom instructions are enabled and configured, they prepend contextual details to the Copilot requests, influencing its responses but not fully replacing its default AI capabilities.

Can custom instructions guide Copilot's commit message generation?

Yes, by specifying commit message styles or preferences in the custom instructions file, you can ensure Copilot generates messages consistent with your team's requirements.


Official reference: GitHub Copilot documentation.