Sub topic 10
Add custom instructions to a repository
Custom instructions are Markdown files stored in your repository. Copilot Chat reads them and adds them to your requests, so project conventions apply without repeating them in every prompt. This chapter covers the repository-wide file, path-specific files, how to confirm they are used, and the common ways they fail.
You should already have Copilot installed and signed in, and know how to use the Chat view and attach context. You should also be able to create files and folders in a VS Code workspace. The file locations and setting names below match recent VS Code releases. Check the Copilot documentation if your version differs.
What custom instructions do
A chat request is more than the text you type. Copilot also sends the files you attached, the current selection, and other context. Custom instructions are one more piece of that context. They are short, standing guidance such as "use Vitest" or "prefer named exports".
Without instructions, you end up writing the same sentence in many prompts. Copilot may also guess wrong about your stack. A TypeScript project using Vitest could get Jest-style tests unless you say otherwise.
Instructions have limits:
- They guide the model but do not force it. Copilot can still produce code that breaks a rule, so review the output as usual.
- They apply to chat features, not to inline suggestions. Typing in the editor does not read your instructions file.
- They are sent with requests, so the content is processed like any other prompt text. Never put secrets in them.
The repository-wide file
The main file is .github/copilot-instructions.md. Create the .github folder at the repository root if it does not exist, then add the file inside it. Because it lives in the repository, it is versioned with the code and shared with everyone who clones it.
# Copilot instructions
- Use TypeScript with strict typing; avoid `any`.
- Write unit tests with Vitest.
- Prefer named exports over default exports.Each line is a plain instruction, and no special syntax is required. Copilot reads the file as natural language. After you save it, new chat requests in that workspace include it automatically.
The setting that controls this is github.copilot.chat.codeGeneration.useInstructionFiles. In current VS Code versions it is on by default, but a team or user settings file may have turned it off. If your instructions seem ignored, check this first.
{
"github.copilot.chat.codeGeneration.useInstructionFiles": true
}How instructions reach a request
The diagram shows how the pieces combine into one request.
All matching instruction sources are added together. They do not override each other in a defined order, so avoid contradictions between files.
Write instructions that work
Short, specific, checkable rules work best. Compare these two lists.
| Weak instruction | Stronger instruction |
|---|---|
| Write good code. | Use TypeScript strict mode; avoid `any`. |
| Test everything. | Write unit tests with Vitest, in a `*.test.ts` file next to the source. |
| Follow our style. | Prefer named exports over default exports. |
| Be careful with the database. | Access the database only through functions in `src/db/`. |
Some guidelines:
- State facts about the project that Copilot cannot infer, such as the test framework, build command, or folder layout.
- Phrase each rule so you could check it by reading the output.
- Keep the file short. A page or less is a good target. Long files dilute the important rules and use up space the model could use for your code.
- Do not describe things the model already does by default, such as "write readable code".
- Do not include instructions about tone or persona unless you want them in every answer.
A fuller example for a small web service might look like this:
# Copilot instructions
## Stack
- Node.js 20, TypeScript with strict typing; avoid `any`.
- Tests use Vitest. Run them with `npm test`.
## Conventions
- Prefer named exports over default exports.
- Put HTTP handlers in `src/routes/` and business logic in `src/services/`.
- Return errors as `{ "error": string }` JSON with a suitable status code.
## Do not
- Do not add new runtime dependencies without asking.
- Do not edit files in `generated/`.Headings help people read the file. The model does not need them, but they cost little.
Path-specific instruction files
One file for a whole repository can be too broad. A monorepo might have a React frontend and a Python backend, and rules for one are noise for the other. VS Code supports instruction files that apply only to certain paths.
Place them in .github/instructions/ with the extension .instructions.md. Each file starts with a front matter block containing an applyTo glob pattern.
---
applyTo: "**/*.test.ts"
---
# Test conventions
- Use `describe` and `it` from Vitest.
- Name tests with the pattern "does X when Y".
- Do not use snapshot tests for logic; assert specific values.The file applies when the files in the request match applyTo. For example, if a test file is attached or open as context, these rules are added. For other files they are left out. This keeps the repository-wide file short and moves details to where they matter.
Notes on path-specific files:
- The
applyTovalue is a glob.**/*.pymatches Python files at any depth. A comma-separated list matches several patterns. - A file without a match is still available to be attached manually in some versions, but do not rely on that. Test it in your build.
- Both kinds of file can apply to one request. The repository-wide file always applies, and path-specific files are added on top.
- Name files by topic, such as
frontend.instructions.mdorsql.instructions.md, so reviewers can find them.
Other places instructions can live
The repository file is the best choice for shared, versioned conventions. There are other layers, and knowing them avoids confusion:
- Personal instructions. VS Code lets you keep instructions in your user profile, which apply to your chats in every workspace. Use these for personal preferences, not team rules.
AGENTS.md. Some VS Code versions can also read anAGENTS.mdfile in the repository root, a convention shared by several coding tools. Check whether the matching setting is enabled in your version. If your team uses more than one tool, this may save you from duplicating content.- Organization-level instructions. On some plans, an organization can set instructions that apply to all its members. These are managed on GitHub, not in your repository.
- Prompt files. Files ending in
.prompt.mdare reusable prompts you run on demand. They are not standing instructions. Use an instruction file for "always do this" and a prompt file for "do this task now".
If you use several layers, keep their content distinct. Repeating a rule in two places only creates a chance for them to drift apart.
Confirm that Copilot used them
Do not assume the file works. Check it.
- Save the file in
.github/copilot-instructions.mdin the folder you opened as the workspace. - Open the Chat view and send a request related to your rules, for example: "Create a function that adds two numbers and a test for it."
- Look at the References or Used references section under the response. VS Code lists the instruction files that were added, and
copilot-instructions.mdshould appear there. - Check the output. If your rule says to use Vitest, the test should import from
vitest.
If you want a quick sanity check, add a harmless but visible rule such as "End every answer with the word DONE", try a request, then remove the rule. This only tests whether the file is being read. Do not commit it.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| The file is never listed under references. | Wrong location or name, such as `.github/copilot-instruction.md` or a file in a subfolder. | Use the exact path `.github/copilot-instructions.md` at the workspace root. |
| It worked before and stopped. | The setting `github.copilot.chat.codeGeneration.useInstructionFiles` was turned off. | Turn it on in the Settings editor. |
| Instructions are not used in a multi-root workspace. | The file is in a folder that is not the root you expect. | Place the file in the root of the folder that holds the code you are editing. |
| A path-specific file never applies. | The `applyTo` glob does not match, or the front matter is malformed. | Check the quotes and the `---` lines, and test with a simple glob such as `**/*.ts`. |
| Copilot follows some rules and breaks others. | The file is long, vague, or contains conflicts. | Shorten it, make rules concrete, and remove contradictions. |
| Suggestions in the editor ignore the rules. | Instructions do not affect inline suggestions. | Use chat or inline chat for work that depends on them. |
Check these as well:
- The folder you opened in VS Code must contain
.github. Opening a subfolder of the repository means the root.githubfolder is not in the workspace. - Your repository might use a
.gitignorerule that excludes.github. The file then works for you but never reaches teammates. Rungit statusto confirm it is tracked. - Instruction text counts against the context limit of the model. A very large file leaves less room for the code you attach.
Maintain the file as a team
Treat the file like code. Change it through pull requests so the team agrees on each rule. When Copilot repeatedly gets something wrong, add one precise rule. When a rule no longer applies, such as after a framework migration, delete it. Old rules cause wrong output that is hard to trace back to its cause.
Exercise
Your repository has a React frontend in web/ and a Python API in api/. You want Copilot Chat to use Vitest only when working with TypeScript test files, and to follow the same naming rules everywhere. Which files would you create, and where?
Show answer
Create .github/copilot-instructions.md for the rules that apply everywhere, such as naming conventions. Create .github/instructions/frontend-tests.instructions.md with front matter applyTo: "web/**/*.test.ts" and the Vitest rules. The repository-wide file always applies, while the path-specific file is added only when the request involves matching files. Then verify in the Chat view that both appear under the response's references.
Exercise
You added .github/copilot-instructions.md saying "Prefer named exports", but inline suggestions while typing still produce default exports. Is the file broken?
Show answer
Not necessarily. Custom instructions apply to Copilot Chat requests, not to inline suggestions. Test the file by asking in the Chat view for a new module and checking that the file appears in the response's references. If it does not appear, check the file path and the github.copilot.chat.codeGeneration.useInstructionFiles setting.