Many people search for this file because other tools taught them the pattern: list the paths, and the assistant leaves them alone. A .claudeignore file in a repository looks like it does that for Claude Code. It does nothing, and the files it lists stay readable.
What Claude Code's docs say
Anthropic's permissions page answers the question in one line, in the section on Read and Edit rules.
If your project has a .claudeignore file, it has no effect, so move its entries into Read deny rules.Claude Code docs, Configure permissions
The file gives no warning that it is unused. In issue 56997, opened in May 2026, a developer reports a .claudeignore at the project root that listed .env, and Claude read the file anyway, secrets included. The workaround in that report is the one the docs give: deny rules in .claude/settings.json.
"Our .env is in .claudeignore, so Claude cannot read it."
What .gitignore does and does not do
A .gitignore file is about commits, not access. Git's own gitignore documentation says it "specifies intentionally untracked files that Git should ignore." A gitignored .env is still on disk, in the folder where the agent runs.
Claude Code has one setting tied to it. In the settings reference, respectGitignore controls whether the @ file picker leaves out gitignored files, and it is on by default. That hides the file from the list you pick from. It does not stop Claude's Read tool, which reads inside the working directory without asking.
Read deny rules are the replacement
A deny rule names a tool and a path pattern, and it blocks in every permission mode. Put it in .claude/settings.json and commit it, so everyone who clones the repository gets it. The settings page notes that deny rules in that file apply right away, before a teammate trusts the folder.
{
"permissions": {
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(./secrets/**)",
"Read(~/.ssh/**)",
"Read(~/.aws/**)"
]
}
}
The paths use the same pattern syntax as .gitignore, so most lines from an old ignore file move over as they are. The prefix decides where a pattern starts:
| Pattern | Starts from | Example |
|---|---|---|
//path | The filesystem root | Read(//etc/**) |
~/path | Your home folder | Read(~/.aws/**) |
/path | The settings source: the project root in project settings | Read(/config/prod.json) |
path or ./path | The current directory | Read(./.env) |
A single leading slash is the usual mistake. /Users/alice/file is not an absolute path to Claude Code; write //Users/alice/file. A Read deny rule also blocks Edit and Write on the same path, and Claude Code makes a best effort to apply it to Grep, Glob, @ mentions and the context an IDE shares. Our notes on how Claude Code permissions work cover how deny, ask and allow rules combine.
Where deny rules stop
The permissions page is plain about the edge. Deny rules cover Claude's file tools, the file commands it recognizes in Bash, such as cat, head and tail, and redirections like < file.
They do not cover a command that reads files without naming them, such as grep -r pattern ., or a Python or Node script that opens the file itself. A test run that loads .env through a library is that second case. The rule is a check on what Claude asks for, not a limit the operating system enforces.
Add the sandbox for shell commands
For shell commands, the sandboxed Bash tool adds a limit the operating system enforces, on the command and every process it starts. It is off by default; /sandbox turns it on. Out of the box it can still read most of the machine, credential files included, and the page says there is no built-in credential deny list.
So list what it must not read. This example from the sandboxing page blocks your home folder and opens the project again; it belongs in the project's .claude/settings.json, where . means the project root.
{
"sandbox": {
"enabled": true,
"filesystem": {
"denyRead": ["~/"],
"allowRead": ["."]
}
}
}
Note what that leaves open: a .env inside the project is still readable to shell commands, so add it to denyRead too. The credentials block can deny files such as ~/.ssh and unset variables such as GITHUB_TOKEN before each command. The sandbox covers shell commands only, and a denyRead entry does not stop the Read tool, which is why you keep both layers.
Keep the file out of reach
Every option above is a rule about a file that is still there. The strongest fix is a secret that never sits in the agent's folder or environment: a development key with little reach, a secret manager that hands the value to the process that needs it, a test setup that does not read production credentials.
Whatever Claude does read becomes part of the conversation sent to the model, which is where the secrets in issue 56997 ended up. A file the agent can reach, a host it can send to and a key it holds are the same three questions behind every one of the AI agent security risks we answer.
| Option | What it covers | What it misses |
|---|---|---|
.claudeignore | Nothing | Everything |
respectGitignore | The @ file picker | Every tool Claude calls |
| Read deny rules | File tools, recognized shell commands, redirections | grep -r, scripts that open files |
Sandbox denyRead | Shell commands and their child processes | The Read tool, hooks, MCP servers |
| No secret in the folder | Every tool and process | Only what you put back |
Our list of Claude Code security best practices puts these layers next to the permission modes and managed settings.
A side note on how we do it
We build Fenzi, which starts the agent inside an OpenShell sandbox on a copy of the project that leaves out gitignored files, .git and your home folder, and names files that look like secrets before it copies them; the workspace sheet lists the rules. A container or a virtual machine with a clean copy of the project answers the same question.
So, what should you use instead?
Delete the .claudeignore file so nobody trusts it, and move its lines into Read deny rules in a committed .claude/settings.json. Turn on the sandbox with denyRead for the same paths, since deny rules do not reach scripts. Then take real secrets out of the folder, because a file that is not there needs no rule, which is the first of the four rules of agentic AI security we hold to. Anthropic's Configure permissions page is the next thing to read.