How to create reusable prompt files on GitHub Copilot
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
Step-by-Step Instructions
Create a .copilot directory in your project
.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.Create your first prompt template file
.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 specificationReference prompt files in Copilot Chat
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.Create context-specific prompt collections
.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.Set up project-wide configuration file
.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.
Create snippet shortcuts with slash commands
"copilot-api-doc": {
"prefix": "//apidoc",
"body": [
"@workspace Apply .copilot/api-documentation.md to: $1"
],
"description": "Apply API documentation prompt"
}Version control your prompt files
.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.Test and refine your prompt templates
.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.Common Issues & 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.