AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

How to Configure Custom Repository Instructions and Rules for GitHub Copilot

廖珮嘉 · 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

GitHub Copilot is notorious for writing code that looks completely plausible while subtly violating your team's architectural patterns. It imports outdated dependencies, defaults to obsolete syntax, or suggests testing patterns your team retired two years ago.

You fix this by committing configuration files directly to your git repository. GitHub Copilot natively reads repository-level instruction files—most notably .github/copilot-instructions.md and scoped .github/instructions/*.instructions.md files—injecting those rules into chat, code review, and background agents without forcing developers to paste custom system prompts into every session.

At 365Finds, our commercial engineering assessment is clear: do not treat repository instructions as a dumping ground for linting rules or code style guides that automated linters already catch. The real leverage comes from defining architectural constraints, dependency preferences, and negative examples where Copilot consistently goes off the rails.


1. Global Repository Instructions: .github/copilot-instructions.md

The simplest and most universally supported configuration file is .github/copilot-instructions.md. Located at the root of your project, this file automatically loads into Copilot Chat in VS Code, JetBrains IDEs, Visual Studio, GitHub.com PR reviews, and Copilot cloud agents.

File Location

my-project/
├── .github/
│   └── copilot-instructions.md
├── src/
└── package.json

What a High-Performance Instruction File Looks Like

365Finds recommends keeping your root instructions file under 60 lines. Long, verbose manifestos dilute the LLM's attention and waste context tokens.

# Repository Rules for GitHub Copilot

## Tech Stack & Architecture
- Runtime: Node.js 22 LTS, TypeScript 5.6 (strict mode enabled).
- Framework: Next.js 15 App Router only. Never generate files in `pages/`.
- State Management: Zustand for client state; TanStack Query for server state. Never suggest Redux.
- Styling: Tailwind CSS v4 utility classes. No inline styles or CSS modules.

## Coding Conventions
- Prefer named exports over default exports.
- Use native `fetch` wrapped in `src/lib/api-client.ts`; do not import `axios`.
- Error handling: Use typed result objects (`Result<T, E>`) rather than throwing raw runtime exceptions.

## Testing & Validation
- Unit tests: Vitest and React Testing Library (`*.test.tsx` colocated with source).
- Never use Jest or Enzyme.
- Write unit tests for all business logic helpers in `src/utils/`.

Every time a developer opens Copilot Chat or invokes inline generation in that repository, Copilot parses this Markdown and uses it as persistent grounding context.


2. Directory-Specific Rules: .github/instructions/*.instructions.md

Monorepos and full-stack projects suffer when backend conventions bleed into frontend UI files. Forcing frontend developers to deal with database ORM rules slows down completions and introduces hallucinations.

GitHub Copilot addresses this through path-specific instruction files placed in .github/instructions/.

File Location and Frontmatter Structure

Create dedicated .instructions.md files under .github/instructions/ and declare an applyTo glob pattern in YAML frontmatter.

my-project/
├── .github/
│   ├── copilot-instructions.md               # Applies globally
│   └── instructions/
│       ├── frontend.instructions.md          # Applies to apps/web/**
│       └── backend.instructions.md           # Applies to services/api/**

Example Frontend File (.github/instructions/frontend.instructions.md)

---
applyTo: "apps/web/**/*.{ts,tsx}"
---
# Frontend UI Guidelines
- Use React Server Components by default; add `'use client'` only when hook state or event listeners are required.
- Accessible components must utilize Radix UI primitives located in `@/components/ui`.
- Do not import `@prisma/client` directly inside UI components.

Example Backend File (.github/instructions/backend.instructions.md)

---
applyTo: "services/api/**/*.ts"
---
# Backend API Guidelines
- Database transactions must run through `prisma.$transaction`.
- All HTTP endpoints must validate request payloads using Zod schemas located in `@/schemas`.
- Never return database entity IDs directly without sanitizing internal audit timestamps.

When a developer edits apps/web/page.tsx, Copilot merges the global .github/copilot-instructions.md with frontend.instructions.md. When they switch to an API route, the backend rules take over automatically.


3. Autonomous Agents and Multi-Turn Instructions (AGENTS.md)

If your team is deploying autonomous coding agents or complex workspace workflows, standard chat instructions are often insufficient. Copilot also respects AGENTS.md files placed in workspace directories (as well as legacy root files like CLAUDE.md or GEMINI.md).

AGENTS.md files follow hierarchical directory inheritance: Copilot consults the closest AGENTS.md file in the folder hierarchy above the file being edited.

monorepo/
├── AGENTS.md                  # Root build and run commands
└── packages/
    └── payment-service/
        └── AGENTS.md          # Strict PCI-DSS compliance & mocking rules

Use AGENTS.md specifically to tell autonomous agents:


4. Editor Settings and Verification

Even the best instruction file is useless if an IDE setting disables it. In Visual Studio Code, verify that workspace instruction parsing is turned on:

  1. Open VS Code Settings (Cmd+, or Ctrl+,).
  2. Search for github.copilot.chat.codeGeneration.useInstructionFiles.
  3. Confirm that it is checked (true), which is the default behavior.
{
  "github.copilot.chat.codeGeneration.useInstructionFiles": true
}

To verify that Copilot is actively using your instructions, open Copilot Chat in VS Code and inspect the active context references, or press Cmd+Shift+P / Ctrl+Shift+P and execute Chat: Open Customizations. Copilot lists all active instruction files associated with your open workspace.


5. What Teams Get Wrong: The 365Finds Rules Checklist

After reviewing dozens of enterprise configurations, 365Finds identified the three most common failure modes:

Anti-PatternWhy It Fails365Finds Better Approach
Pasting the entire ESLint configLLMs cannot reliably enforce 200 mechanical formatting rules in natural language.Run Prettier and ESLint in your pre-commit git hook; keep instructions focused on architecture.
Writing vague platitudesDirectives like "Write clean, readable code" consume tokens without altering model generation weights.Give concrete negative constraints: "Never use any; use unknown with type narrowing."
Monolithic rules for monoreposForcing mobile, frontend, and backend constraints into one file exceeds attention windows.Split into modular .github/instructions/*.instructions.md files using glob matching.

To test your configuration, prompt Copilot Chat with a typical ambiguous query like "Create a user profile component with data fetching." If your instructions mandate TanStack Query and forbid Axios, Copilot should generate the query hook and native fetch wrapper on the first attempt without manual correction.

References