Skip to content

Commit 5caacba

Browse files
houghj16Copilotsaritai
authored
Revise documentation for custom instructions and prompt files (#58589)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Sarita Iyer <66540150+saritai@users.noreply.github.com>
1 parent edeee8e commit 5caacba

File tree

5 files changed

+104
-17
lines changed

5 files changed

+104
-17
lines changed

content/copilot/concepts/prompting/response-customization.md

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,34 +200,90 @@ For information on how to enable, create, and use prompt files, see [AUTOTITLE](
200200

201201
{% visualstudio %}
202202

203-
> [!NOTE] This version of this article is about custom instructions in {% data variables.product.prodname_vs %}. Click the tabs above for other environments. <!-- markdownlint-disable-line MD027 -->
203+
> [!NOTE] This version of this article is about custom instructions and prompt files in {% data variables.product.prodname_vs %}. Click the tabs above for other environments. <!-- markdownlint-disable-line MD027 -->
204204
205205
## About customizing {% data variables.product.prodname_copilot_short %} responses
206206

207-
{% data variables.product.prodname_copilot %} can provide 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 prompts, you can create a custom instructions file in your repository that automatically adds this information for you. The additional information is not displayed in the chat input box, but is available to {% data variables.product.prodname_copilot_short %} to allow it to generate higher quality responses.
207+
{% data variables.product.prodname_copilot %} can provide 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 prompts, you can create files in your repository that automatically add this information for you.
208+
209+
There are two types of files you can use to provide context and instructions to {% data variables.product.prodname_copilot_short %} in {% data variables.product.prodname_vs %}:
210+
211+
* **Repository custom instructions** allow you to specify instructions and preferences that {% data variables.product.prodname_copilot_short %} will consider when working in the context of the repository.
212+
* **Prompt files** allow you to save common prompt instructions and relevant context in Markdown files (`*.prompt.md`) that you can then reuse in your chat prompts. {% data reusables.copilot.prompt-files-available-in-editors %}
213+
214+
While custom instructions help to add codebase-wide context to each AI workflow, prompt files let you add instructions to a specific chat interaction.
208215

209216
{% data reusables.copilot.custom-insts-nondeterministic %}
210217

211218
## About repository custom instructions
212219

213-
In {% data variables.product.prodname_vs %}, repository custom instructions consist of a single file, `.github/copilot-instructions.md`, that you create in a repository. The instructions you add to the file should be short, self-contained statements that add context or relevant information to supplement a {% data variables.product.prodname_copilot_short %} prompt.
220+
You can use two types of repository custom instructions in {% data variables.product.prodname_vs %}:
214221

215-
{% data reusables.copilot.repository-custom-instructions-support %}
222+
* **Repository-wide custom instructions**, which apply to all requests made in the context of a repository.
216223

217-
### Use cases for custom instructions
224+
These are specified in a `copilot-instructions.md` file in the `.github` directory of the repository.
218225

219-
Common use cases for repository custom instructions include:
226+
* **Path-specific custom instructions**, which apply to requests made in the context of files that match a specified path.
220227

221-
* **Test generation.** Create instructions for test generation, such as specifying the use of a certain test framework.
222-
* **Code review.** Specify instructions for reviewing code, such as telling a reviewer to look for a specific error in the code.
223-
* **Commit message generation.** Write instructions for generating commit messages, such as format or the type of information to include.
228+
These are specified in one or more `NAME.instructions.md` files within the `.github/instructions` directory in the repository.
224229

225-
### Example
230+
By using path-specific instructions you can avoid overloading your repository-wide instructions with information that only applies to files of certain types, or in certain directories.
226231

227-
{% data reusables.copilot.repository-custom-instructions-example %}
232+
See the table below for details of support for each of these types of repository custom instructions across different {% data variables.product.prodname_copilot_short %} features.
228233

229234
For a curated collection of examples, see [AUTOTITLE](/copilot/tutorials/customization-library/custom-instructions).
230235

236+
{% data reusables.copilot.repository-custom-instructions-support %}
237+
238+
## About prompt files
239+
240+
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.copilot.copilot_chat_short %} (for example, `Rewrite #file:x.ts`). This allows blending natural language instructions, additional context, and even linking to other prompt files as dependencies.
241+
242+
Common use cases include:
243+
244+
* **Code generation**. Create reusable prompts for components, tests, or migrations (for example, React forms, or API mocks).
245+
* **Domain expertise**. Share specialized knowledge through prompts, such as security practices, or compliance checks.
246+
* **Team collaboration**. Document patterns and guidelines with references to specs and documentation.
247+
* **Onboarding**. Create step-by-step guides for complex processes or project-specific patterns.
248+
249+
You can have multiple prompt files in your workspace, each of which defines a prompt for a different purpose.
250+
251+
### Examples
252+
253+
The following examples demonstrate how to use prompt files.
254+
255+
* `New React form.prompt.md` - contains instructions for a reusable task to generate a form using React.
256+
257+
```markdown
258+
Your goal is to generate a new React form component.
259+
260+
Ask for the form name and fields if not provided.
261+
262+
Requirements for the form:
263+
- Use form design system components: [design-system/Form.md](../docs/design-system/Form.md)
264+
- Use `react-hook-form` for form state management:
265+
- Always define TypeScript types for your form data
266+
- Prefer *uncontrolled* components using register
267+
- Use `defaultValues` to prevent unnecessary rerenders
268+
- Use `yup` for validation:
269+
- Create reusable validation schemas in separate files
270+
- Use TypeScript types to ensure type safety
271+
- Customize UX-friendly validation rules
272+
```
273+
274+
* `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.
275+
276+
```markdown
277+
Secure REST API review:
278+
- Ensure all endpoints are protected by authentication and authorization
279+
- Validate all user inputs and sanitize data
280+
- Implement rate limiting and throttling
281+
- Implement logging and monitoring for security events
282+
283+
```
284+
285+
For information on how to create and use prompt files, see [AUTOTITLE](/copilot/how-tos/configure-custom-instructions/add-repository-instructions?tool=visualstudio#using-prompt-files).
286+
231287
{% data reusables.copilot.custom-instructions-effective %}
232288

233289
## Next steps

content/copilot/how-tos/configure-custom-instructions/add-repository-instructions.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ This version of this article is for using repository custom instructions and pro
3939

4040
{% visualstudio %}
4141

42-
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.
42+
This version of this article is for using repository custom instructions and prompt files in {% data variables.product.prodname_vs %}. Click the tabs above for instructions on using custom instructions in other environments.
4343

4444
{% data reusables.copilot.repository-custom-instructions-about %}
4545

@@ -282,7 +282,19 @@ Once saved, these instructions will apply to the current project in Eclipse that
282282

283283
{% visualstudio %}
284284

285-
{% data variables.product.prodname_vs %} supports a single `.github/copilot-instructions.md` custom instructions file stored in the repository.
285+
{% data variables.product.prodname_vs %} supports two types of custom instructions. For details of which {% data variables.product.prodname_copilot %} features support these types of instructions, see [AUTOTITLE](/copilot/concepts/prompting/response-customization?tool=visualstudio#support-for-repository-custom-instructions-2).
286+
287+
* **Repository-wide custom instructions**, which apply to all requests made in the context of a repository.
288+
289+
These are specified in a `copilot-instructions.md` file in the `.github` directory of the repository. See [Creating repository-wide custom instructions](#creating-repository-wide-custom-instructions-2).
290+
291+
* **Path-specific custom instructions**, which apply to requests made in the context of files that match a specified path.
292+
293+
These are specified in one or more `NAME.instructions.md` files within the `.github/instructions` directory in the repository. See [Creating path-specific custom instructions](#creating-path-specific-custom-instructions-2).
294+
295+
If the path you specify matches a file that {% data variables.product.prodname_copilot_short %} is working on, and a repository-wide custom instructions file also exists, then the instructions from both files are used.
296+
297+
## Creating repository-wide custom instructions
286298

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

@@ -292,6 +304,10 @@ Once saved, these instructions will apply to the current project in Eclipse that
292304

293305
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.
294306

307+
## Creating path-specific custom instructions
308+
309+
{% data reusables.copilot.custom-instructions-path %}
310+
295311
{% endvisualstudio %}
296312

297313
{% webui %}
@@ -533,9 +549,24 @@ Custom instructions are enabled for {% data variables.copilot.copilot_code-revie
533549

534550
{% data reusables.copilot.custom-instructions-enabling-for-ccr %}
535551

552+
## Using prompt files
553+
554+
{% data reusables.copilot.prompt-files-preview-note %}
555+
556+
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.copilot.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.
557+
558+
### Creating prompt files
559+
560+
1. Add a prompt file, including the `.prompt.md` file name extension inside the `.github/prompts` folder in the root of the repository. The name can contain alphanumeric characters and spaces and should describe the purpose of the prompt information the file will contain.
561+
1. Write the prompt instructions, using Markdown formatting.
562+
563+
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.
564+
565+
For more information about prompt files, see [Use prompt files in {% data variables.product.prodname_vs %}](https://learn.microsoft.com/en-us/visualstudio/ide/copilot-chat-context?view=vs-2022#use-prompt-files) in the {% data variables.product.prodname_vs %} documentation.
566+
536567
## Further reading
537568

538-
* [AUTOTITLE](/copilot/tutorials/customization-library/custom-instructions)—a curated collection of examples
569+
* [AUTOTITLE](/copilot/tutorials/customization-library)—a curated collection of examples
539570

540571
{% endvisualstudio %}
541572

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Prompt files are only available in {% data variables.product.prodname_vscode_shortname %} and JetBrains IDEs.
1+
Prompt files are only available in {% data variables.product.prodname_vscode_shortname %}, {% data variables.product.prodname_vs %}, and JetBrains IDEs.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
> [!NOTE]
2-
> * {% data variables.product.prodname_copilot_short %} prompt files are in {% data variables.release-phases.public_preview %} and subject to change. {% data reusables.copilot.prompt-files-available-in-editors %} See [AUTOTITLE](/copilot/concepts/prompting/response-customization?tool=vscode#about-prompt-files).
2+
> * {% data variables.product.prodname_copilot_short %} prompt files are in {% data variables.release-phases.public_preview %} and subject to change. {% data reusables.copilot.prompt-files-available-in-editors %} See [AUTOTITLE](/copilot/concepts/prompting/response-customization#about-prompt-files).
33
> * For community-contributed examples of prompt files for specific languages and scenarios, see the [Awesome GitHub Copilot Customizations](https://github.com/github/awesome-copilot/blob/main/docs/README.prompts.md) repository.

data/reusables/copilot/repository-custom-instructions-support.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The following table shows which {% data variables.product.prodname_copilot_short
66

77
| | Eclipse | JetBrains IDEs | {% data variables.product.prodname_vs %} | {% data variables.product.prodname_vscode_shortname %} | {% data variables.product.prodname_dotcom_the_website %} | Xcode |
88
| --- | --- | --- | --- | --- | --- | --- |
9-
| {% data variables.copilot.copilot_chat_short %} | {% octicon "check" aria-label="Included" %} <sup>1</sup> | {% octicon "check" aria-label="Included" %} <sup>1</sup> | {% octicon "check" aria-label="Included" %} <sup>1</sup> | {% octicon "check" aria-label="Included" %} <sup>3</sup> | {% octicon "check" aria-label="Included" %} <sup>1</sup> | {% octicon "check" aria-label="Included" %} <sup>1</sup> |
9+
| {% data variables.copilot.copilot_chat_short %} | {% octicon "check" aria-label="Included" %} <sup>1</sup> | {% octicon "check" aria-label="Included" %} <sup>1</sup> | {% octicon "check" aria-label="Included" %} <sup>2</sup> | {% octicon "check" aria-label="Included" %} <sup>3</sup> | {% octicon "check" aria-label="Included" %} <sup>1</sup> | {% octicon "check" aria-label="Included" %} <sup>1</sup> |
1010
| {% data variables.copilot.copilot_coding_agent %} | N/A | N/A | N/A | {% octicon "check" aria-label="Included" %} <sup>4</sup> | {% octicon "check" aria-label="Included" %} <sup>4</sup> | N/A |
1111
| {% data variables.copilot.copilot_code-review_short %} | N/A | {% octicon "x" aria-label="Not included" %} | {% octicon "check" aria-label="Included" %} <sup>1</sup> | {% octicon "check" aria-label="Included" %} <sup>1</sup> | {% octicon "check" aria-label="Included" %} <sup>2</sup> | {% octicon "x" aria-label="Not included" %} |
1212

0 commit comments

Comments
 (0)