Sub topic 7
Guiding reviews with repository custom instructions
This chapter assumes you can open and review pull requests on GitHub. It also assumes you have read the earlier chapters on requesting a Copilot review and reading its comments. You should know basic Markdown. You need write access to a repository to add instruction files.
What custom instructions do
By default, Copilot reviews a pull request using only its general knowledge of code. It does not know your team's conventions, which risks you care about most, or which issues your linter already catches. As a result, its comments can be generic or can repeat what your tools already enforce.
Repository custom instructions are a Markdown file stored in your repository. Copilot reads it when it reviews a pull request in that repository. The file tells Copilot what to look for, what to skip, and how to word its comments.
Instructions guide the review. They do not control it. Copilot's output is non-deterministic, so the same pull request with the same instructions can produce slightly different comments on different runs. Treat the file as strong guidance, not as a rule engine. If a rule must never be broken, enforce it with a test, a linter, or a required status check, and keep the instruction as a backup.
Where the file lives
The repository-wide file has a fixed name and location:
.github/copilot-instructions.mdCreate the .github folder at the repository root if it does not exist. The file applies to the whole repository. It is also used by other Copilot features, such as chat, so write it with that in mind. The review-specific rules you add here may show up in other Copilot responses too.
Copilot reads the version of the file on the pull request's base branch. This has a practical effect. If you open a pull request that edits copilot-instructions.md, the edited rules do not apply to that same review. They apply only after the change is merged into the base branch. When you test new instructions, merge them first, then open a fresh pull request to see the effect.
A first instruction file
Here is a starting file:
# 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 rule names a concrete, checkable pattern (string-built queries). Copilot can find it by reading the diff.
- The second rule asks Copilot to compare two things in the same pull request: new public functions and new tests.
- The third rule sets priorities and tells Copilot what to leave alone. Saying that the linter handles formatting removes a whole class of noisy comments.
- The fourth rule controls tone and length, so comments are easy to read and each one explains its reason.
How the review flows with instructions
Writing instructions that work
Good instructions share a few traits. Use them as a checklist when you write or revise your file.
- Be specific. "Write secure code" gives Copilot nothing to act on. "Flag queries built by string concatenation" does.
- Be short. A long file dilutes its own rules. Copilot's handling of very long instruction files is limited, and the later rules may be given less weight or ignored. GitHub's guidance is to keep the file concise, so aim for a page or less.
- State priorities. Tell Copilot what matters most. Without a ranking, it may spend comments on minor points.
- Say what to skip. Naming things that tools already handle, such as formatting or import order, reduces noise.
- Describe the output. Rules about comment length and the need to give a reason make reviews easier to act on.
- Use plain, direct sentences. Short bullet points in the imperative work better than paragraphs of explanation.
Group rules under headings
When your list grows beyond a handful of items, group it under headings. Headings help you maintain the file, and they give Copilot a clear structure to read.
# Review guidelines
## Security
- Flag any new database query that is built by string concatenation.
- Flag secrets, tokens, or passwords written directly in source files.
- Check that user input is validated before it reaches file paths or shell commands.
## Tests
- Point out public functions that have no tests in the same pull request.
- Note bug fixes that do not include a test that fails without the fix.
## Style of comments
- 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.
- Suggest a concrete fix when one is obvious.What to avoid
Some instruction styles reliably cause problems. These are the common ones.
| Instruction style | Example | Problem |
|---|---|---|
| Vague quality goals | "Make the code better" | Gives no check to perform, so comments stay generic |
| Style or tone changes to the product | "Respond like a pirate" | Distracts from review content and may reduce clarity |
| Requests for external lookups | "Compare against our wiki page" | Copilot cannot follow links to outside content reliably |
| Contradictory rules | "Be brief" and "Explain everything in detail" | Output varies between runs |
| Rules that duplicate tools | "Check for trailing spaces" | Adds noise when a linter already does this |
| Commands about the review process | "Approve if all looks fine" | Copilot only leaves a Comment review. It does not approve or block a merge |
The last row matters for your workflow. Copilot's review always has the Comment status. No instruction can turn it into an approval, and it does not count toward required approvals. Chapter content on human review later in this tutorial covers how to combine the two.
Testing and improving your instructions
Instruction files are easy to write and hard to judge in the abstract. Improve them with a short feedback loop.
- Write a small first version with three to six rules.
- Merge it into the base branch.
- Open or update a few real pull requests and request a Copilot review on each.
- Look at which comments were useful and which were noise.
- Add a rule to remove a recurring kind of noise, or to reinforce something Copilot missed.
- Remove rules that never produce a useful comment.
Keep a record of changes in the normal way, through pull requests to the instruction file. Because the file is versioned, you can use history to see when a change made reviews better or worse. Ask the team to review changes to this file, since it shapes every future review.
Common errors
- The file is in the wrong place. The name must be exactly
copilot-instructions.md, and it must be inside.githubat the repository root. A file namedCOPILOT.mdor one placed indocs/is ignored. - You tested on the same pull request that adds the file. As described above, the base branch version is used. Merge first, then test on a new pull request.
- The rules are too many or too long. If Copilot seems to ignore your later rules, shorten the file and move the most important rules to the top.
- A rule works only some of the time. This is expected from a non-deterministic system. If a rule is vital, back it with a automated check.
- The rules clash with another source of guidance. If you use path-specific files (covered in the next chapter), keep them consistent with the repository-wide file. Contradictions lead to uneven results.
- Copilot flags something you told it to skip. Reword the rule to be more direct and name the exact pattern. "Do not comment on formatting such as indentation or line length" is clearer than "ignore style".
Keeping the file useful over time
Your codebase and team habits change. Revisit the file when any of these happen:
- You adopt a new framework or language.
- A kind of bug starts to recur and reaches production.
- The team adds a linter rule that makes an instruction redundant.
- Reviewers report that Copilot comments have become noisy.
Small, regular edits work better than large rewrites, because you can see which change caused which effect.
Summary
A repository instruction file at .github/copilot-instructions.md lets you point Copilot's review at the issues that matter in your project. Keep it short, specific, and ranked by priority. State what to skip as well as what to flag. Remember that Copilot reads the file from the base branch, that results vary between runs, and that the review is a comment and never an approval. The next chapter shows how to limit guidance to specific files with path-specific instructions.
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 see the rule work. The review ignores the new rule. Give the most likely cause and the steps to test the rule properly.
Show answer
Copilot reads the instruction file from the base branch, not from the pull request's own changes. The new rule is not on the base branch yet, so it does not apply. Merge the change into the base branch, open a new pull request that contains code the rule should catch, request a Copilot review, and check whether the comment appears. Because output varies between runs, try more than one pull request before judging the rule.
Exercise
A teammate proposes adding this line: "Make sure the code is clean and well written, and approve the pull request if there are no problems." Name two problems with it and rewrite the first part as a usable rule.
Show answer
First, the quality goal is vague, so it gives Copilot nothing concrete to check. Second, Copilot cannot approve a pull request. Its review has the Comment status and does not count toward required approvals. A usable rewrite is: "Flag functions longer than 50 lines and suggest how to split them, and point out duplicated logic that already exists elsewhere in the same file." Any rule that names a specific, checkable pattern is acceptable.