AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

Configuring Repository Rules and Instructions in GitHub Copilot to Enforce Coding Standards

Solène Génard · 365Finds Editorial
Indexed 88,650 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

Every engineering team adopting GitHub Copilot eventually hits the same frustrating milestone.

Copilot suggests code fast. It looks plausible. Then you look closely at the pull request and realize it used deprecated React lifecycle methods, imported an unapproved utility library, ignored your domain layer boundaries, and omitted error handling. Copilot defaults to the mean of public GitHub repositories. That means it naturally writes whatever was most common on the internet in 2021 unless you explicitly steer it.

At 365Finds, we see engineering managers try to fix this by nagging developers in pull request comments. That does not scale. You cannot fix an automated context problem with manual human policing.

The practical fix is configuring repository-level instructions and rules directly in your source tree. When you wire your conventions into .github/copilot-instructions.md and scoped instruction files, GitHub Copilot shifts from guessing generic patterns to generating code shaped by your team's specific architectural contracts.

Here is how to set it up, how to structure your files, and where LLM instructions end and hard repository rules must take over.


The Two Mechanics: Repository-Wide vs. Path-Specific

GitHub Copilot supports two distinct tiers of repository instructions:

Instruction TypeFile LocationWhen Copilot Applies ItBest Used For
Repository-Wide Instructions.github/copilot-instructions.mdInjected into all Copilot Chat, PR code reviews, and agent prompts within the repositoryUniversal architectural rules, testing libraries, naming conventions, banned dependencies
Path-Specific Instructions.github/instructions/<name>.instructions.mdInjected only when interacting with files matching a YAML applyTo glob patternDistinct frontend vs. backend patterns, database migration rules, unit test scaffolding

At 365Finds, we strongly recommend splitting instructions across these two tiers rather than stuffing everything into a single root file. When you dump an exhaustive 500-line playbook into the root file, you dilute the context window. Copilot's attention degrades, response latency climbs, and the model starts ignoring the subtle rules that matter most.


Step 1: Create Global Rules in .github/copilot-instructions.md

Create a .github directory at the root of your git repository if you do not already have one. Inside it, create copilot-instructions.md.

Copilot treats this file as persistent context across Copilot Chat in IDEs (VS Code, JetBrains, Visual Studio), GitHub.com web chat, and automated Copilot code review on pull requests.

What an Effective Instruction File Looks Like

Keep the file under 150 lines. Focus on constraints, architectural boundaries, and anti-patterns rather than general tutorials. Copilot already knows how to write JavaScript or Python; it does not know what your team bans.

# Repository Coding Standards

## Core Tech Stack
- Runtime: Node.js 22 LTS with ESM (`"type": "module"`).
- Language: TypeScript 5.6+ with strict type checking enabled.
- Web framework: Fastify. Do not suggest Express or NestJS.
- Test runner: Vitest. Never write tests using Jest or Mocha.

## Architecture Boundaries
- Route handlers (`src/api/routes/*`) must never execute direct database queries.
- All persistence logic belongs strictly inside `src/repositories/*`.
- Domain services (`src/services/*`) must take dependencies via constructor injection.

## Mandatory Coding Patterns
- Always use explicit return types on exported functions. Never rely on type inference for public interfaces.
- Avoid the `any` type completely. Use `unknown` with runtime type narrowing (Zod schemas) when input shape is unpredictable.
- Handle errors using domain-specific Result objects or custom error classes extending `AppError`. Never return raw strings in catch blocks.

## Prohibited Libraries & Anti-Patterns
- Never import `lodash` or `underscore`. Use native ES2024 array methods.
- Do not suggest `axios` or `request`. Use native `fetch` with typed wrapper helpers in `src/lib/http.ts`.
- Avoid default exports. Always use named exports for functions, classes, and types.

Notice what 365Finds prioritizes here: explicit negatives. Models fall back on outdated habits unless you tell them what not to import. Explicitly stating "Use native fetch; do not suggest axios" eliminates half of unnecessary third-party package PR comments.


