08-Custom instructions for GitHub Copilot in VS Code
08-Custom instructions for GitHub Copilot in VS Code
com/docs/copilot/copilot-customization
(https://vscode.dev/github/microsoft/vscode-docs/blob/main/docs/copilot/copilot-customization.md)
Copilot applies these instructions to chat prompts in the Chat view, Quick Chat, or Inline Chat. These instructions are not
displayed in the chat, but are passed to Copilot by VS Code.
• Code-generation instructions - provide context specific for generating code. For example, you can specify that private
variables should always be prefixed with an underscore, or that singletons should be implemented a certain way. You
can specify code-generation instructions in settings, or in a Markdown file in your workspace.
• Test-generation instructions - provide context specific for generating tests. For example, you can specify that all
generated tests should use a specific testing framework. You can specify test-generation instructions in settings, or in a
Markdown file in your workspace.
• Code review instructions - provide context specific for reviewing the current editor selection. For example, you can
specify that the reviewer should look for a specific type of error in the code. You can specify review-selection
instructions in settings, or in a Markdown file in your workspace.
• Commit message generation instructions - provide context specific for generating commit messages. You can specify
commit-message-generation instructions in settings, or in a Markdown file in your workspace.
Custom instructions consist of natural language instructions and should be short, self-contained statements that add context
or relevant information to supplement chat questions.
Copilot can help you generate code, for example as part of a refactoring, generating unit tests, or implementing a feature. You
might have specific libraries you want to use in your project, or a particular coding style you want to follow for the code that
Copilot generates.
Note
Copilot does not apply code-generation instructions for code completions (/docs/copilot/ai-powered-suggestions).
Use settings
You can configure custom code-generation instructions by using the
! (vscode://settings/github.copilot.chat.codeGeneration.instructions)github.copilot.chat.codeGeneration.instructions
setting. You can define custom instructions at the User or Workspace level, and you can also specify language-specific
instructions. Get more information about language-specific settings (/docs/editor/settings#_language-specific-editor-
settings).
The following code snippet shows how to define a set of instructions in the settings.json file. To define instruction directly
in settings, configure the text property. To reference an external file, configure the file property.
"github.copilot.chat.codeGeneration.instructions": [ Copy
{
"text": "Always add a comment: 'Generated by Copilot'."
},
{
"text": "In TypeScript always use underscore for private field names."
},
{
"file": "code-style.md" // import instructions from file `code-style.md`
}
],
If you define custom instructions in both the .github/copilot-instructions.md file and in settings, Copilot tries to
combine instructions from both sources.
Note
GitHub Copilot in Visual Studio also detects the .github/copilot-instructions.md file. If you have a workspace that
you use in both VS Code and Visual Studio, you can use the same file to define custom instructions for both editors.
1 Set the
! (vscode://settings/
github.copilot.chat.codeGeneration.useInstructionFiles)github.copilot.chat.codeGeneration.useInstructionFiles
setting to true to instruct Copilot in VS Code to use the custom instructions file.
2 Create a .github/copilot-instructions.md file at the root of your workspace. If needed, create a .github directory
first.
Tip
In the Explorer view in VS Code, you can create the folder and directly in one operation by typing the full path as
the file name.
3 Add natural language instructions to the file. You can use the 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.
You can use Copilot to generate tests for your code, for example by using the @workspace /tests prompt in the Chat view.
You can define custom instructions to help Copilot generate tests that are specific to your project and development workflow.
The following code snippet shows how to define a set of instructions in the settings.json file. To define instruction directly
in settings, configure the text property. To reference an external file, configure the file property.
"github.copilot.chat.testGeneration.instructions": [ Copy
{
"text": "Always use vitest for testing React components."
},
{
"text": "Use Jest for testing JavaScript code."
},
{
"file": "code-style.md" // import instructions from file `code-style.md`
}
],
You can use Copilot to review a selection of code in the editor. You can define custom instructions to help Copilot take into
account specific code review criteria that are relevant to your project and development workflow.
In the Source Control view, you can use Copilot to generate a commit message for the pending code changes. You can define
custom instructions to help Copilot generate a commit message that takes into account specific formatting and structure that
are specific to your project and development workflow.
• Keep your instructions short and self-contained. Each instruction should be a single, simple statement. If you need to
provide multiple pieces of information, use multiple instructions.
• Don't refer to external resources in the instructions, such as specific coding standards.
• Make it easy to share custom instructions with your team or across projects by storing your instructions in an external
file. You can also version control the file to track changes over time.
Prompt files (prompts) 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.
• 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.
• security-api.prompt.md - documents reusable security practices for REST APIs, which can be used to do security
Usage
To enable prompt files, configure the ! (vscode://settings/chat.promptFiles)chat.promptFiles VS Code setting. By default,
prompt files are located in the .github/prompts directory of your workspace. You can also specify additional folders where
prompt files are located.
Within a prompt file, 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 to create a hierarchy of prompts, with reusable prompts that can be
shared across multiple prompt files.
1 Select the Attach Context " icon ( ⌘/ ), and then select Prompt....
2 Choose a prompt file from the Quick Pick to attach it to your chat request.
You can use prompt files in both Copilot Chat and Copilot Edits.
For reusable tasks, send the prompt without any additional instructions.
To further refine a reusable prompt, 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.
Settings
! (vscode://settings/
• github.copilot.chat.codeGeneration.instructions)github.copilot.chat.codeGeneration.instructions
(Experimental): A set of instructions that will be added to Copilot requests that generate code.
! (vscode://settings/
• github.copilot.chat.codeGeneration.useInstructionFiles)github.copilot.chat.codeGeneration.useInstructionFiles
(Preview): Controls whether code instructions from .github/copilot-instructions.md are added to Copilot
requests.
! (vscode://settings/
• github.copilot.chat.testGeneration.instructions)github.copilot.chat.testGeneration.instructions
(Experimental): A set of instructions that will be added to Copilot requests that generate tests.
! (vscode://settings/
• github.copilot.chat.reviewSelection.instructions)github.copilot.chat.reviewSelection.instructions
(Preview): A set of instructions that will be added to Copilot requests for reviewing the current editor selection.
! (vscode://settings/
• github.copilot.chat.commitMessageGeneration.instructions)github.copilot.chat.commitMessageGeneration.instructions
(Experimental): A set of instructions that will be added to Copilot requests that generate commit messages.
true Enable prompt files. Use the default prompt file location ( .github/prompts ).
{ "/path/to/folder": Enable prompt files. Specify one or more folders where prompt files are located. Relative
boolean } paths are resolved from the root folder(s) of your workspace.
Related content
Yes No
02/06/2025
Follow @code(https://go.microsoft.com/fwlink/?LinkID=533687)
Request features(https://go.microsoft.com/fwlink/?LinkID=533482)
Report issues(https://www.github.com/Microsoft/vscode/issues)
Watch videos(https://www.youtube.com/channel/UCs5Y5_7XK8HLDX0SLNwkd3w)
(https://
www.microsoft.com)
(https://go.microsoft.com/fwlink/?LinkID=533687)
(https://github.com/microsoft/vscode) (https://www.youtube.com/@code)
Support (https://support.serviceshub.microsoft.com/supportforbusiness/create?sapId=d66407ed-3967-
b000-4cfb-2c318cad363d)
Privacy (https://go.microsoft.com/fwlink/?LinkId=521839) Terms of Use (https://www.microsoft.com/legal/terms-of-use)
License (/License)