GitHub Copilot

Verified against GitHub Copilot Chat · 2026-07-21

Scope Copilot's instructions to one directory with an applyTo instructions file

A path-scoped .github/instructions/*.instructions.md template using the applyTo frontmatter glob, so a directory-specific rule — a different test framework, a stricter API contract, a legacy pattern that must not spread — applies only where it is actually true instead of polluting the repo-wide instructions file.

GitHub Copilot Chat (VS Code)GitHub Copilot coding agentGitHub Copilot code review6 fillable variables

The prompt

Ready to copy — highlighted parts are example details you can swap.

# Path-scoped custom instructions for GitHub Copilot
# Save as .github/instructions/tests.instructions.md — files under .github/instructions/ apply only to the paths
# matched by their applyTo glob, layered on top of .github/copilot-instructions.md rather than
# replacing it, for any Copilot Chat request or coding-agent session touching a matching file.

---
applyTo: 'tests/**/*.spec.ts'
---

## Why this directory gets its own rules
Tests under tests/ use Vitest with a custom fixture loader, a different pattern than the Jest conventions the rest of the repo's older suites still follow.

## Rules that apply only here
- Import the shared fixture loader from tests/fixtures/index.ts instead of building test data inline.
- Never use jest.mock — this directory has no Jest dependency at all.

## Where this deliberately differs from the repo-wide instructions
The repo-wide instructions say to colocate tests next to components; this directory is the deliberate exception for integration tests that span multiple components.
State the difference explicitly rather than leaving Copilot to notice a contradiction and guess
which file wins — both files are added to context together for a matching request, so an unstated
conflict is a coin flip, not a resolved rule.

## A change that should have been caught by this file but was not
A generated test in this directory once called jest.mock directly, which failed at runtime since Jest is not installed here at all.
If a real instance already happened, name it — a rule justified by a concrete miss is easier to
trust than one written speculatively, and it gives Copilot a worked example of the exact mistake
this file exists to prevent, in a form more specific than the rule statement alone.

## Keeping the glob honest
Test the applyTo glob against the actual file tree before relying on it, not just against the one
file you had in mind when writing it — a glob written to match 'tests under this directory' can
just as easily match an unrelated fixtures folder that happens to share a path segment, silently
applying a rule meant for one kind of file to a completely different one nearby. If the directory
this file governs gets restructured later, this file has to move or its glob has to be rewritten
in the same change — an instructions file whose glob no longer matches anything real is worse than
a missing one, because it looks like coverage exists when it does not.

## If more than one instructions file matches the same file
Two different applyTo globs can both match a single file if their scopes overlap even in part —
say directly whether that is expected and, if so, which file's rule should be treated as more
specific when they seem to disagree, since Copilot has no way to infer an intended priority
between two files that were each written independently of the other.

Customize

Optional — swap in your own details for the highlighted parts above.

Why this works

The applyTo glob is matched against the actual files present in a given request's context, so a rule scoped this way only enters the model's attention when it is relevant — a directory-specific caveat about test tooling or a legacy pattern does not have to compete for attention on every unrelated request the way it would if it were stuffed into the repo-wide copilot-instructions.md file just because there was nowhere narrower to put it. The two files genuinely combine rather than override each other, which is why the conflicting_repo_rule section has to state a difference explicitly rather than leaving it implicit — Copilot has no mechanism to infer that a path-scoped file is meant to take precedence over a repo-wide statement it contradicts; both simply arrive in context together, and an unstated disagreement between them is resolved however the model happens to weigh two contradictory instructions in that moment, which is not a resolution you actually chose. Glob correctness matters more than it looks, because a wrong glob fails in two opposite and equally quiet ways: an over-narrow glob silently matches nothing, so the file sits in the repo looking like coverage exists while providing none, and an over-broad glob matches an unrelated directory that happens to share a path segment, applying a narrow rule where it was never meant to hold. Naming a concrete example_violation, when one exists, functions the way a worked example functions in any instruction set — it gives the model a specific, checkable instance of the mistake rather than only an abstract rule, which is a real difference in how reliably a model pattern-matches a new but similar situation against a rule it has actually seen violated once versus a rule it has only been told about.

What you get back

applyTo: 'tests/**/*.spec.ts'. Rule: import the shared fixture loader from tests/fixtures/index.ts instead of building test data inline; never call jest.mock, since this directory has no Jest dependency. Noted conflict: the repo-wide file says colocate tests next to components — this directory is the stated exception for cross-component integration tests.

Verified against

GitHub Copilot Chat Copilot Chat 1.269 (VS Code, path-scoped instructions) · 2026-07-21

Changelog

  • 2026-07-21 Initial publish, verified against Copilot Chat 1.269 (VS Code) applyTo path-scoped instructions.

Need this built into your business?

If a prompt isn't enough — custom software, built and maintained for you — that's Scult's day job.

EXPLORE CUSTOM SOFTWARE
Write a .github/copilot-instructions.md file Copilot actually followsA repository-wide custom-instructions file that Copilot loads automatically into every Chat request, code-review pass, coding-agent session, and commit or PR-description generation in this repo, written so each rule holds up standing alone instead of only in the context it was written in.GitHub Copilot Chat (VS Code)GitHub Copilot code review2026-07-20Define a custom Copilot Chat mode instead of re-explaining your workflow every sessionA .github/chatmodes/*.chatmode.md definition — scoped tools, a fixed model, and a narrow system prompt — that turns a repeated review-and-plan style of conversation into a mode you switch into once, instead of a persona you re-describe in the first message every time.GitHub Copilot Chat (VS Code)2026-07-22Turn a prompt you keep retyping into a Copilot prompt file instead of pasting it againA .github/prompts/*.prompt.md reusable prompt file with input placeholders, invoked as a slash command from the Chat input box, so a well-tuned multi-paragraph prompt becomes one command instead of a paste you have to keep re-finding.GitHub Copilot Chat (VS Code)2026-07-22Configure separate Copilot instructions for commit messages, PR descriptions, reviews, and testsA VS Code settings.json block wiring distinct instruction sets for commit-message generation, pull-request-description generation, code review, and test generation, so each of Copilot's task-specific generators gets rules suited to what it is actually producing instead of inheriting one general-purpose file uniformly.GitHub Copilot Chat (VS Code)GitHub Copilot (VS Code Source Control)2026-07-23
All GitHub Copilot prompts

Check your AI visibility

One URL in, a 0–100 score and the exact fixes out.

RUN THE CHECK

Browse all the tools

15 tools across six categories
13 of them never send your data anywhere

Free · No signup · No trial clock

SEE THE DIRECTORY