You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/copilot/concepts/prompting/response-customization.md
+67-11Lines changed: 67 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -200,34 +200,90 @@ For information on how to enable, create, and use prompt files, see [AUTOTITLE](
200
200
201
201
{% visualstudio %}
202
202
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 -->
204
204
205
205
## About customizing {% data variables.product.prodname_copilot_short %} responses
206
206
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.
208
215
209
216
{% data reusables.copilot.custom-insts-nondeterministic %}
210
217
211
218
## About repository custom instructions
212
219
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 %}:
214
221
215
-
{% data reusables.copilot.repository-custom-instructions-support %}
222
+
***Repository-wide custominstructions**, which apply to all requests made in the context of a repository.
216
223
217
-
### Use cases for custom instructions
224
+
These are specified in a `copilot-instructions.md` file in the `.github` directory of the repository.
218
225
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.
220
227
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.
224
229
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.
226
231
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.
228
233
229
234
For a curated collection of examples, see [AUTOTITLE](/copilot/tutorials/customization-library/custom-instructions).
230
235
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
+
231
287
{% data reusables.copilot.custom-instructions-effective %}
Copy file name to clipboardExpand all lines: content/copilot/how-tos/configure-custom-instructions/add-repository-instructions.md
+34-3Lines changed: 34 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ This version of this article is for using repository custom instructions and pro
39
39
40
40
{% visualstudio %}
41
41
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.
43
43
44
44
{% data reusables.copilot.repository-custom-instructions-about %}
45
45
@@ -282,7 +282,19 @@ Once saved, these instructions will apply to the current project in Eclipse that
282
282
283
283
{% visualstudio %}
284
284
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
286
298
287
299
1. In the root of your repository, create a file named `.github/copilot-instructions.md`.
288
300
@@ -292,6 +304,10 @@ Once saved, these instructions will apply to the current project in Eclipse that
292
304
293
305
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.
294
306
307
+
## Creating path-specific custom instructions
308
+
309
+
{% data reusables.copilot.custom-instructions-path %}
310
+
295
311
{% endvisualstudio %}
296
312
297
313
{% webui %}
@@ -533,9 +549,24 @@ Custom instructions are enabled for {% data variables.copilot.copilot_code-revie
533
549
534
550
{% data reusables.copilot.custom-instructions-enabling-for-ccr %}
535
551
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
+
536
567
## Further reading
537
568
538
-
* [AUTOTITLE](/copilot/tutorials/customization-library/custom-instructions)—a curated collection of examples
569
+
* [AUTOTITLE](/copilot/tutorials/customization-library)—a curated collection of examples
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.
> * {% 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).
3
3
> * 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.
0 commit comments