How to Write Good Copilot Instructions and Context
Copilot instructions explained with repository rules, focused task prompts, selected files and test criteria for a fictional Node.js service.
Learn the concept, work through an example, and check the result.
Core idea
The right context narrows the proposal.
Test → inspect
Decide → commit
The direct answer
Give Copilot the context needed for a reviewable answer.
Copilot instructions should separate stable repository conventions from the details of one requested change.
A useful coding request states the goal, relevant files, constraints and acceptance evidence. Repository instructions can add stable conventions, while a task prompt names the particular change. Neither replaces developer review. GitHub documents the current mechanism for repository instructions; check its scope and precedence for your environment.
Course pricing follows this introduction. The sample below uses a fictional Node.js service and contains no secrets or private data.
Course access
Choose your next step in GitHub Copilot.
Review the current course options and access details here.
Heycademy Courses · Coming Soon
GitHub Copilot & AI Coding Productivity
We’re preparing an interactive learning experience with practical exercises, skill assessments and personalized learning to help you build confidence and master new skills.
We’re putting the finishing touches on this course. Please check back for updates.
Topic in practice
Copilot instructions in a real decision.
A task prompt names the function, allowed files, rejected inputs and tests. Repository guidance should state enduring rules such as dependency policy.
As you work through the case, identify the next action, the evidence required and what remains uncertain. The GitHub documentation provides background for checking the decision.
Two layers
Separate stable rules from a task request.
| Layer | Example | Review |
|---|---|---|
| Repository guidance | Use Node test runner; do not add dependencies without approval. | Confirm rules still match repository. |
| Task prompt | Reject invalid quantities in orders.js. | Check acceptance criteria. |
| Selected context | orders.js and orders.test.js. | Remove irrelevant or sensitive files. |
Longer prompts are not automatically better. Give the smallest context that explains the change, including behavior that must remain stable.
Weak request
“Make this better” leaves too many choices.
A weak request asks for better validation with no file, input contract or test requirement. The assistant may change the API, add a library or guess at error handling. A reviewable request names the function, permitted inputs, error text and files allowed to change.
Keep building this skill
Turn the example into a skill you can use.
Return to the course options whenever you are ready.
Improved request
State the contract and test evidence.
Task: In orders.js, keep export quantity(value). Accept trimmed positive whole-number strings up to 99. Throw Invalid quantity for zero, decimals, signs and values over 99. Do not add dependencies. Edit orders.js and orders.test.js only. Add tests for 1, 99, 0, 100, 3.5 and whitespace. Return a short summary of assumptions.The wording limits scope but does not prove the generated code is correct. Run the tests and inspect the diff yourself.
Prompt iteration
Repair an assumption without moving the goalposts.
Suppose the proposal accepts “01”. The contract said positive whole-number strings but did not specify leading zeros. Decide the product rule and update the prompt and tests. Do not quietly alter tests to match whatever code was produced. Keep a short note of the chosen rule so a reviewer can reproduce the decision.
Context hygiene
Share only what the task needs.
Remove credentials, personal data and unrelated files. Use placeholder values and approved development fixtures. A repository instruction should not contain a live secret. For current feature behavior, use GitHub’s instructions documentation and your organization’s policies.
Practice prompt
Write a request to add a maximum of 99 while preserving the export, dependency policy and existing error behavior. Include boundary tests.
Context repair
Resolve ambiguity before another prompt.
A repository instruction says “avoid new dependencies,” while a task prompt says “use the validation package.” That conflict should be resolved by a developer or reviewer. Check whether the package is already installed and approved. If it is not, ask the appropriate owner whether a dependency is permitted. Do not ask the assistant to choose which instruction matters more without giving it the repository decision context.
A useful follow-up prompt records the resolved constraint: “Use existing built-in validation only; do not add packages.” It also names the test file and exact edge cases. Keep stable repository rules short enough to review when they change. Outdated instructions can make every later request less reliable, so include a periodic owner check in normal repository maintenance.
FAQ
Questions about this skill.
Should repository instructions contain every task detail?
No. Keep stable conventions there and task-specific criteria in the prompt.
Do better prompts eliminate review?
No. Tests and human review still decide whether to accept a change.
Can I paste customer data for context?
Follow the organization’s data policy and use safe fixtures where possible.
Continue with the course
Build reliable AI-assisted coding skills.
Review the course options and choose your next learning step.