Sub topic 7
Guiding Reviews with Repository Custom Instructions
This chapter assumes you can open and review pull requests on GitHub and that you can write basic Markdown. You should also have already requested a Copilot review at least once. Here you will learn how to steer what Copilot looks for by adding an instruction file to your repository.
Why instructions matter
Without guidance, Copilot reviews every pull request with general-purpose judgment. It may comment on formatting your linter already handles, or miss a rule that is specific to your team. Repository custom instructions are a Markdown file that Copilot reads when it reviews a pull request in that repository. They let you state your team's priorities once, instead of repeating them in every pull request.
Instructions shape the review. They do not guarantee it. Copilot may still skip a rule or apply it inconsistently, so treat the file as a strong hint.
The instruction file
Repository-wide instructions live in one file at a fixed path:
.github/copilot-instructions.mdThe file is plain Markdown with no required structure. It applies to the whole repository, so write only rules that hold everywhere. Rules for one language or folder belong in path-specific files, covered in the next chapter.
Here is an example:
# Review guidelines
- Flag any new database query that is built by string concatenation.
- Point out public functions that have no tests in the same pull request.
- Prefer comments about correctness and security over style; formatting is enforced by the linter.
- Keep each comment short and say why the change is needed.Each line does a different job:
- The first two bullets name concrete things to look for.
- The third sets a priority and tells Copilot what to leave alone.
- The fourth shapes how the comments are written.
Adding the file
- Create a branch in the repository.
- Create the
.githubfolder if it does not exist, then addcopilot-instructions.mdinside it. - Write your guidelines and commit the file.
- Open a pull request and merge it.
Copilot reads the version of the file from the pull request's base branch, which is usually your default branch. Your instructions take effect for reviews only after the file is merged. If you test changes inside the same pull request that edits the file, Copilot will not use the edited version.
Writing instructions that work
Short, specific, checkable rules work best. Compare these two:
| Weak instruction | Stronger instruction |
|---|---|
| Write good, secure code. | Flag any new database query that is built by string concatenation. |
| Make sure everything is tested. | Point out public functions that have no tests in the same pull request. |
| Be helpful. | Keep each comment short and say why the change is needed. |
The weak versions give Copilot nothing it can verify in a diff. The stronger versions name an observable pattern.
Some habits that help:
- Keep the file short. A page or less is enough. Long files dilute the rules that matter most.
- Say what to skip as well as what to flag. Telling Copilot that the linter owns formatting removes a common source of noise.
- Explain the reason when a rule is not obvious. A short "because" helps Copilot apply the rule to cases you did not list.
- Avoid rules Copilot cannot check from a diff, such as "follow the design document" or "match our performance targets".
- Avoid instructions that change the review's format or tone in dramatic ways, such as asking for emoji or long essays. They tend to be unreliable and make comments harder to read.
Common errors
- The file is in the wrong place. A file named
copilot-instructions.mdin the repository root, or one under.github/instructions/, is not the repository-wide file. Check the exact path and name. - The change is not merged. Edits on a feature branch do not affect that branch's review, as described above.
- Rules contradict each other. "Be thorough" and "keep comments minimal" pull in opposite directions. Decide which wins and say so.
- Too many rules. If you list thirty items, expect some to be ignored. Start with the five that matter most.
- Treating the file as enforcement. If a rule must never be broken, such as banning a vulnerable function, enforce it with a test, a linter, or required human review. Copilot's feedback is advisory.
Improving the file over time
Review the comments Copilot posts over several pull requests. If it keeps raising an issue you do not care about, add a line telling it to skip that. If it misses something you care about, add a specific rule for it. Make each change in its own small pull request so you can see its effect.
Exercise
You add a rule to .github/copilot-instructions.md in a pull request, then request a Copilot review on that same pull request to test it. The rule has no effect on the review. Why, and what should you do?
Show answer
Copilot reads the instruction file from the base branch, and the edited file is not merged yet. Merge the pull request that adds the file, then request a review on a later pull request to see the rule applied.
Exercise
Rewrite the vague instruction "Make sure the code is secure" so Copilot can check it in a diff.
Show answer
Name a specific pattern, for example: "Flag any new database query that is built by string concatenation, and say which parameterized alternative to use." Any rule that points to something visible in the changed lines is acceptable.