How to create custom instructions file on GitHub Copilot
Create a .copilot-instructions.md file in your project root or workspace to provide custom context and coding preferences to GitHub Copilot. This file helps Copilot understand your project structure, coding standards, and specific requirements for better code suggestions.
Prerequisites
- GitHub Copilot subscription
- Visual Studio Code with GitHub Copilot extension
- Basic understanding of file system navigation
- Knowledge of your preferred programming languages and frameworks
Step-by-Step Instructions
Create the instructions file in your project root
.copilot-instructions.md. This file should be placed at the same level as your package.json, README.md, or other main project files. Right-click in the file explorer and select New File, then name it exactly .copilot-instructions.md.Define your project context and architecture
# Project Overview and describe your tech stack, main directories, and overall application purpose. Include information about your database schema, API structure, or any unique architectural patterns you're using.Specify coding standards and preferences
# Coding Standards section to define your preferred coding style, naming conventions, and formatting rules. Include details about indentation (tabs vs spaces), bracket placement, variable naming patterns (camelCase, snake_case), and any specific linting rules. Mention your preferred libraries or frameworks for common tasks.Configure language-specific instructions
# JavaScript Guidelines or # Python Standards. Specify preferred libraries, error handling patterns, async/await vs promises preferences, and any language-specific best practices. Include information about testing frameworks and documentation styles you prefer.Add security and performance guidelines
# Security & Performance section with specific requirements for data validation, authentication patterns, and performance considerations. Mention any security libraries you use, input sanitization requirements, and performance optimization strategies relevant to your project.Set up environment and dependency preferences
# Environment Setup section that describes your development environment, preferred package managers, and dependency management strategies. Include information about environment variables, configuration files, and any specific build tools or deployment processes.Test and refine your instructions
.copilot-instructions.md file and restart Visual Studio Code to ensure Copilot picks up the new instructions. Create a new file in your project and start coding to test if Copilot's suggestions align with your specified guidelines. Make adjustments to your instructions file based on the quality and relevance of suggestions.Common Issues & Troubleshooting
Copilot isn't following the custom instructions
Ensure your .copilot-instructions.md file is in the project root and restart VS Code. Check that the file is properly formatted with clear markdown headers and that your instructions are specific rather than vague.
Instructions file is too long and seems overwhelming
Keep your instructions concise and focus on the most important guidelines. Use bullet points and code examples rather than long paragraphs. Aim for 200-500 words total with clear sections.
Copilot suggestions don't match the specified coding style
Make your coding standards more explicit with concrete examples. Include both Do and Don't examples in code blocks to clearly demonstrate preferred patterns.
Multiple team members have different instruction preferences
Create a team-wide .copilot-instructions.md file that reflects your shared coding standards and commit it to your repository. Ensure all team members pull the latest version and restart their editors.