Step 2: Configure Scoped Rules via .github/instructions/*.instructions.md

In multi-tier projects or monorepos, backend conventions will contradict frontend conventions. A rule requiring immutability and functional composition in React will confuse a developer writing an imperative database migration script.

GitHub Copilot handles this via modular instruction files inside .github/instructions/. Each file specifies target files using the applyTo YAML frontmatter key.

Example: Frontend React Guidelines

Create .github/instructions/frontend.instructions.md:

---
applyTo: "src/frontend/**/*.{ts,tsx}"
---
# Frontend Component Standards

- Framework: React 19 with Vite.
- Styling: Tailwind CSS utility classes exclusively. Never suggest inline style attributes or separate `.css` modules.
- State Management: Use TanStack Query for server state. Use React Context only for global user preferences (theme, auth state).
- Components:
  - Write functional components with named function declarations.
  - Decompose components that exceed 120 lines into internal sub-components.
  - Require `aria-label` or explicit text labels on all interactive buttons and links.

Example: Database Migrations and Repositories

Create .github/instructions/database.instructions.md:

---
applyTo: 
  - "src/repositories/**/*.ts"
  - "src/migrations/**/*.sql"
---
# Database Persistence Rules

- ORM/Query Builder: Kysely with PostgreSQL.
- Id generation: Use UUIDv7 via `crypto.randomUUID()` for primary keys. Never use sequential integer IDs.
- Concurrency: Transactions must specify explicit isolation levels (`Serializable` or `RepeatableRead`) for balance mutations.
- Safety: Every SQL migration script must include both an `UP` and a corresponding idempotent `DOWN` block.

When a developer opens a file in src/frontend/components/UserCard.tsx and invokes Copilot Chat, Copilot pulls both the global .github/copilot-instructions.md and the frontend instruction file. The database rules stay out of memory, preserving token budget for the actual task.


Step 3: Enforce Guidelines During Pull Requests with Copilot Code Review

Writing instructions for code generation is only half the enforcement loop. Developers will still copy-paste legacy snippets or accept quick completions without reading them.

GitHub Copilot Code Review uses .github/copilot-instructions.md automatically when reviewing pull requests.

To ensure it works:

  1. Navigate to your repository on GitHub.com.
  2. Go to Settings > Copilot > Code review.
  3. Verify that Copilot code review is active and repository custom instructions are permitted.
  4. When a contributor opens a pull request, request a review from @github-copilot or configure automated Copilot reviews on new PRs.

Copilot will compare the incoming diff against the rules laid out in your instruction files. If a developer accepts a suggestion using axios or writes an any type, Copilot flags the line in the PR review with the exact rule citation from your .github/copilot-instructions.md.


Step 4: The 365Finds Reality Check — Instructions Are Not Compiler Guarantees

Here is where 365Finds insists on intellectual honesty: Copilot instructions are prompt context, not deterministic enforcement.

An LLM interprets instructions probabilistically. It can still slip. Under long chat sessions or complex multi-file refactors, Copilot will occasionally ignore a negative constraint.

If your team treats .github/copilot-instructions.md as an alternative to linters and CI checks, you will regret it.

+-------------------------------------------------------------------+
|                     Enforcement Architecture                      |
+-------------------------------------------------------------------+
|  Upstream Guidance (Probabilistic)                                |
|  - .github/copilot-instructions.md (Universal architectural context)|
|  - .github/instructions/*.instructions.md (Directory-scoped rules) |
|  - GitHub Copilot Code Review (Automated PR sanity feedback)       |
+-------------------------------------------------------------------+
                                  │
                                  ▼
|  Downstream Gatekeeping (Deterministic)                            |
|  - ESLint / Biome / Ruff / Clippy (Syntax and static analysis)    |
|  - TypeScript Compiler (`tsc --noEmit`)                           |
|  - GitHub Repository Rulesets (Require passing CI before merge)   |
+-------------------------------------------------------------------+

True team code standard enforcement requires two layers working in tandem:

  1. Upstream Guidance (GitHub Copilot): Instructions steer the model to produce clean, compliant drafts right at the cursor, eliminating tedious syntax rework before the developer even commits.
  2. Downstream Gatekeeping (GitHub Repository Rulesets): Configure GitHub Rulesets (Settings > Rules > Rulesets) requiring mandatory status checks (ESLint, Prettier, unit tests) and blocking merges if branch protections fail.

Use Copilot instructions to teach the AI your team's intentions. Use static linters and repository rulesets to protect your main branch.


Summary Checklist for Teams

References