GitHub Copilot prompts

How to write GitHub Copilot prompts in VS Code

Start with the broad goal, list your requirements with the most important first, name the function or file you mean and show an example. Put rules you repeat into an instructions file and prompts you reuse into prompt files, so you stop retyping them.

Download for Mac

macOS 13+·Windows 10+·Free for 3 days, no card

Updated

Goal first

Goal first, then requirements

Copilot answers best when it knows the big picture before the details.

GitHub's guide says to start with the broad goal and then list the specific requirements. Put your most important requirements first.

Write each rule as a direct instruction. "Use two decimal places" works better than "Remember to always be careful with decimals". GitHub warns against meta-instructions of that second kind.

Do not say "this". Name the function, the file or the block of code you mean. Vague references leave Copilot guessing.

Examples

Show an example, and split the job

One small example removes a lot of guessing.

Give sample inputs and the outputs you expect, or a sample of the code style you want. GitHub also suggests writing the unit tests first, then asking for a function that satisfies them. A unit test is a small automatic check of one piece of code.

Break a large task into small steps and run them one at a time. Small steps are also easier for you to check.

Context

Control what Copilot can see

Copilot works from the context you give it, so manage that context on purpose.

Scrubbr writes in any text box, including the Copilot Chat box in VS Code. Say the task, and the prompt arrives with the facts already in it.

This tool

What is different in VS Code

VS Code lets you save your standing rules and your favourite prompts as files.

Habits common to every tool are on the hub. The files below are read only by VS Code.

Worked example

From "write tests for the invoice total" to a prompt that names the cases

Kofi runs Marrowbone Ledger, a small bookkeeping app for market traders. A rounding bug reached a customer last month, and nothing tests the invoice total.

In GitHub Copilot in VS Code

You say

optionwrite tests for the invoice total, hana explained the discount and tax rules in slack and ivy emailed the rounding thing, use whatever we test with

Scrubbr finds

  • Slack · #billing thread, Hana Marsh: "calculateInvoiceTotal has no tests"
  • Gmail · Ivy Grant (accountant), "Rounding rule for tax"
  • Knowledge base · How we test: Vitest, tests sit beside the file

Copilot · Prompt

Goal: Write unit tests for the function calculateInvoiceTotal. A rounding bug reached a customer last month, and the function has no tests today.

Facts: From Hana Marsh in Slack and Ivy Grant's email: the discount is applied before tax. Tax is 8.25%. Tax is rounded to the cent on each line, not on the final total. An empty invoice totals 0.00. We test with Vitest, and test files sit beside the file they test.

Steps: 1. Open the file that defines calculateInvoiceTotal and read it. Do not guess what it does. 2. List the cases first, then write one test for each. Case 1: one line, no discount, no tax; the total equals the line price. Case 2: two lines of $40.00, 10% discount, 8.25% tax; the total is 77.94. Case 3: three lines of $0.33 with 8.25% tax; the total is 1.08, because tax rounds on each line. Case 4: an empty invoice; the total is 0.00. Case 5: a 100% discount; the total is 0.00. 3. Run the tests.

Limits: Use Vitest. Put the tests in a new test file beside the function. Leave calculateInvoiceTotal as it is. Add no new packages. If a case in this prompt does not match what the code does, say so and stop. Do not change the case to fit.

Format: One test per case. Name each test in plain words, such as "applies the discount before tax". After the tests, three plain lines: which pass, which fail and why.

A great answer: All five cases are covered and named. Every failing test points to the rule it breaks. No source code changed. You show the test command and what it printed.

Demo data. The people, company and facts are invented.

Questions

GitHub Copilot questions

What are custom instructions in VS Code?

They are standing rules saved in a file, so you do not retype them. VS Code can discover copilot-instructions.md, AGENTS.md and CLAUDE.md in your project, and also files such as style.instructions.md under .github/instructions/.

What is a prompt file?

A saved prompt you can run again. An example is review.prompt.md under .github/prompts/, which you run from the Chat view.

How do I know Copilot used my instructions?

Test the new or edited file in a fresh chat. Where VS Code shows a References section on the response, it lists the instructions that were used.

Why does Copilot misread what I mean by "this"?

A vague word gives it nothing to hold on to. Name the function, the file or the block of code instead.

Should I keep one long chat going?

No. Start a new conversation for each new task, so earlier messages do not steer the next one.

Sources

Where these facts come from

Try Scrubbr free for 3 days

Download Scrubbr, connect your tools, and give your first prompt in two minutes.

Download for Mac

macOS 13+·Windows 10+·Free for 3 days, no card