Customization and Configuration - Step 2: Excluding Files/Directories
from AI Context (Copilot)
Learn how to control which parts of your project GitHub Copilot
considers for context. This helps maintain privacy, improve relevance,
and optimize performance by ensuring Copilot focuses on the code that
matters most.
Availability
Content exclusion features are available for:
-
Repository administrators and organization owners (for
configuration)
-
Users with "Maintain" role can view but not edit settings
-
Organizations with Copilot Business or Enterprise plans
Understanding Content Exclusion
When you exclude content from Copilot:
-
Code completion will not be available in excluded files
-
Excluded content won't inform suggestions in other files
-
Excluded files won't influence Copilot Chat responses
-
Excluded files won't be included in Copilot code reviews
Common reasons to exclude content:
-
Security: Prevent access to files with
secrets, API keys, or personal information (e.g.,
.env files)
-
Performance: Exclude large dependency folders
(like node_modules/) and build
outputs
-
Relevance: Focus context on your actual source
code for better suggestions
-
Compliance: Ensure sensitive or proprietary
code isn't included in AI context
Using .gitignore for Basic
Exclusions
GitHub Copilot automatically respects your project's
.gitignore file, making it the
simplest way to exclude common patterns:
# Standard exclusions for Copilot
# Dependencies
node_modules/
vendor/
bower_components/
# Build outputs
build/
dist/
out/
target/
# Environment and secrets
.env
.env.*
!.env.example
credentials.json
secrets/
*.pem
*.key
# Logs and temporary files
*.log
logs/
tmp/
temp/
# IDE and OS files
.vscode/
.idea/
*.swp
.DS_Store
Thumbs.db
IDE-Specific Exclusions
Different IDEs offer various ways to control Copilot's context:
VS Code
// settings.json
{
"github.copilot.enable": {
"*": true, // Enable for all languages
"plaintext": false, // Disable for plain text
"markdown": false // Disable for markdown
},
// Optional: Hide files from explorer (may affect context)
"files.exclude": {
"**/node_modules": true,
"**/dist": true
}
}
JetBrains IDEs
-
Use Project Structure settings to mark directories as "Excluded"
-
Configure Copilot plugin settings for language-specific exclusions
Visual Studio
-
Use Solution Explorer filters to exclude content
-
Configure Copilot extension settings per language/project
Best Practices
-
Start with a comprehensive
.gitignore file
-
Regularly review excluded patterns as your project evolves
-
Document your exclusion decisions for team reference
-
Test exclusions to ensure they're working as expected