Prevent Copilot read .env* file #159254
Replies: 13 comments 11 replies
This comment was marked as spam.
This comment was marked as spam.
-
|
@nhatchimai111 check this discussion thread https://github.com/orgs/community/discussions/13334 |
Beta Was this translation helpful? Give feedback.
-
|
Hi @nhatchimai111, You're on the right track with trying to exclude Steps to Prevent Copilot from Accessing
|
Beta Was this translation helpful? Give feedback.
-
I get an "Unknown configuration setting" warning. Also tried: VSCode: |
Beta Was this translation helpful? Give feedback.
-
π Preventing Copilot from Reading
|
| File | Configuration | Status/Note |
|---|---|---|
.copilot-ignore |
Place this file in your project root: .env .env.* |
This file is intended for suggestions control, but its effectiveness can be limited, and it may not be supported on all Copilot tiers. |
settings.json |
Use the copilot.exclude setting: "copilot.exclude": ["**/.env", "**/.env.*"] |
This setting is often reported by users as generating an "Unknown configuration setting" warning and may not be officially supported by the current Copilot extension version. |
Conclusion
If Copilot is ignoring your local settings and your primary goal is to prevent the exposure of sensitive environment variables, you must either:
- Upgrade your Copilot subscription to Business/Enterprise and use the official Content Exclusion feature.
- Move sensitive variables into a secure vault or secrets manager (like Azure Key Vault, AWS Secrets Manager, or GitHub Secrets) instead of keeping them in unencrypted
.envfiles that must live in your project structure.
Beta Was this translation helpful? Give feedback.
-
|
I am having this issue too. I used to add "files.associations": {
".env*": "dotenv"
},
"github.copilot.enable": {
"dotenv": false
}in my settings.json file, as recommended by this Jan 2024 StackOverflow Q&A, but it seems that is no longer supported? I noticed the Copilot icon does NOT have a slash through it on the bottom taskbar like it did a year ago. I am using the free version of Copilot, but -- assuming I interpreted "Copilot is now generally available for all Copilot Business and Copilot Enterprise users" (see 2024-11-12 github blog and github docs accessed on 2025-11-08) correctly -- it makes no sense Github would be excluding this important privacy feature to paying users only. Is there a known, documented, and please NOT AI-generated recommendation to solve this issue?? |
Beta Was this translation helpful? Give feedback.
-
|
hello, Your .env file is likely still open in a VSCode tab. You must close the file. Copilot reads your open tabs for context, regardless of your settings. The settings only prevent it from accessing closed files in your workspace. How to Fix It { Reload VSCode: Press Ctrl+Shift+P and run "Developer: Reload Window". |
Beta Was this translation helpful? Give feedback.
-
|
Root Cause: Local settings (.gitignore, .copilot-ignore, settings.json) are ineffective for preventing Copilot from accessing .env file content. Copilot reads all open tabs for context regardless of these exclusions. Official Solution: Content Exclusion feature requires Copilot Business or Enterprise subscription. Configured server-side on GitHub.com under Organization or Repository Settings using: "*":
Effect takes up to 30 minutes after configuration. Immediate Workarounds (No Subscription Upgrade): Key Point: Language-based disabling prevents completions within .env files but does not stop Copilot from using their content as context elsewhere. |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as low quality.
This comment was marked as low quality.
-
|
To prevent GitHub Copilot from reading your .env files, the most effective method depends on your subscription tier. While a .copilotignore file is a popular community request, its official support is currently limited. This is the only guaranteed way to prevent Copilot from accessing specific files. It must be configured by an administrator at the repository or organization level. How to set it up: Go to your repository Settings on GitHub.com. In the sidebar, under "Code & automation," click Copilot > Content exclusion. In the "Paths to exclude" box, enter the patterns:
|
Beta Was this translation helpful? Give feedback.
-
|
If Copilot is still reading your .env files even after configuration, it usually means the exclusions are not applied correctly or VS Code hasnβt reloaded them. Follow these steps carefully to fully block access:
If it STILL happens:
Final note: |
Beta Was this translation helpful? Give feedback.
-
|
Any update on May 2026??? So far what I understood is, and correct me if I'm wrong, that content exclusion is a paid feature and that If that is true, Github should be ashamed of themselves for not providing a simply scoping feature to files in client. Qwen has it, Claude, Codex etc... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Select Topic Area
Question
Copilot Feature Area
Copilot Agent Mode
Body
Configure Visual Studio Code to prevent Copilot from accessing and suggesting content from .env files.
Specifically:
Please provide the current structure of your .env files and VSCode workspace configuration for more targeted guidance.
For reference, consult:
I have update many configs on VSCode and my project. However Copilot still read .env files in my project
Beta Was this translation helpful? Give feedback.
All reactions