Skip to main content

Adding repository custom instructions for GitHub Copilot

Create a file in a repository that gives Copilot additional context for the work it does in that repository.

Note

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

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.

About repository custom instructions for Copilot

Repository custom instructions are currently supported for:

  • Copilot Chat in Visual Studio, VS Code and on the GitHub website
  • Copilot coding agent
  • Copilot code review

You can configure GitHub Copilot to generate responses that are tailored to the way your team works, the tools you use, or the specifics of your project. You can do this by creating a file in your repository that provides Copilot with the contextual information it needs to generate higher quality responses.

The custom instructions file is used for chat responses, for code review, and also by Copilot when you assign it to an issue or ask it to create a pull request. Instructions included in this file can help Copilot to work on files in a way that matches your team's working practices and conforms to coding standards for your project. See About assigning tasks to Copilot.

Example

This example of a .github/copilot-instructions.md file contains three instructions for Copilot.

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.

For examples of custom instructions used to configure Copilot code review, see Using GitHub Copilot code review.

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

About repository custom instructions and prompt files for Copilot

Repository custom instructions are currently supported for:

  • Copilot Chat in Visual Studio, VS Code and on the GitHub website
  • Copilot code review

You can configure GitHub Copilot to generate responses that are tailored to the way your team works, the tools you use, or the specifics of your project. You can do this by creating a file in your repositories that provides Copilot with the contextual information it needs to generate higher quality responses.

There are two types of files you can use to provide context and instructions to Copilot in VS Code:

  • Repository custom instructions allow you to specify repository-wide instructions and preferences, in a single file, that Copilot will use when working in this repository.
  • Prompt files (public preview) allow you to save common prompt instructions and relevant context in Markdown files (*.prompt.md) that you can then reuse in your Copilot Chat prompts. Prompt files are only available in VS Code.

While custom instructions help to add codebase-wide context to each AI workflow, prompt files let you add instructions to a specific Copilot interaction.

Repository custom instructions example

This example of a .github/copilot-instructions.md file contains three instructions for Copilot.

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.

For examples of custom instructions used to configure Copilot code review, see Using GitHub Copilot code review.

Prompt file examples

The following examples demonstrate how to use prompt files.

  • New React form.prompt.md - contains instructions for a reusable task to generate a form using React.

    Your goal is to generate a new React form component.
    
    Ask for the form name and fields if not provided.
    
    Requirements for the form:
    - Use form design system components: [design-system/Form.md](../docs/design-system/Form.md)
    - Use `react-hook-form` for form state management:
      - Always define TypeScript types for your form data
      - Prefer *uncontrolled* components using register
      - Use `defaultValues` to prevent unnecessary rerenders
    - Use `yup` for validation:
      - Create reusable validation schemas in separate files
      - Use TypeScript types to ensure type safety
      - Customize UX-friendly validation rules
    
  • API security review.prompt.md - contains reusable information about security practices for REST APIs, which can be used to do security reviews of REST APIs.

    Secure REST API review:
    - Ensure all endpoints are protected by authentication and authorization
    - Validate all user inputs and sanitize data
    - Implement rate limiting and throttling
    - Implement logging and monitoring for security events
    …
    

Note

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

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

About repository custom instructions for Copilot

Repository custom instructions are currently supported for:

  • Copilot Chat in Visual Studio, VS Code and on the GitHub website
  • Copilot code review

You can configure GitHub Copilot to generate responses that are tailored to the way your team works, the tools you use, or the specifics of your project. You can do this by creating a file in your repositories that provides Copilot with the contextual information it needs to generate higher quality responses.

Example

This example of a .github/copilot-instructions.md file contains three instructions for Copilot.

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.

For examples of custom instructions used to configure Copilot code review, see Using GitHub Copilot code review.

Prerequisites for repository custom instructions

  • You must have 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 provide Copilot with relevant information to help it work in this repository.

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, these may cause problems:

  • 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 requests that you submit to Copilot in the context of that repository. For example, they are added to the prompt you submit to Copilot Chat.

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.

Custom instructions are not visible in the Chat view or inline chat, but you can verify that they are being used by Copilot by looking at the References list of a response in the Chat view. If custom instructions were added to the prompt that was sent to the model, the .github/copilot-instructions.md file is listed as a reference. You can click the reference to open the file.

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

Custom instructions are not visible in the Chat view or inline chat, but you can verify that they are being used by Copilot by looking at the References list of a response in the Chat view. If custom instructions were added to the prompt that was sent to the model, the .github/copilot-instructions.md file is listed as a reference. You can click the reference to open the file.

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

Enabling or disabling repository custom instructions

You can choose whether or not you want Copilot to use repository-based custom instructions.

Enabling or disabling custom instructions for Copilot Chat

Custom instructions are enabled for Copilot Chat by default but you can disable, or re-enable, them at any time. This applies to your own use of Copilot Chat and does not affect other users.

  1. On GitHub.com, do one of the following:

    • Go to a repository with a custom instructions file and open the assistive chat panel.
    • Go to the immersive view of Copilot Chat (github.com/copilot) and attach a repository that contains a custom instructions file.
  2. Click the button at the top of the Chat panel, or the top right of the immersive page.

  3. Click Disable custom instructions or Enable custom instructions.

    Note

    You will only see these options in the context of a repository that contains a custom instructions file.

Your choice persists, for all repositories containing a custom instructions file, until you change it.

  1. Open the Setting editor by using the keyboard shortcut Command+, (Mac) / Ctrl+, (Linux/Windows).
  2. Type instruction file in the search box.
  3. Select or clear the checkbox under Code Generation: Use Instruction Files.
  1. In the Visual Studio menu bar, under Tools, click Options.

    Screenshot of the Visual Studio menu bar. The "Tools" menu is expanded, and the "Options" item is highlighted with an orange outline.

  2. In the "Options" dialog, type custom instructions in the search box, then click Copilot.

  3. Select or clear the checkbox for (Preview) Enable custom instructions to be loaded from .github/copilot-instructions.md files and added to requests.

Enabling or disabling custom instructions for Copilot code review

Custom instructions are enabled for Copilot code review by default but you can disable, or re-enable, them in the repository settings on GitHub.com. This applies to Copilot's use of custom instructions for all code reviews it performs in this repository.

  1. On GitHub, navigate to the main page of the repository.

  2. Under your repository name, click Settings. If you cannot see the "Settings" tab, select the dropdown menu, then click Settings.

    Screenshot of a repository header showing the tabs. The "Settings" tab is highlighted by a dark orange outline.

  3. In the "Code & automation" section of the sidebar, click Copilot, then Code review.

  4. Toggle the “Use custom instructions when reviewing pull requests” option on or off.

Enabling and using prompt files

Note

Prompt files are public preview and subject to change.

Prompt files let you build and share reusable prompt instructions with additional context. A prompt file is a Markdown file, stored in your workspace, that mimics the existing format of writing prompts in Copilot Chat (for example, Rewrite #file:x.ts). You can have multiple prompt files in your workspace, each of which defines a prompt for a different purpose.

Enabling prompt files

To enable prompt files, configure the workspace settings.

  1. Open the command palette by pressing Ctrl+Shift+P (Windows/Linux) / Command+Shift+P (Mac).
  2. Type "Open Workspace Settings (JSON)" and select the option that's displayed.
  3. In the settings.json file, add "chat.promptFiles": true to enable the .github/prompts folder as the location for prompt files. This folder will be created if it does not already exist.

Creating prompt files

  1. Open the command palette by pressing Ctrl+Shift+P (Windows/Linux) / Command+Shift+P (Mac).

  2. Type "prompt" and select Chat: Create Prompt.

  3. Enter a name for the prompt file, excluding the .prompt.md file name extension. The name can contain alphanumeric characters and spaces and should describe the purpose of the prompt information the file will contain.

  4. Write the prompt instructions, using Markdown formatting.

    You can reference other files in the workspace by using Markdown links—for example, [index](../../web/index.ts)—or by using the #file:../../web/index.ts syntax. Paths are relative to the prompt file. Referencing other files allows you to provide additional context, such as API specifications or product documentation.

Using prompt files

  1. At the bottom of the Copilot Chat view, click the Attach context icon ().

  2. In the dropdown menu, click Prompt... and choose the prompt file you want to use.

  3. Optionally, attach additional files, including prompt files, to provide more context.

  4. Optionally, type additional information in the chat prompt box.

    Whether you need to do this or not depends on the contents of the prompt you are using.

  5. Submit the chat prompt.

For more information about prompt files, see Custom instructions for GitHub Copilot in VS Code in the Visual Studio Code documentation.