Skip to content

Google Analytics, Vercel Web Analytics, Leadsy, the Ship or Die traffic check, the TikTok Pixel, the OpenAI Ads Measurement Pixel, Behavly, the Convincd demo agent and HubSpot stay off until you accept. The help chat starts once you have chosen. The Book a demo button appears once you have chosen. Read our Privacy Policy.

StellarFirmStellarFirm

Platforms

GitHub Copilot custom instructions: tips from the docs

How GitHub Copilot reads custom instructions, path-specific files and AGENTS.md, plus tips on length, scope and iteration, taken from GitHub's own docs.

StellarFirm team5 min read

View as Markdown
On this page

Every coding agent works better when it knows how your project runs. GitHub Copilot gives you several places to write that down, and the way they combine is worth understanding before you create a pile of files. This guide collects the practical points from GitHub's own documentation. Names, menus and limits change, so confirm details in the linked pages.

Which instruction files does Copilot read?#

Copilot reads a small set of Markdown files, from your user level down to the folder you are working in. Which files apply depends on the Copilot feature, and this list is for Copilot CLI; repository-wide instructions are the most widely supported, so check GitHub's docs for code review or the cloud agent. According to the Copilot CLI docs, these include:

LevelFile
You, everywhereA copilot-instructions.md file and modular *.instructions.md files in a Copilot folder in your home directory
The repository.github/copilot-instructions.md, plus modular files under .github/instructions/
Agent guidanceAGENTS.md, CLAUDE.md and GEMINI.md
Extra foldersAny folders you list in a dedicated environment variable

Most repository and agent files are found in the repository root, the current directory, the directories in between, and folders nested along the path of the file being edited. That means a nested AGENTS.md can carry rules for one part of a large codebase.

What are path-specific instructions?#

They are modular files whose frontmatter holds a glob, so the rules apply only when Copilot works on matching files. A rule about test files, a framework or one language then does not leak into unrelated code. The docs also describe an option to exclude a file from code review or from the cloud agent, which helps when a rule only makes sense in one place.

A sensible split, in line with GitHub's guidance:

  • One repository-wide file for general standards.
  • Path-scoped files for language or framework rules.
  • AGENTS.md for guidance aimed at agents.

If you already keep an AGENTS.md for other tools, Copilot can read it too, so you do not have to maintain the same rules twice. We explain the file in making a codebase agent-ready, and compare it with Cursor and Codex rules in Cursor and OpenAI Codex agent tips.

What happens when files overlap?#

Copilot merges every file that applies. The CLI docs say identical duplicates are removed, but there is no general precedence order. If one file says to use tabs and another says spaces, you cannot count on a winner. The fix is editorial, not technical: keep rules consistent, and delete a rule from one place when you add it to another. The CLI also has an instructions command that shows which files are active and lets you switch them off, which is a quick way to debug a surprising answer.

Two smaller limits to know:

  • File references with an @path form work in some files but not in the modular instruction files, and they must stay inside the repository or, for local instructions, the custom instructions folder.
  • Edits do not change a session that is already running, so resume or start a new one.

How should I write the rules?#

Write short, direct statements, grouped under headings, with a small example of the pattern you want and the one you do not. GitHub's code review tutorial adds a few findings worth copying:

  1. Be specific. Rules with concrete examples work. Vague goals such as "be more accurate" do not.
  2. Stay short. Keep each file well under about 1,000 lines. Longer files can give weaker results.
  3. Copy, do not link. Links to external standards did not work well, so paste the relevant content into the file.
  4. Do not ask for the impossible. Requests to change how review comments look, or to change Copilot's core behavior, were listed as things that do not work.
PromptDraft a repository instructions file

Read this repository and draft a .github/copilot-instructions.md. Use short headings and bullet points: how to build, test and lint, the conventions the code follows, and what must not be edited. Add one small good and bad example for the two most important conventions. Use only commands you can verify in the repository, and list anything you are unsure about at the end.

How do I improve instructions over time?#

Treat them like code: start small, test, and change a few things at a time. GitHub suggests beginning with roughly 10 to 20 targeted instructions for your most common needs, trying them on real pull requests, and noting which ones are ignored or misread. Output is not fully deterministic, so expect some variation between runs. Because Copilot code review reads instructions from the pull request's branch, you can test a change to the instructions inside the same pull request that adds it.

PromptAudit existing instructions

Here are our current agent instruction files: [paste]. Find rules that conflict, rules that are vague, and rules that duplicate each other. Propose a shorter version that keeps every specific rule and say what you removed and why.

PromptAdd a path-specific rule file

Create a path-specific instructions file for [language or folder]. Put a glob for the matching files in its frontmatter, then add five short rules with one good and one bad example each. Do not repeat anything already in our repository-wide file, and flag any rule that might conflict with it.

Where does StellarFirm fit?#

Instruction files tell an agent how to work. They do not decide what it is allowed to do. In StellarFirm the Coder reads your repository's own instructions and keeps working inside its own computer. By default, a step that reaches other people, such as a merge or a deploy, waits for your Approve; an automatic merge rule or the production auto-approve switch lets that step run without asking. Writing a good instruction file and keeping a human at the point of consequence are two halves of the same habit; see approval workflows for AI agents and your first week with the StellarFirm Coder.

Frequently asked questions

Where does GitHub Copilot read custom instructions from?

The docs for Copilot CLI list a repository-wide file at .github/copilot-instructions.md, modular files under .github/instructions/, user-level files in a Copilot folder in your home directory, and agent files such as AGENTS.md, CLAUDE.md and GEMINI.md.

What happens when two instruction files disagree?

GitHub's docs say applicable files are merged and no general precedence order exists, so conflicting instructions should be avoided. Keep rules consistent across files.

How long should an instruction file be?

GitHub's guidance for code review instructions says to stay well under about 1,000 lines, because longer files can give weaker results. Start small and add rules over time.

Do edits to instructions affect a session that is already running?

Not in Copilot CLI. The docs say edits do not affect active sessions, so resume or start a new session to pick them up.

Sources