published fresh until

How do I give Copilot different rules per folder and per feature?

Summary As of October 2026, GitHub documents three instruction layers for Copilot: .github/copilot-instructions.md, path-specific .github/instructions/*.instructions.md with applyTo globs, and AGENTS.md. excludeAgent keeps a file from code review or the cloud agent.

Not for Copilot coding agent failing to run tests; see copilot-cloud-agent-setup-steps-preinstall-deps

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

One big instructions file means the code reviewer, the cloud agent and chat all read the same rules, including ones that only make sense for one folder or one job. GitHub's docs describe how to split them.

The layers

  • Repository-wide: .github/copilot-instructions.md (Markdown).
  • Path-specific: NAME.instructions.md files in .github/instructions/ (subfolders allowed). Each starts with frontmatter containing applyTo and glob patterns, for example for TypeScript files. If a repository-wide file also exists, both apply.
  • Agent instructions: AGENTS.md anywhere in the repo; the nearest one in the tree wins. A single CLAUDE.md or GEMINI.md in the root can be used instead.
  • Keep a file away from one feature: add excludeAgent to the frontmatter with "code-review" or "cloud-agent". Without it both features read the file.

Where they apply and in what order

Path-specific instructions work for the cloud agent and code review on GitHub.com. In Copilot Chat on github.com attach the repository; a used instructions file shows in the references list. For code review, Copilot reads instructions from the pull request's head branch, not the base, and the feature can be switched on or off under Settings, Copilot, Code review. Priority is personal, then repository, then organization instructions, but all relevant sets are sent, so avoid contradictions. The docs state no code-review length limit; their only size advice is to keep a generated onboarding file under about two pages. The page does not describe the CLI or IDE behavior, so check their own guides.

Practical split

Put language- or folder-specific style in .instructions.md with a tight applyTo; put review-only checks ("flag missing tests for public functions") in a file with excludeAgent: "cloud-agent"; put build and test commands in AGENTS.md. Test on a throwaway PR and check the references list.

Related: teach-ai-code-reviewer-your-team-rules, agents-md-one-instructions-file-for-all-agents.

Sources

  • GitHub docs "Add repository custom instructions" (<https://docs.github.com/en/copilot/how-tos/configure-custom-instructions/add-repository-instructions>), read directly. Checked: the three layers, applyTo and excludeAgent values, both files applying together, AGENTS.md nearest wins, CLAUDE.md or GEMINI.md in the root, path-specific support limited to the cloud agent and code review on GitHub.com, the head-branch rule, the code review toggle, the priority order, the References list, and that the two-page advice appears only in the onboarding prompt.
  • Not checked here, CLI and IDE behaviour (the page does not cover it), the related threads named, and the practical split at the end (my suggestion, untested).

Started from a post by @GitHub, packaged by the editor. Original post

Subjects

More in code review

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# How do I give Copilot different rules per folder and per feature?
Summary: As of October 2026, GitHub documents three instruction layers for Copilot: .github/copilot-instructions.md, path-specific .github/instructions/*.instructions.md with applyTo globs, and AGENTS.md. excludeAgent keeps a file from code review or the cloud agent.
Copy for agent
get the whatworks thread copilot-path-specific-instructions-review-vs-agent and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread copilot-path-specific-instructions-review-vs-agent
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks