skip to content

How do you write a VS Code Copilot prompt file that runs as /write-tests, and what do its agent and tools fields do?

level: middleimportance: should knowfreq 7%

answer

  1. a saved prompt you invoke yourself
  2. .github/prompts and the .prompt.md extension
  3. name defaults to the file name
  4. listing tools makes agent the default
  5. paths resolve from the prompt file

basics

~10 s

Save .github/prompts/write-tests.prompt.md with optional YAML frontmatter and a Markdown body, then type /write-tests in chat. agent picks ask, agent, plan or a custom agent; tools limits which tools the prompt may use.

solid answer

~50 s

A prompt file is a Markdown file with the `.prompt.md` extension. Workspace ones live in `.github/prompts`, and user ones live in your profile. Its optional YAML frontmatter takes `description`, `name` (shown after `/`; it defaults to the file name), `argument-hint`, `agent`, `model` and `tools`. `agent` can be `ask`, `agent`, `plan` or a custom agent's name. By default the current agent is used, unless `tools` is set, in which case the default is `agent`. `tools` lists the tools or tool sets the prompt may use, and a missing tool is ignored. The body is the prompt itself, with Markdown links or `#file:` references resolved relative to the prompt file. You run it with `/write-tests` plus any extra text, with **Chat: Run Prompt**, or with the editor's play button. VS Code's current docs say Agent Host sessions don't load prompt files, which still work with the Local agent, and recommend migrating them to agent skills.

code

markdown · 13 lines
markdown
---
name: write-tests
description: 'Write unit tests for the selected code'
argument-hint: 'function or file to test'
agent: 'agent'
tools: ['search/codebase', 'edit', 'execute/runInTerminal']
---
Write unit tests for ${selection} with the test framework this project already uses.

Follow [our testing guide](../../docs/testing.md) and match the style of
#file:../../src/orders/order-service.test.ts

Run the new tests and fix any failure before you finish.

go deeper

for a junior

Recall where a prompt file lives (.github/prompts, a .prompt.md file) and that you run it yourself by typing / and its name.

for a middle

Explain the frontmatter: the name default, agent and its default when tools is set, model, the tools priority order, and paths resolved relative to the prompt file.

for a senior

Show judgment on which team requests deserve a shared prompt file, how to scope its tools tightly, and why its deprecation for Agent Host sessions affects the decision.

for a principal

Weigh the cost of maintaining a library of team prompts against migrating to agent skills now, given where the team's sessions run.

## What a prompt file is A **prompt file** is a saved chat request that you run on demand. VS Code's docs call them "also known as slash commands". The file holds a task's instructions, its context and how the task should be done, so a team writes a request like "write unit tests the way we do it" once and runs it by name. The key contrast is with **custom instructions**, which are applied to every request automatically. A prompt file runs only when someone invokes it. ## Where it lives and how it is named | Scope | Location | |---|---| | Workspace | `.github/prompts` folder | | User profile | Your VS Code profile's user data | - The file must end in `.prompt.md`. - The name after `/` comes from the `name` field, or from the file name when `name` is absent. - Ways to create one: **Chat: New Prompt File**, `/prompts` to open the **Configure Prompt Files** menu, or `/create-prompt`, which drafts a file from a description and asks whether to store it in the workspace or your profile. - In a monorepo opened at a subfolder, `chat.useCustomizationsInParentRepositories` (default `false`) lets VS Code find prompt files at the parent repository root. ## The frontmatter fields Every field is optional: | Field | What it does | Default | |---|---|---| | `description` | Short description shown with the prompt | none | | `name` | Name used after `/` | the file name | | `argument-hint` | Hint text in the chat input | none | | `agent` | `ask`, `agent`, `plan`, or a custom agent's name | the current agent, or `agent` when `tools` is set | | `model` | Language model for this prompt | the model picker's current model | | `tools` | Tools or tool sets the prompt may use; `<server name>/*` takes all of an MCP server's tools | the agent's tools | Two rules about tools are worth knowing: 1. **Priority.** The tools come from the prompt file's `tools` first, then from the custom agent the prompt references, then from the selected agent's defaults. 2. **Missing tools.** If a listed tool is not available when the prompt runs, it is ignored, and the prompt does not fail. ## The body The body is plain Markdown instructions. Inside it: - Reference files with Markdown links or `#file:`. Workspace paths are relative to the **prompt file**, not the workspace root. A `~` or `~/` path starts from your home folder. - Reference a tool with `#tool:<tool-name>`. - Use `${selection}` and input variables such as `${input:variableName}` to make the prompt reusable. - Link to instruction files rather than copying their rules into every prompt. ## Reading the example The file in the example, `.github/prompts/write-tests.prompt.md`, shows each part working: - `name: write-tests` makes it `/write-tests`. Without that line the file name would give the same command. - `agent: 'agent'` is spelled out for readers. Because `tools` is set, `agent` would be the default anyway. - `tools` lists a semantic search tool, the `edit` tool set and the terminal tool, so the prompt can find code, write the test file and run the tests. Because the list is set, it takes priority over the agent's default tools. - `${selection}` passes in whatever the developer selected, so one prompt works for any function. - The `../../` paths climb from `.github/prompts` to the repository root, because paths resolve from the prompt file. ## Running it 1. Type `/write-tests` in the Chat view and add any extra text, e.g. `/write-tests for the refund path`. 2. Or run **Chat: Run Prompt** from the Command Palette and choose the file. 3. Or open the file and press the play button in the editor title, which is the quickest way to test changes as you edit. `chat.promptFilesRecommendations` can suggest prompts when a new chat session starts. ## Status: check which sessions load it GitHub's documentation labels prompt files a public preview. VS Code's current docs go further. Prompt files are **deprecated for Agent Host sessions and are not loaded there**. They still work with the **Local agent**, which VS Code says will be removed in a future release, and the recommended path is migrating prompt files to **agent skills**. A prompt file therefore still works in a Local agent session, but a team that is standardising on one should plan its migration.

  • What happens if a Copilot prompt file's frontmatter lists tools but sets no agent?
    VS Code runs it with the `agent` role, because listing `tools` makes `agent` the default. With neither field set, the prompt runs with whatever agent is currently selected in the chat.
  • How does a prompt file's tools list interact with a custom agent it references?
    The prompt file's own `tools` win. Without them, the tools of the custom agent named in `agent` apply, and failing that the selected agent's default tools. A tool that is not available when the prompt runs is ignored.
  • How do you test a prompt file while you are still writing it?
    Open the `.prompt.md` file and press the play button in the editor title. You can run it in the current chat session or a new one, which makes it quick to edit and run again.

A prompt file is like a recipe card pinned in the team kitchen: nobody cooks from it until they take it down and use it, and when the card names its own pan, that pan beats the kitchen default.

  • Prompt files are applied to every chat request, like custom instructions.
  • A prompt file must declare a name field or it cannot run as a / command.
  • A missing tool in the tools list makes the prompt fail to run.
  • #file: paths in a prompt file resolve from the workspace root.
  • Prompt files load in every VS Code session target, including Agent Host sessions.