Skip to content
Install Core free
ProductsCompare Core, Hub, Connect and MDM pricing
Solutions
Docs
ResearchPricing
CompareCompare all AI data-leak tools
TrustBenchmarks
Start 30-day free trial

Shadow Hub for your business

Tell us about your team and we'll help you get started.

We use these details only to reply to your enquiry. No newsletter, no cookies, no trackers.

Do AI coding agents keep your .env files out of the prompt? A source-code and documentation audit

Source-code audit of AI coding agents: what controls stop .env files and secrets from reaching models, and which tools protect you by default.

Shadow Research Team12 min read

Most AI coding agents do not block every path to your .env file by default. Where protections exist, they usually cover the agent’s built-in file tools, indexing, or search. When an agent runs cat .env in a shell, or a script that opens your secrets file, most of those protections do not apply. This audit examines nine popular agents, documents what each actually does, and identifies a second leak path: agent configuration folders that can persist secrets in plaintext.

Summary: what protects your secrets?

ToolVersion/DateDefault .env protectionIgnore mechanismCovers agent tool reads/shell?Evidence
ContinueCommit 5522c6f (Jul 2026, main as of Nov 9)Yes, for built-in file toolsDEFAULT_SECURITY_IGNORE_FILETYPES includes *.env, *.env.*, .env*; read/edit tools throw an errorFile tools yes; terminal commands (cat .env) and scripts not checkedSource
Codex CLICommit 8703d32, Nov 2026No; default :workspace profile can read the workspaceCustom permission profile: "**/*.env" = "deny" under :workspace_rootsYes when configured: the OS sandbox enforces deny-read for shell commandsDocs
Gemini CLICommit 62bab5b, Nov 2026Partly: **/.env excluded from multi-file readsSYSTEM_FILE_EXCLUDES; .gitignore and .geminiignore respected by the read toolFile tools partly; shell commands unblockedSource
ClineCommit 5413dc1, Nov 2026No, requires .clineignore.clineignore blocks file access and validates shell commandsYes for recognized commands if configuredSource
AiderCommit 5dc9490 (May 2026, main as of Nov 9)Partly: gitignored files can’t be added to chatOffers to gitignore .env; --add-gitignore-files off by default; .aiderignore optionalContents sent only for files you add; /run output only if you share itSource
CursorDocs, Nov 2026.env* on default ignore list.cursorignore blocks Agent, Tab and @-mentionsNo: docs say Agent’s terminal and MCP tools can’t be blockedDocs
Claude CodeDocs, Nov 2026No; requires deny ruleRead(./.env) deny in settings.json; .claudeignore has no effectRecognized commands only; scripts unblockedDocs
GitHub CopilotDocs, Nov 2026No; requires content exclusion (Business/Enterprise)Repository/org settings with fnmatch patternsCopilot tools yes; identifiable paths in commands checked; indirect access may be missedDocs
Windsurf / Devin DesktopDocs, Nov 2026Hidden and gitignored paths skipped by indexing.devinignore (legacy .codeiumignore / .windsurfignore still read).devinignore blocks agent view/edit; terminal not documentedDocs

The two paths secrets can leak

Path 1: Agent reads .env into the prompt

When an AI coding agent builds context for a model request, it may read files from your workspace. If .env is not excluded, its contents become part of the prompt. This happens in several ways:

  1. Explicit file read tools: The agent’s Read File tool opens .env to answer a question or debug an issue
  2. Shell commands: The agent runs cat .env, grep API_KEY .env, or a script that logs configuration
  3. Codebase search: A search for “DATABASE” matches a line in .env and returns the match
  4. Context gathering: The agent pulls project files into context automatically, such as open files or “important” config files

Path 2: Agent config folders persist secrets

A second leak path was measured at scale in November 2026: agent permission approvals that save shell commands as rules. When you pick “Yes, and don’t ask again” in Claude Code, it saves an allow rule in .claude/settings.local.json. When that rule is the exact command, any password or API key typed into it is saved in plaintext, and the file is sometimes committed to Git by mistake.

Apiiro’s research, by Shmulik Cohen and Matan Giladi and published November 5, 2026, found real secrets in 1,122 of 104,185 public copies of .claude/settings.local.json. Counting the file’s git history, shared .claude/settings.json files and committed agent transcripts, it found 2,539 distinct secrets across 1,994 public repositories. They included database passwords, cloud and AWS keys, and API tokens. Apiiro did not test whether the secrets still work.

This is not unique to Claude Code. Any agent that persists approved commands, remembered contexts, or conversation history may inadvertently store secrets that appeared in those commands.

Detailed findings by tool

Continue (open source)

Protection level: Strong defaults

Continue has the most comprehensive default protection of any tool we examined. Its DEFAULT_SECURITY_IGNORE_FILETYPES list explicitly covers environment and credential files:

