Sub topic 3
Reusable Prompt Files
What this chapter assumes
You have used an AI coding assistant in an editor or terminal and have typed the same request more than once. You can read Markdown and simple YAML frontmatter, and you know what a repository layout looks like. You have met the context window and persistent project instructions (such as an AGENTS.md file) in earlier chapters.
What a prompt file is
A prompt file is a Markdown file that stores a request you make often. You save it once, give it a name, and run it on demand. Many tools expose these files as slash commands. Typing the command loads the file's text into the conversation as if you had typed it yourself.
A prompt file is not a new kind of intelligence. It is saved text with a trigger. That has three consequences:
- It costs nothing until you invoke it. Persistent instructions are loaded in every session, but a prompt file enters the context window only when you call it.
- You decide when it runs. The model does not choose it. This makes behavior predictable.
- It is only as good as the text inside it. The agent reads the file the way it reads any message.
The file names, folder locations, and frontmatter fields differ between products. Some tools use a dedicated prompts folder, some use a commands folder, and some use a different file extension. Check your tool's documentation for the exact layout. The structure described here is the part that transfers.
How a prompt file reaches the model
The flow is short. You type a command, the tool finds the file, strips or reads the frontmatter, and sends the body to the model along with whatever persistent instructions are already loaded.
The frontmatter is mostly metadata for the tool. A typical field is a description, which the tool shows in command menus. Some tools also use frontmatter to set a model or allowed tools. The body is what the model actually reads.
A complete example
This prompt file reviews staged changes. It has a fixed task, numbered steps, a restriction, and an output format.
---
description: Review the staged changes for bugs and missing tests
---
Review the changes I have staged in Git.
1. List any likely bugs, with file and line references.
2. Point out public behavior that has no test.
3. Suggest the smallest fix for each finding.
Do not edit any files. Reply with a short Markdown list ordered by severity.Each part does a job:
| Part | Purpose |
|---|---|
| `description` | Helps you find the command in a menu. It does not instruct the model in most tools. |
| First sentence | States the task and the scope: the staged changes only. |
| Numbered steps | Fix the order of work and the depth of the review. |
| "Do not edit any files" | Sets a boundary on what the agent does. |
| Last sentence | Fixes the output shape so results are comparable across runs. |
What makes a prompt file worth saving
A request is a good candidate when you repeat it, and when you keep correcting the model's first attempt in the same way. Those corrections belong in the file.
A reusable prompt file usually answers four questions:
- What is the task? One task per file. If you write "review and then refactor and then update docs", you have three files.
- What should the agent look at? Name the scope, such as staged changes, a folder, or an issue.
- What does a finished answer look like? Give a format, a length limit, or an ordering rule.
- What must the agent not do? State the limits plainly.
Compare two versions of the same request.
Weak: "Look over my code and tell me what you think."
Stronger: "Review the staged changes. List likely bugs with file and line references, ordered by severity. Do not edit files."
The weak version leaves the scope, the criteria, and the output to chance. Different runs give different shapes of answer, and you cannot compare them.
Prompt files compared with persistent instructions
Persistent instructions describe the project: build commands, naming rules, where tests live. They apply to every task. Prompt files describe one task. They apply when you ask.
Put a rule in persistent instructions if it should hold all the time, such as "run the linter before finishing". Put it in a prompt file if it matters only for one workflow, such as "order review findings by severity". Moving task-specific text out of the always-loaded file keeps the instruction budget free for what every session needs.
A prompt file should not repeat what persistent instructions already say. Duplicates waste context and can drift apart. If the project rules change, you would then update two places.
Edge cases and common errors
The file assumes state the conversation does not have
The staged-changes example works only if the agent can see the Git state. It needs a way to run a command like git diff --staged. If your tool cannot run shell commands, or nothing is staged, the agent may guess or invent findings. Make the dependency explicit, for example: "Run git diff --staged to see the changes. If nothing is staged, say so and stop."
A prohibition is a request, not a lock
"Do not edit any files" asks the model to behave. It does not remove the ability to edit. A model can still misread the instruction, or a later message in the conversation can override it. If an edit would cause real harm, enforce the limit with tool permissions instead of wording. A later chapter covers this under tool scoping.
The prompt does too many things
A file with six goals gets six shallow results. Split it. You can still chain files by running them one after another.
The output format is vague
"Give a summary" produces anything from one line to a page. "Reply with a short Markdown list ordered by severity" gives a shape you can scan, paste into a pull request, or check by eye.
Stale references
A prompt file may name a path, a script, or a document. When that target moves, the prompt silently points at nothing. The agent may then search for something similar and pick the wrong file. Review prompt files when you restructure the repository.
Conflicts with persistent instructions
If the project rules say "always add tests" and your prompt file says "do not edit any files", the agent must pick one. Which one wins is not guaranteed. Remove the conflict instead of relying on the model's tie-breaking.
Command name collisions
Some tools load prompt files from both a user-level folder and a project folder. If two files share a name, one may shadow the other. Check your tool's precedence rules before you rely on a name.
Writing guidelines
- Use plain imperative sentences. "List the bugs" works better than "It would be great if bugs could be listed".
- Number steps when order matters. Use a plain paragraph when it does not.
- Keep the file short. A prompt file of a few lines is normal. If it grows to pages of rules, the content is probably a skill or a reference document.
- Name the file after the action, such as
review-stagedordraft-release-notes, so the command reads like a verb. - Write a
descriptionthat you would recognize in a menu six months from now.
Where prompt files stop being enough
Prompt files are manual. You must remember they exist and call them. They also carry no tool restrictions of their own in many products, and they have no standard place for supporting files such as scripts or long reference documents. When you need a specialist with a fixed tool set, or a capability the agent should discover and load by itself, the next mechanisms in this tutorial fit better. Making a prompt file accept input is the first step in that direction, and it is the topic of the next chapter.
Exercise
Your team keeps typing "Summarize this pull request for the release notes" and getting answers of different lengths and styles. You write a prompt file. Name two things to put in the body that fix the inconsistency, and say where you would put a rule like "always run the formatter before finishing".
Show answer
Fix the inconsistency by stating the output format (for example, one line per change in the past tense, grouped under headings) and the scope (which pull request or which commits to read). The formatter rule applies to every task, so it belongs in persistent project instructions, not in this prompt file.
Exercise
A prompt file says "Do not edit any files", yet an agent modified a file during a run. Why can this happen, and what is the more reliable fix?
Show answer
The sentence is an instruction the model may misread or that a later message may override. It does not remove the agent's ability to write. The reliable fix is to restrict the agent's tools or permissions so that writing is not allowed, which the tool scoping chapter covers.