AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

How to Configure Repository-Level Custom Instructions in GitHub Copilot

Betsy Paoletta · 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

Default GitHub Copilot behaves like a brilliant contractor with zero memory. It writes code based on billions of public GitHub lines, guessing your team's architecture from whichever three tabs you happen to leave open. Without explicit guidance, it will happily suggest deprecated lifecycle hooks, write mock styles your team retired two years ago, or bypass your data-access layer entirely.

The fix takes less than five minutes: create .github/copilot-instructions.md at the root of your repository.

Here is exactly how to set it up, how GitHub Copilot consumes it across editors and code reviews, and what 365Finds recommends putting in—and leaving out of—the file.

Step 1: Create the Instruction File

In the root directory of your project:

  1. Create a .github directory if it does not already exist.
  2. Create a Markdown file named copilot-instructions.md:
    mkdir -p .github && touch .github/copilot-instructions.md
    
  3. Commit and push the file to your default branch (main or master).

Once pushed, GitHub Copilot automatically discovers the file. Whenever a developer on your team uses Copilot Chat in VS Code, JetBrains IDEs, Visual Studio, or Xcode, triggers pull request summaries, or invokes Copilot Code Review on GitHub.com, Copilot injects this document into the background prompt context.

Step 2: What to Include in copilot-instructions.md

At 365Finds, our rule for this file is simple: treat it as an architectural boundary, not an employee handbook.

The ideal file is between 40 and 120 lines. If you paste your entire corporate style guide into it, you will flood the context window, dilute the model's attention, and end up with worse code than if you had left it blank.

A high-impact template covers four areas:

# Repository Instructions for GitHub Copilot

## Project Overview & Tech Stack
- Modern full-stack application built with Next.js 15 (App Router), TypeScript (strict mode), and Tailwind CSS v4.
- Data fetching uses Server Components by default; client fetching uses TanStack Query.
- State management uses Zustand (no Redux, no React context for global state).

## Architecture & Code Boundaries
- All database queries belong strictly in `src/server/db/queries/`. Never query the database directly inside route handlers or UI components.
- API route handlers in `src/app/api/` must validate input payloads using Zod schemas located in `src/shared/schemas/`.
- Domain business logic lives in `src/core/services/` and must remain pure functions without direct HTTP request references.

## Coding Conventions
- Prefer functional components with explicit TypeScript interfaces. Do not use `React.FC`.
- Use early returns and guard clauses to minimize nesting depth.
- Error handling: return custom `Result<T, E>` types for internal operations instead of throwing generic errors.

## Testing Standards
- Unit tests run via Vitest. Place test files next to the source code as `[filename].test.ts`.
- Prefer React Testing Library querying by accessibility role (`getByRole`) over `querySelector` or test IDs.

## Anti-Patterns & Preferences
### Bad (Avoid):
```typescript
// Do not fetch data in client useEffect hooks
useEffect(() => {
  fetch('/api/user').then(res => res.json()).then(setData);
}, []);

Good (Prefer):

// Use React Server Component or TanStack Query
const { data, isPending } = useQuery({
  queryKey: ['user'],
  queryFn: fetchUserProfile,
});

## Step 3: Granular Rules with Path-Specific Instructions

A single root instruction file works well for standalone services. But in monorepos or full-stack projects, frontend guidelines often conflict directly with backend rules. If your instruction file says "prefer immutable functional programming" for React, Copilot might start fighting your Go or Rust microservice inside the same repo.

To solve this, GitHub Copilot supports path-specific instruction files.

1. Create a directory named `.github/instructions/`.
2. Inside it, create dedicated Markdown files with the `.instructions.md` suffix (for example, `.github/instructions/backend.instructions.md`).
3. Add an `applyTo` frontmatter block to target specific directory globs:

```markdown
---
applyTo: "apps/api/**/*.go"
---
# Backend Go Guidelines
- Follow standard Go package layout.
- Use `context.Context` as the first argument in all exported functions that perform I/O.
- Wrap errors with `fmt.Errorf("action description: %w", err)` to maintain trace stacks.

When a developer opens or edits a matching Go file, GitHub Copilot automatically loads these backend rules alongside or in place of the broader repository instructions.

Step 4: Verify Repository Settings on GitHub

If your organization uses Copilot Code Review on pull requests:

  1. Open your repository on GitHub.com and select Settings.
  2. In the left sidebar under "Code, planning, and automation", navigate to Copilot > Code review.
  3. Verify that custom instructions are toggled on so automated PR reviews enforce the rules declared in .github/copilot-instructions.md.

The 365Finds Take: Where Teams Go Wrong

We see engineering leads make two predictable mistakes when configuring custom instructions:

First is treating .github/copilot-instructions.md as a substitute for linters. Telling Copilot "always use semicolons" or "indent with 2 spaces" is a waste of prompt tokens. ESLint, Biome, and Prettier already enforce syntax deterministically in milliseconds. Reserve custom instructions for intent, architectural boundaries, and library preferences that static analyzers cannot infer.

Second is writing vague platitudes like "write modular, clean, and testable code." GitHub Copilot already defaults to generic "clean code" tropes from its training corpus. What Copilot lacks is your repository's local context: which legacy libraries to avoid, where internal utilities reside, and which architectural boundaries must never be breached.

When written with concrete "Do this / Avoid that" examples, a concise .github/copilot-instructions.md turns GitHub Copilot from an unpredictable autocomplete engine into a tool that respects your repository's actual design.

References