Your profile

One profile for every MSDEVBUILD site. Only you can see it, and the site owner if you write in.

Lesson 11 of 30
❮Prev Next❯

Custom Instructions and Prompt Files

Module 2: Copilot Features ⏱ 10 min read Updated

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    All my bookmarks and notes

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    30-second answer

    Custom instructions are standing rules that Copilot adds to requests for you. Repository-wide rules go in .github/copilot-instructions.md, which Copilot Chat, the coding agent and code review all read; path-specific rules go in .github/instructions/*.instructions.md with an applyTo glob; agents also read AGENTS.md. A prompt file (.github/prompts/*.prompt.md) is a reusable prompt you run with /name in chat, with front matter for mode, description, tools and model and ${input:name} variables, so everyone on the team sends the same request.

    Simulate it » No Azure account needed

    Exam objective: 2.3.3 Use Spaces, Spark, Pull Request summaries, and customizable review standards via instructions files. 2.3.4 Understand the limits, options, feedback, and commands of GitHub Copilot Chat; include prompt file reuse for consistent responses. (Skills measured as of August 7, 2026)

    Simulations

    Feel it before you read it. No account needed, nothing leaves this page.

    VS Code & GitHub: Custom instructions and prompt files Write repository instructions, a path rule and a prompt file.
    </> Embed

    Embed this simulation

    Free for trainers, teachers and bloggers. Paste this into your page:

    Loading…

    <strong>Repository custom instructions</strong> live in <code>.github/copilot-instructions.md</code>. Copilot Chat, the coding agent and code review add them to requests in this repo automatically.

    👆 Click the glowing item on screen to continue

    Read the steps as text
    1. Repository custom instructions live in .github/copilot-instructions.md. Copilot Chat, the coding agent and code review add them to requests in this repo automatically.
    2. Path-specific instructions go in .github/instructions/.instructions.md with an applyTo glob, so test rules only apply to test files.
    3. A prompt file (.github/prompts/.prompt.md) is a reusable prompt. Everyone on the team gets the same, consistent request.
    4. Run it in chat by typing /new-endpoint. The answer shows which instruction and prompt files were used, so you can check they applied. Personal and organization instructions can be added too.

    🧪 Simulation for learning. Screens are simplified versions of Visual Studio Code and github.com with GitHub Copilot; names, files and suggestions are examples. Not affiliated with GitHub or Microsoft, and nothing here touches your real account.

    😟 THE PROBLEM

    You type “use the Node test runner, ES modules, no console.log” in every prompt.

    😊 THE SOLUTION

    Write it once as custom instructions, and save repeat tasks as prompt files.

    • Repeating house rules✓ .github/copilot-instructions.md
    • Rules for one folder✓ .instructions.md with applyTo
    • The same task every week✓ .prompt.md run with /name
    🛠️ Solved with: Instructions and prompt files

    Start with a question

    Why do I have to tell Copilot 'we use ES modules and the Node test runner' every single time?

    You join the contoso-shop team. On day one you ask Copilot for a test, and it writes Jest with require(). The team uses the Node test runner and ES modules. So you correct it. Next chat, same thing. Next developer, same thing.

    A new colleague would read the team’s README once and remember. Copilot doesn’t remember between chats, but it does read a file you give it. Put the house rules in .github/copilot-instructions.md and Copilot adds them to every request in that repo. Save the tasks you repeat as prompt files, and the whole team runs the same prompt with one slash command.

    Explain it like I’m 10

    Visual: Custom instructions in motion

    Watch which instruction files ride along with a request, how applyTo picks the right ones, and how a prompt file runs with one slash command.

    ▶ Explainer video See it in motion 8 steps · 1 min 33 sec

    An animation in the contoso-shop repository. Asked for a test with no instructions, Copilot writes Jest with require. A .github/copilot-instructions.md file is added and its rules join the next request, so the test uses the Node test runner. A path-specific tests.instructions.md with applyTo tests/**/*.js joins only when a test file is involved and stays out when src/discount.js is edited. A prompt file runs with /new-endpoint and fills its input variable. The answer lists the files it used, and the same repository instructions are read by Copilot Chat, the coding agent and code review. Instructions steer the model, so review and tests still decide.
    Read the video script
    1. Copilot guesses your conventionsYou ask Copilot for a test in contoso-shop. It doesn't know your team uses the Node test runner, so it writes Jest with require. Wrong for this repo.
    2. Write the rules down onceSo you write the house rules once, in dot github, copilot instructions dot md. Node 22, ES modules, tests with node dash dash test.
    3. The rules join every requestAsk again. This time the repository file rides along with your request, and the test uses node test and ES imports.
    4. Rules for some files onlyTest rules only matter for test files. Put them in a path-specific file with applyTo. You're working in tests slash cart dot test dot js, the glob matches, so it joins too.
    5. No match, no extra rulesNow you edit source discount dot js. The glob doesn't match, so the test rules stay out. Only the repository rules go in.
    6. A prompt the team reusesFor tasks you repeat, save a prompt file. Type slash new endpoint, resource equals orders, and the input variable becomes orders. Everyone sends the same request.
    7. Check what was usedThe answer lists the files it used, so you can check your rules applied. And the same repository file is read by Copilot Chat, the coding agent and code review.
    8. Steer, then verifyRemember, instructions steer the model, they don't enforce anything. Keep them short and clear, and let review and tests have the final word.

    The technical explanation

    Copilot only knows what’s in the prompt. Custom instructions and prompt files are two ways to put the same good context into the prompt every time, without typing it.

    The instruction files

    FileWhereWhen it appliesWho reads it
    copilot-instructions.md.github/Every request in the repositoryCopilot Chat, Copilot coding agent, Copilot code review
    *.instructions.md.github/instructions/Only when the files involved match its applyTo globChat and agents in supported editors, coding agent, code review
    AGENTS.mdRepo root (or a folder)Agent work in that part of the repoAgents, including the coding agent
    Personal and organization instructionsYour GitHub settings, or set by the orgYour requests, or the org’sCopilot Chat on github.com and supported clients

    A repository file for contoso-shop might look like this:

    # Copilot instructions for contoso-shop
    - Node.js 22, ES modules, no CommonJS.
    - Tests use the Node test runner: node --test.
    - Never log secrets; read config from environment variables.

    Keep it short and true for the whole repo. Rules that only matter for some files go in a path-specific file:

    ---
    applyTo: "tests/**/*.js"
    ---
    Arrange, act, assert. One behaviour per test.
    Name each test after the behaviour it checks.

    Save that as .github/instructions/tests.instructions.md. When you ask Copilot to change tests/cart.test.js, both files go into the prompt. When you change src/discount.js, only the repo-wide file does.

    Did it work?

    In Copilot Chat, the answer’s references list shows the instruction files that were used. If yours isn’t there, check the folder and file name, check that instruction files are turned on in your editor’s Copilot settings, and check that the applyTo glob really matches.

    Prompt files: reusable prompts

    A prompt file is a saved task. It lives in .github/prompts/ and ends in .prompt.md. The front matter is optional and can set:

    FieldWhat it does
    mode (or agent)Which chat mode or custom agent runs it, for example agent
    descriptionThe text you see when you pick the command
    toolsWhich tools the prompt may use
    modelA model to use, if your organization allows it
    ---
    mode: agent
    description: Add a REST endpoint with validation and tests
    ---
    Create a new endpoint for ${input:resource}.
    Validate input, return 400 on bad data, and add tests.

    Save it as .github/prompts/new-endpoint.prompt.md and type /new-endpoint resource=orders in Chat. ${input:resource} becomes orders. Because the file is in the repo, the prompt gets reviewed in pull requests and improves over time, and every developer gets a consistent response shape.

    Custom agents, briefly

    If you keep asking Copilot to play the same role, make a custom agent: .github/agents/test-writer.agent.md with a name, a description, a short list of tools and its own instructions. In the CLI you can keep personal agents in ~/.copilot/agents/ and run one with --agent=test-writer or pick it with /agent.

    1. 1 You type

      /new-endpoint resource=orders

    2. 2 Prompt file

      new-endpoint.prompt.md expands with orders filled in.

    3. 3 Repo rules

      .github/copilot-instructions.md is added.

    4. 4 Path rules

      tests.instructions.md joins only when tests/ files are involved.

    5. 5 Answer

      The references list shows which files were used.

    What goes into a chat request in contoso-shop
    Architect level Instructions steer; they don't enforce

    Instructions are text added to the prompt. The model weighs them with everything else, so a long, contradictory file works worse than ten clear lines. Write rules as short statements, avoid “always try to” phrasing, and don’t paste whole style guides. If a rule must never break (no console.log of tokens, no new dependencies without approval), back it with a linter rule, a test or a branch protection check. Copilot code review reading your instructions is useful, but it leaves comments only, and a person still decides.

    Real-world business scenario

    Online retail

    Contoso (fictional)

    The problem
    Twelve developers on contoso-shop got Copilot answers in three test frameworks and two module styles, and new endpoints all looked different. Reviews kept catching the same style issues.
    What they used
    A ten-line .github/copilot-instructions.md, a tests.instructions.md with applyTo for tests/, and a new-endpoint.prompt.md that runs in agent mode.
    Why that choice
    The rules ride along with every chat, coding agent task and Copilot code review in the repo, and the prompt file gives everyone the same starting request.
    The result
    Generated tests now use the Node test runner by default, new endpoints follow one pattern, and reviewers spend their time on logic instead of style.

    When to use it and when not to

    ✓ Use it when…

    • Rules that are true for the whole repository: language version, test runner, security basics.
    • Rules that only apply to some folders or file types, using applyTo.
    • Tasks your team repeats, saved as prompt files so the request is the same every time.

    ✕ Think twice when…

    • Secrets or private data. Instruction and prompt files live in the repo and go into prompts.
    • Rules that must never break. Use linters, tests and branch protection, and let instructions remind.
    • A huge style guide pasted in full. Short, clear rules work better.

    ↔ Alternatives to consider

    • Custom agents (.agent.md) when you want a named role with its own tools.
    • Copilot Spaces when the team needs shared documents and issues as context, not rules.
    Ready for more?The full lesson adds the technical explanation, when to use it, interview questions and revision notes.

    Test yourself with exercises

    5 original practice questions in the GH-300 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.

    Question 1

    Question 1 of 5

    A team wants Copilot Chat, Copilot coding agent, and Copilot code review to follow the same coding conventions in every request made in a repository. The solution must require no action from individual developers. What should the team create?

    Question 2

    Question 2 of 5

    A repository contains rules that apply only to test files in the tests folder. Developers report that Copilot applies these rules when it edits application code. You need the rules to apply only to test files. What should you do?

    Question 3

    Question 3 of 5

    A developer saves the following file as .github/prompts/new-endpoint.prompt.md in a repository that is open in Visual Studio Code: front matter that sets mode to agent and description to "Add a REST endpoint", followed by the text "Create a new endpoint for ${input:resource} and add tests."

    How does a developer run this prompt for an orders resource in Copilot Chat?

    Question 4

    Question 4 of 5 · Select 2

    Which TWO settings can you define in the front matter of a Copilot prompt file?

    Question 5

    Question 5 of 5

    A team lead wants every developer to send the same well-structured request when they ask Copilot Chat to scaffold a new service, so that the responses are consistent. The request should run only when a developer asks for it. What should the team lead create?

    Interview preparation

    Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.

    Beginner What's the difference between custom instructions and a prompt file?

    Model answer

    Custom instructions are always on. Copilot adds them to every relevant request without me asking, so they're for house rules like "we use ES modules". A prompt file only runs when I call it with /name. It's a saved task, like "add a REST endpoint with validation and tests".

    Interviewer follows up

    Where do they live?

    You

    Repository instructions in .github/copilot-instructions.md, path-specific ones in .github/instructions/ with an applyTo glob, and prompt files in .github/prompts/ as .prompt.md files.

    Intermediate Your test rules keep showing up when Copilot edits production code. How would you fix that?

    Model answer

    I'd move them out of copilot-instructions.md into a path-specific file, say .github/instructions/tests.instructions.md, with applyTo set to "tests/**/*.js". Then they only ride along when the work touches test files.

    Experienced developer How do you check that Copilot actually used your instructions?

    Model answer

    The chat response lists its references, and the instructions file shows up there when it was applied. If it's missing, I check the file name and folder, that the setting for instruction files is on in my editor, and that the applyTo glob really matches the file I'm working on.

    Interviewer follows up

    Can instructions guarantee Copilot follows a rule?

    You

    No. They're added to the prompt, so they steer the model, but the output still needs review. For hard rules I add a linter or a test that fails the build.

    Scenario Five developers write the same "new endpoint" prompt five different ways and get five different styles. What do you do?

    Model answer

    Write one prompt file, .github/prompts/new-endpoint.prompt.md, with agent mode in the front matter and an ${input:resource} variable. Commit it, and everyone types /new-endpoint resource=orders. Same request, same shape of result, and the prompt gets reviewed like code.

    Architecture & design How would you organise instructions in a large monorepo?

    Model answer

    Keep copilot-instructions.md short and true for the whole repo: language version, test runner, security rules. Then add one .instructions.md per area with its own applyTo, like the API, the web front end and the tests. Prompt files cover repeated tasks, and a custom agent covers a role such as a test writer with limited tools. Everything is in .github, so changes go through pull requests.

    Quick revision

    Key points

    • .github/copilot-instructions.md holds repository-wide rules. Copilot Chat, the coding agent and code review read it.
    • Path-specific rules go in .github/instructions/*.instructions.md with an applyTo glob in front matter.
    • Agents also read AGENTS.md. Personal and organization instructions can exist too.
    • Prompt files are .github/prompts/<name>.prompt.md and run with /name in chat.
    • Prompt file front matter can set the mode or agent, a description, tools and the model. ${input:name} adds variables.
    • Custom agents live in .github/agents/*.agent.md (repo) or ~/.copilot/agents/ (CLI, personal).

    Important terminology

    Repository custom instructions
    A Markdown file at .github/copilot-instructions.md whose rules Copilot adds to chat, coding agent and code review requests in that repository.
    Path-specific instructions
    Files in .github/instructions/ ending in .instructions.md, with an applyTo glob in front matter so the rules only apply to matching files.
    applyTo
    The front matter field in an .instructions.md file that holds a glob such as "tests/**/*.js" to say which files the rules cover.
    AGENTS.md
    An instructions file that agents, including the Copilot coding agent, read for project rules.
    Prompt file
    A reusable prompt saved as .github/prompts/<name>.prompt.md and run in Copilot Chat by typing /name.
    Input variable
    A placeholder such as ${input:resource} in a prompt file that Copilot fills from what you type after the command.
    Custom agent
    A named persona with its own instructions and tools, defined in .github/agents/<name>.agent.md (or ~/.copilot/agents/ for the CLI).

    Common mistakes

    • Putting every rule in copilot-instructions.md so test-only rules apply to all code.
    • Treating instructions as a guarantee. They steer the model; reviews, linters and tests still enforce the rule.
    • Saving a prompt file outside .github/prompts or without the .prompt.md ending, then wondering why /name doesn't appear.

    Exam tips

    • "Rules for the whole repository, used by chat, coding agent and code review" = .github/copilot-instructions.md.
    • "Rules only for some files" = .instructions.md with applyTo.
    • "Reuse the same prompt for consistent responses" = prompt file run with /name.

    Five quick revision questions

    1. 1.Which file holds repository-wide custom instructions?Show

      .github/copilot-instructions.md.

    2. 2.Which front matter field limits an .instructions.md file to certain paths?Show

      applyTo, with a glob.

    3. 3.How do you run .github/prompts/new-endpoint.prompt.md in chat?Show

      Type /new-endpoint.

    4. 4.How do you add a variable to a prompt file?Show

      With ${input:name}, for example ${input:resource}.

    5. 5.Does Copilot code review read repository custom instructions?Show

      Yes, it uses them as the team's review standards.

    Official references

    Finished this lesson? Tick it off. Your progress is saved in this browser.

    Next up: Copilot Code Review on Pull Requests

    Studying with a friend? Send them this lesson

    It's free and needs no sign-up. Their progress saves in their own browser.

    Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges. Play ❯

    Install MSDEVBUILD Azure

    Free · no account · works offline

    Save the whole course for offline ›

    Hi, I’m your Nimbus

    Your study buddy. Pick what we do next.

    MSDEVBUILD · Multi-Stack Dev Build

    Sign in to MSDEVBUILD

    One account for Azure certifications and the blog: sign in here and you are signed in on both. Your XP, streak, practice deck and certificate stay in sync on every device. Optional: everything works without an account.