Skip to main content

Adding repository custom instructions for GitHub Copilot

You can create a file in a repository that automatically adds information to all questions you ask Copilot Chat.

Note

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

  • 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 in VS Code. Click the tabs above for instructions on using custom instructions in other environments.

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.

Additionally, you can create prompt files. With prompt files, you can specify common prompt instructions and relevant context in a Markdown file (*.prompt.md), that you can then reuse in your chat prompts. Prompt files are only available in VS Code.

Prerequisites

  • 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.

Sample instructions

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.

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.

The following types of instructions are unlikely to work as desired and 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

The following instructions are therefore unlikely to have the intended result:

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 attached to requests that you submit in either the Copilot Chat view, or in inline chat.

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.

Enabling or disabling repository custom instructions

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

  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.

About 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 that mimics the existing format of writing prompts in Copilot Chat (for example, Rewrite #file:x.ts). This allows blending natural language instructions, additional context, and even linking to other prompt files as dependencies.

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

Common use cases include:

  • Code generation. Create reusable prompts for components, tests, or migrations (for example, React forms, or API mocks).
  • Domain expertise. Share specialized knowledge through prompts, such as security practices, or compliance checks.
  • Team collaboration. Document patterns and guidelines with references to specs and documentation.
  • Onboarding. Create step-by-step guides for complex processes or project-specific patterns.

Prompt file examples

The following examples demonstrate how to use prompt files.

  • react-form.prompt.md - documents a reusable task for generating a form.

    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
    
  • security-api.prompt.md - documents reusable 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
    …
    

Using prompt files

To enable prompt files, configure the chat.promptFiles VS Code setting. Set it to true or use the { "/path/to/folder": boolean } notation to specify a different path. Relative paths are resolved from the root folder(s) of your workspace, and the default value of .github/prompts is used if no other path is provided. For more detailed instructions, see GitHub Copilot in VS Code settings reference in the Visual Studio Code documentation.

  1. Create a .prompt.md file in the .github/prompts directory of your workspace.

  2. Write prompt instructions by using Markdown formatting.

    Reference additional workspace files as Markdown links ([index](../index.ts)), or as #file:../index.ts references within the prompt file. You can also reference other .prompt.md files.

  3. Select the attach icon, then select Prompt... and choose the prompt file to attach it in Copilot Chat or Copilot Edits.

  4. Optionally, attach additional context files required for the task.

  5. Send the chat prompt.

    • For reusable tasks, send the prompt without any additional instructions.
    • Include additional instructions to provide more context for the task at hand.

Tip

Reference additional context files like API specs or documentation by using Markdown links to provide Copilot with more complete information.