Skip to main content

Adding repository custom instructions for GitHub Copilot

Create a file in a repository that automatically adds information to questions you ask Copilot Chat.

Note

This feature is currently in public preview and is subject to change.

Repository custom instructions are currently supported for Copilot Chat in Visual Studio, VS Code and on the GitHub website.

This version of this article is for using repository custom instructions on the GitHub website. Click the tabs above for information on using custom instructions in other environments.

For an overview of the methods you can use to customize GitHub Copilot Chat responses, see About customizing GitHub Copilot Chat responses.

About repository custom instructions for GitHub Copilot Chat

GitHub Copilot can provide chat responses that are tailored to the way your team works, the tools you use, or the specifics of your project, if you provide it with enough context to do so. Instead of repeatedly adding this contextual detail to your chat questions, you can create a file in your repository that automatically adds this information for you. The additional information is not displayed in the chat, but is available to Copilot to allow it to generate higher quality responses.

Example

This example of a .github/copilot-instructions.md file contains three instructions that will be added to all chat questions.

We use Bazel for managing our Java dependencies, not Maven, so when talking about Java packages, always give me instructions and code samples that use Bazel.

We always write JavaScript with double quotes and tabs for indentation, so when your responses include JavaScript code, please follow those conventions.

Our team uses Jira for tracking items of work.

Prerequisites for repository custom instructions

  • A custom instructions file (see the instructions below).

Creating a repository custom instructions file

  1. In the root of your repository, create a file named .github/copilot-instructions.md.

    Create the .github directory if it does not already exist.

  2. Add natural language instructions to the file, in Markdown format.

    Whitespace between instructions is ignored, so the instructions can be written as a single paragraph, each on a new line, or separated by blank lines for legibility.

To see your instructions in action, go to https://github.com/copilot, attach the repository containing the instructions file, and start a conversation.

Did you successfully add a custom instructions file to your repository?

Yes No

Writing effective repository custom instructions

The instructions you add to the .github/copilot-instructions.md file should be short, self-contained statements that add context or relevant information to supplement users' chat questions.

You should also consider the size and complexity of your repository. The following types of instructions may work for a small repository with only a few contributors, but for a large and diverse repository, they may cause problems with other areas of Copilot:

  • Requests to refer to external resources when formulating a response
  • Instructions to answer in a particular style
  • Requests to always respond with a certain level of detail

For example, the following instructions may not have the intended results:

Always conform to the coding styles defined in styleguide.md in repo my-org/my-repo when generating code.

Use @terminal when answering questions about Git.

Answer all questions in the style of a friendly colleague, using informal language.

Answer all questions in less than 1000 characters, and words of no more than 12 characters.

Repository custom instructions in use

The instructions in the .github/copilot-instructions.md file are available for use by Copilot Chat as soon as you save the file. The complete set of instructions will be automatically added to chat prompts that relate to the repository containing the instructions file.

In Copilot Chat's immersive view (github.com/copilot), you can start a conversation that uses repository custom instructions by adding, as an attachment, the repository that contains the instructions file.

Whenever repository custom instructions are used by Copilot Chat, the instructions file is added as a reference for the response that's generated. To find out whether repository custom instructions were used, expand the list of references at the top of a chat response in the Chat panel and check whether the .github/copilot-instructions.md file is listed.

Screenshot of an expanded References list, showing the 'copilot-instructions.md' file highlighted with a dark orange outline.

You can click the reference to open the file.

Note

  • It is possible for multiple types of custom instructions to apply to a conversation. Personal instructions take the highest priority, followed by repository instructions, with organization instructions prioritized last. However, all sets of relevant instructions are still combined and provided to Copilot Chat.
  • Whenever possible, you should avoid providing conflicting sets of instructions. If you are concerned about response quality, you can also choose to temporarily disable repository instructions. See Adding repository custom instructions for GitHub Copilot.

Enabling or disabling repository custom instructions

You can choose whether or not to have custom instructions added to your chat questions.

  1. Click the button at the top of the Chat panel, or the top right of the immersive page.

  2. Click Disable custom instructions or Enable custom instructions.

    Note

    In immersive mode, you will only see these options if you have attached a repository that contains a custom instructions file.

Your choice persists until you change it.