Keep secrets safe with AI coding tools: ignore files and permissions
AI coding tools read your project to help you. That can include files you never meant to share, like a .env file full of API keys. Each tool has a way to keep files out of reach or to ask before it acts. This guide shows those settings for Cursor, Claude Code, Codex and GitHub Copilot, and what each vendor says the settings can't do. None of them is a guarantee. Everything here comes from each vendor's own docs, read on October 15, 2026.
Not affiliated with or endorsed by Anthropic, Anysphere (Cursor), OpenAI, GitHub or Microsoft. Check each vendor's current docs before relying on these details.
Our tool pages: Cursor | Claude Code | OpenAI Codex | GitHub Copilot
The short version
| Tool | Setting | What the vendor says it can't do |
|---|---|---|
| Cursor | .cursorignore in your project root | "The terminal and MCP server tools used by Agent cannot block access to code governed by .cursorignore" (checked Oct 2026) |
| Claude Code | deny rules in permissions in a settings file | Our advice, not a vendor quote: check the docs for what each rule type covers |
| OpenAI Codex | Sandbox mode and approval policy | Full access mode has "No sandbox; no approvals" (checked Oct 2026) |
| GitHub Copilot | Content exclusion (admins and owners) | "not supported in Edit and Agent modes of Copilot Chat in Visual Studio Code and other editors" (checked Oct 2026) |
Our advice, not a vendor quote: the safest secret is one that isn't in your project. Keep keys in a .env file that your .gitignore lists, and never paste a key into a chat with an AI tool. If a key was ever pasted, committed or shown to a tool, rotate it (make a new one and turn off the old one).
Cursor: .cursorignore
Cursor's ignore-files docs say to add a .cursorignore file in your root directory. It uses the same patterns as .gitignore:
# .cursorignore (NOT TESTED)
.env
.env.*
secrets/
Cursor's docs are clear about the limits. The terminal and MCP tools aren't covered: "The terminal and MCP server tools used by Agent cannot block access to code governed by .cursorignore" (checked Oct 2026). And: "While Cursor blocks ignored files, complete protection isn't guaranteed due to LLM unpredictability." (checked Oct 2026)
Our advice, not a vendor quote: treat .cursorignore as a helpful extra layer. It doesn't replace keeping secrets out of the project.
Claude Code: deny rules
Claude Code's settings docs say permissions cover "what Claude Code can run without asking and how to write allow, ask, and deny rules." (checked Oct 2026) Their example blocks reading .env files:
{
"permissions": {
"deny": ["Read(./.env)", "Read(./.env.*)"]
}
}
(Example layout from the docs, NOT TESTED.) The docs say that in a project settings file, deny and ask rules apply "right away", before the folder is trusted (checked Oct 2026). A Read rule is about reading files. Check the permissions docs for what other rule types cover before relying on it.
OpenAI Codex: sandbox and approvals
OpenAI's Codex sandbox docs describe the default for version-controlled folders as "Auto (workspace write + on-request approvals)" (checked Oct 2026), where "Codex can read files, make edits, and run commands in the workspace." (checked Oct 2026) For a careful, look-only session, the docs show:
codex --sandbox read-only --ask-for-approval on-request
(NOT TESTED.) The docs mark full access, --dangerously-bypass-approvals-and-sandbox (alias --yolo), as "Elevated Risk" (checked Oct 2026) with "No sandbox; no approvals (not recommended)". (checked Oct 2026) Our advice, not a vendor quote: in the modes the docs describe, Codex can read files in your workspace, so keep secrets out of the project folder.
GitHub Copilot: content exclusion
GitHub's content exclusion docs say "Repository administrators, organization owners, and enterprise owners can configure content exclusion." (checked Oct 2026) GitHub lists it for "The Copilot Business and Copilot Enterprise plans" (checked Oct 2026).
GitHub lists clear limits on its content exclusion page: "Content exclusion is currently not supported in Edit and Agent modes of Copilot Chat in Visual Studio Code and other editors." (checked Oct 2026) And: "It's possible that Copilot may use semantic information from an excluded file if the information is provided by the IDE indirectly." (checked Oct 2026) GitHub's setup page also says: "GitHub Copilot CLI and Agent mode in Copilot Chat in IDEs do not support content exclusion." (checked Oct 2026)
Habits that work in every tool
Our advice, not a vendor quote:
- Keep secrets out of the repo. Use a
.envfile and list it in.gitignore. - Don't paste keys into chats. A pasted key has left your machine.
- Rotate anything that leaked. If a key was committed, pasted or shown to a tool, make a new one and turn off the old one.
- Keep approvals on. Let the tool ask before it runs commands until you trust what it does.
- Use ignore and deny settings as an extra layer, not your only one. Every vendor above says its setting has limits.
For keeping MCP server tokens out of config files, see our MCP setup guide. For what your agent reads at the start, see our AGENTS.md and CLAUDE.md guide.
Not affiliated with or endorsed by Anthropic, Anysphere (Cursor), OpenAI, GitHub or Microsoft. Check each vendor's current docs before relying on these details.