Intermediate
How to create reusable prompt files on GitHub Copilot
Quick Answer
Create reusable prompt files by saving custom instructions in .txt or .md files within your project's .copilot folder or as GitHub Copilot snippets. These files can contain context, coding patterns, and specific instructions that Copilot can reference across multiple sessions.
Prerequisites
- GitHub Copilot subscription
- Visual Studio Code with GitHub Copilot extension
- Basic understanding of file management
- Familiarity with GitHub Copilot Chat
1
Create a .copilot directory in your project
Navigate to your project root and create a new folder named
.copilot. This directory will house all your reusable prompt files and configurations. Right-click in your project explorer in VS Code and select New Folder, then name it .copilot.Tip
The .copilot folder should be at the same level as your main project files for optimal recognition.
2
Create your first prompt template file
Inside the
.copilot directory, create a new file with a descriptive name like api-documentation.md or code-review-checklist.txt. Add your reusable prompt content including context, specific instructions, and examples. Use clear headings and structured formatting:# API Documentation Prompt
## Context
You are helping document REST API endpoints
## Instructions
- Include parameter descriptions
- Add example requests/responses
- Follow OpenAPI specificationTip
Use Markdown formatting for better readability and organization of your prompt templates.
3
Reference prompt files in Copilot Chat
Open GitHub Copilot Chat by pressing
Ctrl+Shift+I (or Cmd+Shift+I on Mac). Reference your prompt file using the @workspace command followed by your instruction: @workspace Use the prompt from .copilot/api-documentation.md to document this function. Copilot will read and apply the instructions from your saved prompt file.Tip
You can reference multiple prompt files in a single chat session for complex tasks.
4
Create context-specific prompt collections
Organize prompts by creating subdirectories within
.copilot for different purposes: .copilot/testing/, .copilot/documentation/, .copilot/refactoring/. Each folder can contain specialized prompt files relevant to that domain. For example, create .copilot/testing/unit-test-template.md with specific testing frameworks and patterns.Tip
Keep related prompts together to make them easier to find and maintain.
5
Set up project-wide configuration file
Create a
This configuration helps Copilot understand your project structure and preferred prompt patterns.
.copilot/config.json file to define default behaviors and prompt preferences:{
"defaultPrompts": {
"codeReview": ".copilot/code-review.md",
"testing": ".copilot/testing/unit-tests.md"
},
"contextFiles": [".copilot/project-context.md"]
}This configuration helps Copilot understand your project structure and preferred prompt patterns.
Tip
Update the config file whenever you add new frequently-used prompt templates.
6
Create snippet shortcuts with slash commands
In VS Code, go to File > Preferences > Configure User Snippets and select your language. Create custom snippets that reference your prompt files:
"copilot-api-doc": {
"prefix": "//apidoc",
"body": [
"@workspace Apply .copilot/api-documentation.md to: $1"
],
"description": "Apply API documentation prompt"
}Tip
Use consistent naming conventions for your snippet prefixes to make them memorable.
7
Version control your prompt files
Add your
.copilot directory to your Git repository by committing it with your project files. Create a .copilot/README.md file documenting each prompt file's purpose and usage examples. This allows team members to use the same prompt templates and maintains consistency across the project.Tip
Consider creating a team-wide prompt library repository that can be referenced across multiple projects.
8
Test and refine your prompt templates
Regularly test your prompt files with different code scenarios and refine them based on Copilot's responses. Keep a
.copilot/changelog.md to track improvements and modifications. Use the Copilot Chat history to analyze which prompts produce the best results and iterate on less effective ones.Tip
Ask team members to provide feedback on prompt effectiveness to continuously improve your templates.
Troubleshooting
Copilot doesn't recognize my prompt files
Ensure the
.copilot folder is in your project root and files have proper extensions like .md or .txt. Reload VS Code window with Ctrl+Shift+P > Developer: Reload Window.Prompt files are too long and Copilot ignores parts of them
Break large prompts into smaller, focused files. Keep individual prompt files under 500 words and use clear sections with headings. Reference multiple smaller files instead of one large file.
@workspace command doesn't find my prompt files
Check that your workspace includes the project root directory. Open the folder containing
.copilot as your VS Code workspace, not a subdirectory. Verify file paths are relative to the workspace root.Team members can't access shared prompt files
Ensure the
.copilot directory is committed to version control and not listed in .gitignore. Have team members pull the latest changes and reload their VS Code workspace.Ready to get started with GitHub Copilot?
Put this tutorial into practice. Visit GitHub Copilot and follow the steps above.
Visit GitHub Copilot →