GitHub Copilot applyTo: Apply Instructions by File Type¶
For / Key Points
For: Developers using Copilot in multi-language or multi-framework repositories
Key Points: - .github/instructions is a default discovery location - applyTo scopes a file with repository-relative globs - Verify application through References, Diagnostics, or /instructions
Do not apply React conventions to Python code. Split rules into *.instructions.md files and use applyTo to select their target paths. This is GitHub Copilot's path-specific instruction model.1
The design question is: which rules should always apply, and which should follow a file path?
The minimum setup needs only two files¶
Put repository-wide rules in .github/copilot-instructions.md. Put language- or directory-specific rules in .github/instructions/*.instructions.md.
.github/
├── copilot-instructions.md
└── instructions/
├── frontend.instructions.md
└── python.instructions.md
.github/instructions is a default discovery location in VS Code and GitHub Copilot CLI. If you use only that location, you do not need the older chat.instructionsFilesLocations setup shown in some guides.2
Add applyTo¶
A frontend instruction file can look like this:
---
description: React and TypeScript implementation rules
applyTo: "**/*.ts,**/*.tsx"
---
## Frontend rules
- Keep TypeScript strict mode enabled
- Never call React Hooks inside a conditional branch
- Update tests for every changed behavior
applyTo uses repository-relative glob patterns. Separate multiple patterns with commas. .tsx matches the current directory, while **/.tsx includes nested directories.
VS Code can attach an instruction file manually when applyTo is absent, but it will not apply that file automatically. For rules shared with Copilot CLI or cloud surfaces, an explicit applyTo is easier to reason about.
Keep always-on and path-specific rules independent¶
When several instruction files apply, Copilot can add all of them to the request. Do not rely on a universal precedence rule to resolve conflicts.3
| File | Put here | Keep out |
|---|---|---|
copilot-instructions.md | Build, test, and architecture conventions | React-only naming |
frontend.instructions.md | TSX, CSS, and accessibility rules | Python exception handling |
python.instructions.md | Type hints, pytest, and formatting | Frontend state management |
AGENTS.md | Repository operations shared across agents | Copilot-only UI settings |
A link from a general instruction file does not guarantee automatic path-based application. Use applyTo for that behavior.
Configure locations only when adding non-default folders¶
Use the VS Code setting when you need an additional workspace or profile directory:
{
"chat.instructionsFilesLocations": {
".github/instructions": true,
"docs/copilot-rules": true
}
}
This setting does not enable applyTo. It changes discovery locations. Automatic pattern application is controlled by chat.includeApplyingInstructions, which is enabled by default.2
Account for surface differences¶
VS Code, Copilot CLI, cloud agent, and code review do not implement every instruction behavior identically.
- VS Code can consider both path matches and semantic relevance from the description
- Copilot CLI exposes discovered files through
/instructions excludeAgent: "code-review"excludes Copilot code reviewexcludeAgent: "cloud-agent"excludes the cloud agent
Use the current value cloud-agent, not the older coding-agent wording. Custom instructions also do not apply to inline suggestions as you type.1
Troubleshooting order¶
- Confirm the name ends with
.instructions.md - Confirm the file is in a discovered location
- Test the glob against the actual repository path
- Inspect VS Code References or Customization Diagnostics
- In Copilot CLI, start a new session and run
/instructions
An active Copilot CLI session might not reload an instruction change immediately. Verify in a fresh session.
Operating decision¶
More files do not automatically improve results. Map each file to one technology stack or one quality responsibility so overlaps remain visible.
Do not invent a percentage improvement in context use or output quality.
Summary¶
Record the applied instruction, generated change, and test result, then judge each rule from evidence.