Claude Code Ignore Files: No .claudeignore, Use Read Deny Rules
Claude Code has no .claudeignore. To keep files like .env away from it, add Read deny rules to settings.json, and turn on the sandbox for Bash subprocesses.
- Claude Code has no .claudeignore; a .claudeignore file has no effect. Add rules such as Read(./.env) to permissions.deny in .claude/settings.json instead.
- Read deny rules cover the built-in file tools and Bash commands Claude Code recognizes, such as cat and head, but not a Python or Node script that opens files itself. The sandbox covers those.
- respectGitignore only hides files from the @ file picker. It doesn't block reads.
Claude Code has no .claudeignore. If your project has one, it has no effect. To keep a file away from Claude, add a Read deny rule such as Read(./.env) or Read(./secrets/**) to permissions.deny in .claude/settings.json. To stop programs that Bash starts from reading it too, turn on the sandbox.
This guide covers what each setting blocks, a paste-ready config, how to move from .claudeignore, where to put the rules, and their limits. For rule syntax and settings precedence, see the permissions and settings.json cheat sheet.
File-exclusion rules and the limits on indirect Bash reads were rechecked against the official permissions reference on 2026-11-09. The test below remains the original Claude Code 2.1.314 test; it was not rerun.
What each setting blocks
| What you want | Setting | What it covers | What it doesn’t cover |
|---|---|---|---|
Ignore files with .claudeignore | None | Nothing | Everything |
| Keep Claude from reading a file | Read(...) in permissions.deny | Built-in file tools (including Grep and Glob), @ mentions, IDE selection context, Bash cat, head, tail, sed, tee, and redirections | grep -r without naming the file, scripts that open files themselves |
Hide files from @ suggestions | respectGitignore | The @ file picker | Reads themselves |
| Keep Bash processes from reading a path | sandbox.filesystem.denyRead | Sandboxed commands and their subprocesses | The built-in Read tool |
A Read deny rule also blocks Edit and Write on the same path, including creating a new file there. NotebookEdit isn’t covered, so add an Edit deny rule for paths no tool may change.
respectGitignore defaults to true and appears in /config as “Respect .gitignore in file picker”.
Source: https://code.claude.com/docs/en/permissions and https://code.claude.com/docs/en/settings-reference, checked 2026-10-31
A paste-ready config
This follows the official example. Put it in .claude/settings.json:
{
"permissions": {
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(./secrets/**)",
"Read(./config/credentials.json)"
]
}
}
Paths use gitignore syntax, and the prefix sets the anchor:
//path: absolute, from the filesystem root~/path: from your home directory/path: relative to the settings source. In project settings that’s the project root, but in~/.claude/settings.jsonit’s~/.claude/pathor./path: relative to the current directory
A pattern like /Users/... with one leading slash isn’t an absolute path. Start absolute paths with //. * matches within one path segment, and ** matches across directories. A bare filename such as Read(.env) matches a .env at any depth under the current directory.
You can carve out exceptions with !. Read(*.env) followed by Read(!sample.env) blocks every .env file except sample.env. The carve-out only reaches rules from the same settings file; it can’t cancel a deny from another one.
Path rules written as Write(...), Glob(...) or NotebookEdit(...) never match. Use Read(...) for reads and Edit(...) for writes.
Source: https://code.claude.com/docs/en/permissions and https://code.claude.com/docs/en/settings-reference, checked 2026-10-31
Moving from .claudeignore
Turn each .claudeignore line into one Read(...) deny rule. Before:
.env
.env.*
secrets/
dist/
After:
{
"permissions": {
"deny": [
"Read(.env)",
"Read(.env.*)",
"Read(secrets/**)",
"Read(dist/**)"
]
}
}
Written this way, each rule matches at any depth under the current directory. To match only at the project root, anchor it with one slash, as in Read(/dist/**). A filename with ./, such as Read(./.env), points at the .env in the current directory.
Source: https://code.claude.com/docs/en/permissions, checked 2026-10-31
Where to put the rules
.claude/settings.json: shared with the project. Commit it and everyone who clones the repo gets the same deny rules.claude/settings.local.json: you, in this project only. When Claude Code creates this file, it adds it to your git excludes. If you create it by hand, add it to.gitignoreyourself~/.claude/settings.json: all your projects. A/prefix anchors at~/.claude/here, so use~/or//- Managed settings: deployed by your organization. Nothing else can override them
If a path is denied at any level, no other level can allow it.
Source: https://code.claude.com/docs/en/settings and https://code.claude.com/docs/en/permissions, checked 2026-10-31
What deny rules don’t stop
For the built-in tools, the docs call Read rules a “best-effort attempt”. In Bash, they only apply to file commands Claude Code recognizes. A command that reads files without naming them, such as grep -r pattern ., and a Python or Node script that opens files itself are not blocked.
The sandbox covers that gap. It is off by default; turn it on with /sandbox or sandbox.enabled. With the sandbox on, Claude Code adds your Read deny paths to sandbox.filesystem.denyRead, so they’re enforced at the OS level for sandboxed commands and every subprocess they start. For paths you only want to block from Bash, write them in denyRead directly:
{
"sandbox": {
"enabled": true,
"filesystem": {
"denyRead": ["~/.aws/credentials"]
}
}
}
By default, sandboxed commands can read most of the machine, including ~/.ssh and ~/.aws/credentials. And denyRead doesn’t stop the built-in Read tool, which follows permission rules. That’s why you need both layers. Sandbox paths use different syntax from permission rules: /tmp/build is absolute and ~/ is your home directory.
Environment variables are a separate path. Sandboxed commands inherit Claude Code’s environment, secrets included. Keep Secrets Away from Claude Code reproduces those leaks.
Source: https://code.claude.com/docs/en/sandboxing and https://code.claude.com/docs/en/settings-reference, checked 2026-10-31
Checking that it works
In our test setup, we put a dummy .env (containing DUMMY_TOKEN=not-a-real-secret) in a temporary directory, with a .claude/settings.json that denies Read(./.env). We used Claude Code 2.1.314:
claude -p "Use the Read tool to read the file .env in the current directory and print its contents. If you cannot, say exactly what error you got." --allowedTools Read
The Read tool returned this error, and the contents were not shown:
File is in a directory that is denied by your permission settings.
We did not test Bash cat or the sandbox (not run). Those parts of this guide come from the official docs. To confirm a settings file loaded, check the Setting sources line in /status.
Summary
.claudeignorehas no effect. Move its entries intoRead(...)deny rules- Put deny rules in
.claude/settings.jsonfor the project, or.claude/settings.local.jsonfor yourself - Use
//for absolute paths. A single leading/anchors at the settings source respectGitignoreonly hides files from@suggestions. It doesn’t block reads- Deny rules don’t stop scripts that open files themselves. Turn on the sandbox
Related articles
- Permission rules and settings precedence: choose the settings file and understand deny priority.
- Secrets exposed through files and inherited environment variables: check the paths file rules do not cover.
- Environment-variable configuration: diagnose settings that do not take effect.
FAQ
- How do I exclude files from Claude Code without .claudeignore?
- Add Read deny rules to permissions.deny in .claude/settings.json. A .claudeignore file has no effect. Read rules do not cover arbitrary scripts that open files themselves; use the sandbox for OS-level restrictions on shell processes.
- Does .gitignore stop Claude Code from reading files?
- No. respectGitignore only leaves gitignored files out of the @ file picker; it doesn't stop Claude from reading them. Put files you want to block in Read deny rules.
- Can Claude Code still read .env through Bash if I deny it?
- Deny rules cover Bash file commands Claude Code recognizes, such as cat, head, tail, sed and tee. They don't cover a command that reads files without naming them, such as grep -r, or a Python or Node script that opens files itself. Turn on the sandbox to block those.
- Where do I put Claude Code deny rules?
- Use the project's .claude/settings.json to share them through git, .claude/settings.local.json for yourself in one project, or ~/.claude/settings.json for all your projects. A deny at any level can't be overridden by an allow at another.
- How do I keep deny rules out of git?
- Put them in .claude/settings.local.json. When Claude Code creates that file, it adds it to your git excludes. If you create it by hand, add it to .gitignore yourself.