1
0
mirror of synced 2025-12-19 18:10:59 -05:00
Files
docs/content/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot.md
Siara 4ebc0afdca [DO NOT MERGE] MSFT Build Copilot coding agent megabranch (#55536)
Co-authored-by: hubwriter <hubwriter@github.com>
Co-authored-by: Felicity Chapman <felicitymay@github.com>
Co-authored-by: Joe Clark <31087804+jc-clark@users.noreply.github.com>
Co-authored-by: Isaac Brown <101839405+isaacmbrown@users.noreply.github.com>
Co-authored-by: Anne-Marie <102995847+am-stead@users.noreply.github.com>
Co-authored-by: felix <guntrip@github.com>
Co-authored-by: Felix Guntrip <stevecat@github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Laura Coursen <lecoursen@github.com>
Co-authored-by: Tim Rogers <timrogers@github.com>
Co-authored-by: Sarah Schneider <sarahs@users.noreply.github.com>
Co-authored-by: Sophie <29382425+sophietheking@users.noreply.github.com>
Co-authored-by: Nhu Do <nhu-do@github.com>
Co-authored-by: Ellie Bennett <34038869+elliebennett@users.noreply.github.com>
Co-authored-by: Janice <janiceilene@github.com>
Co-authored-by: Melanie Yarbrough <11952755+myarb@users.noreply.github.com>
Co-authored-by: Sarah Schneider <sarahs@github.com>
Co-authored-by: Ben Ahmady <32935794+subatoi@users.noreply.github.com>
Co-authored-by: Sunbrye Ly <56200261+sunbrye@users.noreply.github.com>
Co-authored-by: Steve Ward <steveward@github.com>
Co-authored-by: Vanessa <vgrl@github.com>
Co-authored-by: mc <42146119+mchammer01@users.noreply.github.com>
Co-authored-by: Kate Catlin <KateCatlin@users.noreply.github.com>
Co-authored-by: Claire W <78226508+crwaters16@users.noreply.github.com>
2025-05-19 15:32:57 +00:00

17 KiB

title, shortTitle, intro, redirect_from, versions, topics
title shortTitle intro redirect_from versions topics
Adding repository custom instructions for GitHub Copilot Repository custom instructions Create a file in a repository that gives {% data variables.product.prodname_copilot_short %} additional context for the work it does in that repository.
/copilot/customizing-copilot/adding-custom-instructions-for-github-copilot
feature
copilot
Copilot

{% webui %}

This feature is currently in {% data variables.release-phases.public_preview %} and is subject to change.

{% data reusables.copilot.repository-custom-instructions-note %} They are also supported for {% data variables.copilot.copilot_coding_agent %}.

This version of this article is for using repository custom instructions on the {% data variables.product.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 {% data variables.product.prodname_copilot_chat %} responses, see AUTOTITLE. For information on customizing {% data variables.copilot.copilot_coding_agent %} see AUTOTITLE.

About repository custom instructions for {% data variables.product.prodname_copilot_short %}

{% data variables.product.prodname_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 {% data variables.product.prodname_copilot_short %} to allow it to generate higher quality responses.

The custom instructions file is also used by {% data variables.product.prodname_copilot_short %} when you assign it to an issue or ask it to create a pull request. Instructions included in this file can help {% data variables.product.prodname_copilot_short %} to work on files in a way that matches your team's working practices and conforms to coding standards for your project. See AUTOTITLE.

Example

{% data reusables.copilot.repository-custom-instructions-example %}

{% endwebui %}

{% vscode %}

{% data reusables.copilot.repository-custom-instructions-note %}

This version of this article is for using repository custom instructions in {% data variables.product.prodname_vscode_shortname %}. Click the tabs above for instructions on using custom instructions in other environments.

For an overview of the methods you can use to customize {% data variables.product.prodname_copilot_chat %} responses, see AUTOTITLE.

About repository custom instructions and prompt files for {% data variables.product.prodname_copilot_chat %}

{% data variables.product.prodname_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 files in your repository that automatically add this information for you.

There are two types of files you can use to provide context and instructions to {% data variables.product.prodname_copilot_chat %} in {% data variables.product.prodname_vscode_shortname %}:

  • Repository custom instructions allow you to specify repository-wide instructions and preferences, in a single file, that apply to any conversation held in the context of the 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 chat prompts. Prompt files are only available in {% data variables.product.prodname_vscode_shortname %}.

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

Repository custom instructions example

{% data reusables.copilot.repository-custom-instructions-example %}

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
    …
    

{% endvscode %}

{% visualstudio %}

This feature is currently in {% data variables.release-phases.public_preview %} and is subject to change.

{% data reusables.copilot.repository-custom-instructions-note %}

This version of this article is for using repository custom instructions in {% data variables.product.prodname_vs %}. Click the tabs above for instructions on using custom instructions in other environments.

For an overview of the methods you can use to customize {% data variables.product.prodname_copilot_chat %} responses, see AUTOTITLE.

About repository custom instructions for {% data variables.product.prodname_copilot_chat %}

{% data variables.product.prodname_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 {% data variables.product.prodname_copilot_short %} to allow it to generate higher quality responses.

Example

{% data reusables.copilot.repository-custom-instructions-example %}

{% endvisualstudio %}

Prerequisites for repository custom instructions

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

{% webui %}

  • Your personal choice of whether to use custom instructions must be set to enabled. This is enabled by default. See Enabling or disabling repository custom instructions later in this article.
  • During the {% data variables.release-phases.public_preview %}, if you're using a {% data variables.product.prodname_copilot_business_short %} {% ifversion ghec %}or {% data variables.product.prodname_copilot_enterprise_short %}{% endif %} plan, the organization {% ifversion ghec %}or enterprise{% endif %} that provides your plan must have the Opt in to preview features setting enabled. See AUTOTITLE{% ifversion ghec %} and AUTOTITLE{% endif %}.

{% endwebui %}

{% vscode %}

{% endvscode %}

{% visualstudio %}

{% endvisualstudio %}

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.{% webui %}

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

{% note %}

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

Yes No

{% endnote %}

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 {% data variables.product.prodname_copilot_short %}:

  • 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

{% webui %}

The instructions in the .github/copilot-instructions.md file are available for use by {% data variables.product.prodname_copilot_chat_short %} 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 {% data variables.product.prodname_copilot_chat_short %}'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 {% data variables.product.prodname_copilot_chat_short %}, 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.

{% data reusables.copilot.custom-instructions-interactions-note %}

{% endwebui %}

{% vscode %}

{% data reusables.copilot.custom-instructions-reference %}

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

{% endvscode %}

{% visualstudio %}

{% data reusables.copilot.custom-instructions-reference %}

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

{% endvisualstudio %}

Enabling or disabling repository custom instructions

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

{% webui %}

  1. Click the {% octicon "kebab-horizontal" aria-label="Conversation options" %} 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.

{% endwebui %}

{% vscode %}

  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.

{% endvscode %}

{% visualstudio %}

  1. In the {% data variables.product.prodname_vs %} menu bar, under Tools, click Options.

    Screenshot of the {% data variables.product.prodname_vs %} 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 {% data variables.product.prodname_copilot_short %}.

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

{% endvisualstudio %}

{% vscode %}

Enabling and using prompt files

[!NOTE] Prompt files are {% data variables.release-phases.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 {% data variables.product.prodname_copilot_chat_short %} (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 {% data variables.product.prodname_copilot_chat_short %} view, click the Attach context icon ({% octicon "paperclip" aria-hidden="true" %}).

  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 {% data variables.product.prodname_copilot %} in VS Code in the {% data variables.product.prodname_vscode %} documentation.

{% endvscode %}