Overview
Give GitHub Copilot in VS Code custom instructions to write a failing test, run it, fix the code and rerun, while you approve or skip each terminal command it wants to run.
Problem or Objective
- Which agents write or run tests against an application?
- Which agents turn an issue report into a fix?
More in Coding and Code Review
AI Agents and Models
Tools and Integrations
- Tools
- GitHub Copilot · Visual Studio Code
- Prerequisites
- Visual Studio Code with GitHub Copilot, a project with a working test command, and a Git branch for the fix. Chat and agent work use GitHub AI credits from your plan.
How It Works
Create a branch for the fix. Add custom instructions to the project that describe the loop: reproduce the bug with a failing test first, run only that test, read the failure, change the code, rerun, add extra diagnostic output if it still fails, and stop after a set number of attempts with a summary. Open Chat in VS Code with an agent session, describe the bug and the test command, and let Copilot work. When an approval prompt appears for a terminal command, read the command and what it acts on, then choose Allow Once or Skip; skip anything that installs packages, deletes files or reaches the network unless you expected it. When the test passes, read the diff, remove leftover debug output, run the full test suite yourself and commit on the branch.
Implementation Workflow
Steps assembled from the agents, tools and prompt of this entry. Adapt them to your own setup.
- Choose the agentSet up GitHub Copilot.
- Connect the toolsConnect the tools this workflow relies on: GitHub Copilot, Visual Studio Code.
- Check the prerequisitesVisual Studio Code with GitHub Copilot, a project with a working test command, and a Git branch for the fix. Chat and agent work use GitHub AI credits from your plan.
- Gather your detailsCollect what the prompt asks for: The bug, Where the test goes, Command for one test, Attempt limit.
- Run the starter promptPaste the starter prompt below into GitHub Copilot and adapt it to your case.
- Check against the documentationCompare what you get with the documentation at code.visualstudio.com before you rely on it.
Practical Starter Prompt: Fix this bug test-first
Fill the fields to adapt the prompt. Empty fields stay as visible [placeholders].
Fix this bug: [The bug]. First write a test in [Where the test goes] that fails because of the bug, and run only that test with [Command for one test]. Read the failure, change the code, and rerun. If it still fails, add temporary diagnostic output and rerun. Stop after [Attempt limit] attempts and summarise what you tried. Wait for my approval before any command other than the test command, and do not commit, push or install packages.Approve terminal commands one at a time with Allow Once and skip anything you did not expect. When the test passes, read the diff, remove debug output, run the full suite yourself and commit on your branch.
Expected Results and Benefits
This is a suggested workflow, not a reported result. The points below are what the cited documentation says the tools can do.
This is a suggested workflow, not a reported outcome. The VS Code documentation says custom instructions tailor Copilot to a project, that tool approval decides whether a call runs without your confirmation, and that at an approval prompt you review the command and choose Allow Once or Skip. Whether a prompt appears depends on your permission level and saved approvals. No cited page describes how many rounds a fix takes; the attempt limit in the instructions keeps that bounded.
Limitations and Considerations
Saved approvals and higher permission levels can let commands run without a prompt, so check your approval settings before starting if you want to see every command. Stopping a request does not undo edits or commands that already ran, so work on a branch. A passing test only proves what the test checks: read the diff and run the whole suite. Chat and agent work use GitHub AI credits from your plan. Results depend on your setup and were not independently reproduced by Top 200 Repos.
Sources
- Use tools with agents (opens in a new tab)
Project documentation · code.visualstudio.com · Undated · Source checked 27 Nov 2026, 13:25 UTC
What this source supports
- Tool approval determines whether a specific call can run without your confirmation.
- If an approval prompt appears, review the tool's inputs and the command, file, or destination it will act on.
- Choose Allow Once to approve that call, or Skip to decline it.
- Your permission level, runtime decisions, and saved approvals affect whether a call needs review.
- Use chat in VS Code (opens in a new tab)
Project documentation · code.visualstudio.com · Undated · Source checked 27 Nov 2026, 13:24 UTC
What this source supports
- tailor the AI's behavior to your project by adding custom instructions , creating reusable prompt files , or building custom agents for specialized workflows.
- Stopping a request doesn't undo file edits, terminal commands, or other actions that already completed.
- GitHub Copilot · Your AI coding agent · GitHub · GitHub (opens in a new tab)
Project documentation · github.com · Undated · Source checked 25 Nov 2026, 11:59 UTC
What this source supports
- You use credits when you chat with Copilot and work with agents.