export const DEFAULT_SECURITY_IGNORE_FILETYPES = [
// Environment and configuration files with secrets
"*.env",
"*.env.*",
".env*",
"config.json",
// ... more config, certificate, key, database and credential patterns
// such as "*.key", "*.pem" and "*.secret"
];

Continue’s built-in read, read-range, read-open-file, create-file and edit tools call throwIfFileIsSecurityConcern(), which throws an error on these files instead of just filtering them:

export function throwIfFileIsSecurityConcern(filepath: string) {
if (isSecurityConcern(filepath)) {
throw new ContinueError(
ContinueErrorReason.FileIsSecurityConcern,
`Reading or Editing ${filepath} is not allowed...`,
);
}
}

Source: core/indexing/ignore.ts

Limitations: The terminal tool does not check this list. Continue’s terminal security policy treats cat, head and grep as read-only commands, so cat .env is not blocked, and neither is a script that opens files itself.

OpenAI Codex CLI (open source)

Protection level: Strong when configured; not on by default

Codex CLI runs commands in an OS-level sandbox (Seatbelt on macOS, bwrap and seccomp on Linux). The default :workspace profile lets commands read the whole workspace and write inside it, and it protects .git, .agents, .codex and .aws as read-only. It does not deny reads of .env. In the source at this commit, **/*.env deny entries appear only in tests, not in a built-in profile.

The permission system can deny reads, though, and the sandbox enforces that for shell commands as well. OpenAI’s permissions documentation gives this pattern:

default_permissions = "workspace-no-env"
[permissions.workspace-no-env]
extends = ":workspace"
[permissions.workspace-no-env.filesystem.":workspace_roots"]
"**/*.env" = "deny"

Source: Codex permissions documentation, accessed 9 November 2026; built-in profiles in codex-rs/protocol/src/permissions.rs.

Limitations: Test your profile with codex sandbox macos or codex sandbox linux before relying on it. An open issue reports deny globs not blocking reads in v0.130.0.

Gemini CLI (open source)

Protection level: Default exclusion from indexing/search

Gemini CLI’s SYSTEM_FILE_EXCLUDES array includes .env files:

export const SYSTEM_FILE_EXCLUDES: string[] = ['**/.DS_Store', '**/.env'];

These patterns are part of DEFAULT_FILE_EXCLUDES, which the multi-file read tool uses. The glob and grep tools use a shorter core list that does not include .env. The single-file read_file tool refuses paths matched by .gitignore or .geminiignore, and both are respected by default. So a gitignored .env is refused, but **/.env does not match .env.local or .env.production.

Source: packages/core/src/utils/ignorePatterns.ts, packages/core/src/tools/read-file.ts

Limitations: Shell commands run by the agent are not filtered against these patterns. Add .env* to .geminiignore to cover variants.

Cline (open source)

Protection level: Opt-in via .clineignore

Cline’s ClineIgnoreController reads a .clineignore file at the project root. When present, it blocks matching files from AI access and validates shell commands:

validateCommand(command: string): string | undefined {
if (!this.clineIgnoreContent) {
return undefined;
}
const fileReadingCommands = ["cat", "less", "more", "head", "tail", "grep", ...];
// Validates file arguments against ignore patterns
}

Source: apps/vscode/src/core/ignore/ClineIgnoreController.ts

By default: No .clineignore exists, so all files are accessible. Users must create this file manually.

Cline’s SDK also ships an example plugin (sdk/examples/plugins/gitignore-read-files-guard.ts) that blocks file tools from reading files ignored by .gitignore. It must be installed separately with the Cline CLI.

Aider (open source)

Protection level: Moderate, if .env is gitignored

Aider sends a file’s contents to the model only after the file is added to the chat. At startup it offers to add .env to .gitignore:

env_path = Path(git_root) / ".env"
if env_path.exists() and not repo.ignored(".env"):
patterns_to_add.append(".env")

That matters for reads, not just commits: by default (--add-gitignore-files is off), Aider refuses to add gitignored files to the chat, with “Can’t add … which is in gitignore”.

special.py does list .env in ROOT_IMPORTANT_FILES, but that list only ranks file names in the repo map, which is built from git-tracked files. It does not send .env contents.

Source: aider/main.py, aider/commands.py, aider/special.py

Limitations: A .env that is already tracked by git can be added and appears in the repo map. Output from /run cat .env reaches the model if you choose to add it to the chat. A .aiderignore file adds another layer.

Cursor (closed source)

Protection level: File tools covered once configured; terminal not covered

Cursor’s documentation lists .env* in its default ignore list, together with files in .gitignore. It says a .cursorignore file blocks matching files from code accessible by Agent and Tab, and from @-mention references. It also warns that “complete protection isn’t guaranteed due to LLM unpredictability”, and:

