AI Summary: GitHub Copilot ingests repository context through three distinct configuration layers: the global repository file
.github/copilot-instructions.md, path-specific scoped rules in.github/instructions/*.instructions.md(usingapplyToglob filters), and portableAGENTS.mdfiles. Understanding this resolution precedence eliminates conflicting rules and minimizes context dilution in Copilot Chat and code completions.
The Context Assembly Pipeline in GitHub Copilot
GitHub Copilot does not rely exclusively on the open editor buffer. In modern Copilot Chat, Copilot Edits, and Copilot Workspace environments, context is assembled dynamically from multiple inputs:
[Active File & Cursor Position]
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Copilot Prompt Synthesizer │
│ │
│ 1. Neighbor Tabs (Jaccard similarity on recently opened) │
│ 2. Global Repo Instructions (.github/copilot-instructions) │
│ 3. Path-Scoped Rules (.github/instructions/*.instructions) │
│ 4. Local Workspace Standards (AGENTS.md nearest ancestor) │
│ 5. Language Server (LSP) Definitions & Type Signatures │
└─────────────────────────────┬───────────────────────────────┘
│
▼
[Inline Autocomplete / Chat Generation]
If multiple instruction files contradict each other (e.g. global instructions recommend Jest while a path-scoped rule mandates Vitest), the model generates fractured imports or mocks out real runtime modules.
The 3 Instruction Surfaces Explained
1. Global Repository Instructions (.github/copilot-instructions.md)
This file establishes global invariants applied to every Copilot prompt across the repository. It should remain concise (under 500 tokens) and focus on global tooling, package managers, and safety boundaries:
# Repository Guidelines for GitHub Copilot
## Package & Tooling Standards
- Package Manager: `pnpm` (never use npm or yarn).
- Test Framework: `vitest` for unit tests; `playwright` for e2e.
- Module System: ESM modules exclusively (`import`/`export`).
## Security & Privacy
- Never output real API keys, secrets, or internal server IPs in suggestions.
- Server-side data fetching must route through `@/lib/safe-fetch`.
2. Path-Specific Rules (.github/instructions/NAME.instructions.md)
When conventions differ between the backend API and frontend React components, create scoped instruction files with applyTo YAML frontmatter:
---
applyTo: "src/components/**/*.tsx"
---
# Frontend Component Standards
- All components must use named functional exports (`export function Card()`).
- Never use inline CSS styles or Tailwind classes; use CSS variables from `globals.css`.
- Interactive client components must include `'use client'` as the first statement.
When an engineer edits src/components/Modal.tsx, Copilot merges these scoped instructions into context; when editing a backend script, these UI instructions are automatically excluded.
3. Portable AGENTS.md Support
GitHub Copilot natively honors AGENTS.md located in the root or subdirectories. If a directory contains both AGENTS.md and .github/copilot-instructions.md, Copilot concatenates them, giving precedence to the more localized instructions.
Instruction Layer Precedence & Scope Matrix
| Instruction Surface | Physical Location | Activation Condition | Best Suited For |
|---|---|---|---|
| Global Repo Rule | .github/copilot-instructions.md | Injected into all Copilot turns | Package managers, language versions, global security |
| Path-Scoped Rule | .github/instructions/*.instructions.md | Injected only when active file matches applyTo glob | UI conventions, database migration rules, API schemas |
| Vendor-Neutral Agent | AGENTS.md (root or sub-folder) | Recognized by Copilot, Cursor, Claude Code, Cline | Universal commands, testing gates, monorepo hierarchy |
Harmonizing Copilot, Cursor, and Claude Code
To maintain a clean codebase without duplicating documentation across vendor files, follow the Unified Source Pattern:
[AGENTS.md] (Single Source of Truth)
▲
│ Symbolic link or @import
├─────────────────────────────────────────────┐
│ │
[.github/copilot-instructions.md] [CLAUDE.md] / [.cursor/rules/]
(Imports AGENTS.md for Copilot) (Imports AGENTS.md for Claude/Cursor)
By pointing .github/copilot-instructions.md to reference AGENTS.md, your engineering team guarantees that GitHub Copilot, Cursor Composer, and Claude Code CLI follow the exact same architectural standards and test gates.
Related guidance
To configure universal instructions, read our guide on AGENTS.md Best Practices, study editor tuning in Cursor IDE Optimization, and review terminal workflows in Claude Code Optimization.
References
- GitHub Docs: Adding Custom Instructions for GitHub Copilot: Official guide to configuring
.github/copilot-instructions.mdand path-specific rules. - The AGENTS.md Standard: The open standard for cross-platform agent instructions.
Need to optimize your entire site for AI search visibility? Run a comprehensive audit with Geolify.ai.