“The terminal and MCP server tools used by Agent cannot block access to code governed by .cursorignore.”

Source: Cursor Ignore Files documentation, accessed 9 November 2026.

Configuration: Add .env and .env.* to .cursorignore explicitly. For every project, add **/.env and **/.env.* to the global ignore list in Cursor’s user settings; it is empty by default.

Claude Code (closed source)

Protection level: Requires explicit deny rules

Claude Code does not read .claudeignore files—they have no effect. The documented control is a Read deny rule in .claude/settings.json:

{
"permissions": {
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(./secrets/**)"
]
}
}

This blocks Claude’s file tools and the file commands Claude Code recognizes in Bash, such as cat, head, tail and sed, but not:

  • Commands that don’t name the file (e.g., grep -r API_KEY .)
  • Scripts that open files directly
  • Environment variables already in the shell (printenv)

For OS-level enforcement that also covers scripts, Anthropic’s docs point to Claude Code’s sandbox.

Source: Claude Code permissions documentation, accessed 9 November 2026.

The settings.local.json issue

When you approve a Claude Code command with “Yes, and don’t ask again,” it saves an allow rule in .claude/settings.local.json. The first time it writes the file in a git repository, Claude Code adds **/.claude/settings.local.json to your global git excludes file, but:

  • This doesn’t protect other machines, containers, or CI environments
  • It doesn’t untrack an already-committed file
  • Files created manually are not auto-ignored
  • It is never added to the project’s own .gitignore

Apiiro found 104,185 public copies of this file on GitHub; 1,122 of them (1.1%) held at least one real secret, 1,379 distinct secrets in total. Counting the file’s git history, shared .claude/settings.json files and committed agent transcripts, the total was 2,539 distinct secrets across 1,994 repositories. They included 379 database passwords, 43 SSH logins, 42 GitHub, GitLab and npm tokens, and 23 AWS keys. Apiiro counted a value as a real secret if it matched a provider key format or sat next to a public host, and did not test whether the secrets still worked.

Sources: Apiiro research (November 5, 2026), Claude Code settings documentation, accessed 9 November 2026. Coverage: The Hacker News.

GitHub Copilot (closed source)

Protection level: Requires admin configuration (Business or Enterprise)

Content exclusion must be configured in repository or organization settings:

"*":
- "**/.env"
- "**/.env.*"

GitHub’s documentation lists chat and agent support for content exclusion in VS Code, Visual Studio, JetBrains IDEs, Copilot CLI and the Copilot app, but not in Xcode or Eclipse chat. It also sets limits:

“When you use a Copilot agent in an IDE, GitHub Copilot CLI, or the GitHub Copilot app, content exclusion prevents the agent from accessing excluded files through Copilot tools and checks identifiable file paths in commands and scripts before running them, but might not detect indirect file access.”

The docs add that content exclusion “is not a filesystem security boundary” and is not guaranteed to be respected by third-party MCP servers.

Source: GitHub Copilot content exclusion documentation, accessed 9 November 2026.

Windsurf / Devin Desktop (closed source)

Protection level: Indexing exclusions by default; agent access blocked once configured

The docs, now titled Devin Desktop, say indexing skips .gitignore paths, node_modules and hidden paths (so .env) by default, and that files matched by .gitignore cannot be edited by the agent. Paths in a .devinignore file “are excluded from indexing and cannot be viewed, edited, or created by Devin”. The legacy .codeiumignore and .windsurfignore names are still read. For explicit .env protection, create a .devinignore:

.env
.env.*
*.pem
*.key

Source: Devin Desktop .devinignore documentation, accessed 9 November 2026. The docs do not say whether terminal commands are covered.

What ignore mechanisms don’t cover

Every tool we examined has at least one of these gaps in its default setup:

  1. Shell commands that don’t name the file: grep -r SECRET . can match .env even when .env is denied
  2. Scripts that open files directly: A Python script with load_dotenv() bypasses file-tool restrictions
  3. Environment variables in the shell: printenv and echo $DATABASE_URL aren’t file reads
  4. MCP servers with file access: External tools called by the agent use their own file access
  5. Semantic information from the IDE: Type definitions and hover information may leak excluded content

Practical recommendations

For individual developers

  1. Don’t rely on defaults. Even tools with default .env exclusions may not block all access paths. Explicitly configure ignore rules.

  2. Keep secrets out of the workspace. Use a secrets manager or environment injection so real credentials never exist as files the agent could read.

  3. Audit agent config folders. Check .claude/, .cursor/, .gemini/, and similar directories for files containing secrets. Add them to .gitignore.

  4. Use variable references, not values. When approving shell commands, use $DATABASE_URL rather than the actual connection string, so saved rules don’t contain secrets.

  5. Rotate exposed credentials immediately. If a secret was committed to Git or sent to a model, assume it’s compromised. Rotate first, then clean up.

For teams

  1. Enforce ignore rules at the repository level. Commit a .cursorignore, .clineignore, or equivalent with your project.

  2. Configure Copilot content exclusion at the organization level. Apply patterns like **/.env across all repositories.

  3. Add Claude Code’s local settings to your .gitignore template.

    .claude/settings.local.json
  4. Use short-lived, scoped credentials. A leaked token that expires in an hour and can only read one resource is less damaging than a long-lived admin key.

  5. Audit for committed secrets. Search your GitHub organization for .claude/settings.local.json, .env, and similar files—including in git history.

Where Shadow fits

Shadow is a privacy layer that sits between AI tools and model APIs. For coding agents whose model traffic goes through Shadow in a format it can read—Claude Code, Codex CLI, Gemini CLI, Aider, Cline, Continue, and GitHub Copilot—Shadow replaces secrets, names, emails, and other sensitive values with realistic fakes before the request leaves your machine, then restores them in the response.

This provides defense-in-depth: even if an agent reads a file it shouldn’t, or a shell command prints credentials, the actual values don’t reach the model provider.

Shadow cannot mask Cursor’s traffic because Cursor uses a binary protocol to its own backend where the final prompt is constructed. Shadow recognizes Cursor’s requests and shows them on the dashboard as “seen, not protected.”

For setup: Protect secrets from AI coding assistants.

Limitations of this research

  • We audited source code at specific commits; behavior may differ in other versions
  • Documentation review for closed tools may not reflect undocumented behavior
  • We did not verify all claims by testing against live models
  • The GitHub scan figures are Apiiro’s own published findings; we did not replicate the scan
  • Some pattern-matching detections may have false positives or negatives

About this research

Written by the Shadow Research Team from source code inspection of open-source repositories and official documentation of closed-source tools. Shadow is a privacy layer for AI from Tiny Bubble Company. It is not affiliated with any of the AI coding tools examined in this article.

Disclaimer: This article describes publicly available source code and documentation as of the dates noted. It is not legal advice. Behavior may change between versions; verify protections on your actual installed version before relying on them.

Install Shadow Core freeAll research

Frequently asked questions

Does Cursor read my .env file?

Cursor's docs put .env* on its default ignore list and say .cursorignore blocks Agent, Tab and @-mentions. The docs also say the terminal and MCP tools used by Agent cannot be blocked this way, so cat .env run in the terminal is not stopped. Add .env and .env.* to .cursorignore or the global ignore list explicitly.

Does Claude Code send .env to Anthropic?

If Claude Code reads your .env file—via its Read tool or a shell command—the contents are sent to Anthropic's API as part of the prompt. Add a Read(./.env) deny rule in .claude/settings.json to block the built-in file tools and recognized commands like cat.

How do I stop Copilot reading secrets?

On Copilot Business or Enterprise, configure content exclusion in repository or organization settings with patterns like **/.env and **/.env.*. GitHub's docs say IDE agents, Copilot CLI and the Copilot app respect it for Copilot tools and check file paths they can identify in commands. They also say it may miss indirect file access and is not a filesystem security boundary.

Does Aider ignore .env files?

Mostly, if .env is gitignored. Aider sends a file's contents only after you add it to the chat, and by default it refuses to add gitignored files (--add-gitignore-files is off). It also offers to add .env to .gitignore at startup. The risk is a .env already tracked by git, or the output of a /run command you choose to share. A .aiderignore gives extra control.

What is .clineignore?

Cline's optional ignore file. If it exists, Cline blocks matching files from AI access and validates shell commands against the patterns. By default no .clineignore exists, so all files are accessible.

Does Gemini CLI protect .env files?

Partly. **/.env is in Gemini CLI's default excludes for multi-file reads, but not .env.local or other variants. The single-file read tool refuses files matched by .gitignore or .geminiignore, which it respects by default. Shell commands are not filtered, so list .env* in .geminiignore and keep secrets out of the workspace.

What is the .claude/settings.local.json issue?

When you approve a Claude Code shell command with 'Yes, and don't ask again', it saves an allow rule in .claude/settings.local.json. Sometimes that rule is a pattern; sometimes it is the exact command, including any password or API key typed into it, in plaintext. Apiiro found 1,122 public copies of the file on GitHub holding at least one real secret.

Can Shadow protect secrets from AI coding agents?

For agents whose model traffic goes through Shadow in a format it can read (Claude Code, Codex CLI, Gemini CLI, Aider, Cline, Continue, GitHub Copilot), Shadow replaces secrets with reversible fakes before the request leaves your machine. Cursor uses a binary protocol to its own backend, so Shadow can observe but not mask its requests.