Deny Sensitive Files Setup
Production-ready setting that handles deny, access, sensitive, files. Includes structured workflows, validation checks, and reusable patterns for permissions.
Deny Sensitive Files Setup
Block Claude Code from reading environment files, secrets, and credential configurations.
When to Use This Setting
Apply this setting when you need to:
- Prevent accidental exposure of API keys, database passwords, and authentication tokens during Claude Code sessions
- Enforce security policies that restrict AI tool access to sensitive configuration files
- Create a baseline security layer that protects credentials regardless of other permission settings Consider alternatives when:
- You need Claude Code to read environment files for debugging configuration issues
- Your project uses encrypted secrets management and the raw files do not contain plaintext credentials
Quick Start
Configuration
name: deny-sensitive-files-setup type: setting category: permissions
Example Application
claude setting:apply deny-sensitive-files-setup
Example Output
Setting applied. Changes:
- permissions.deny: [Read(./.env), Read(./.env.*), Read(./secrets/**), Read(./config/credentials.json)]
Core Concepts
Sensitive File Protection Overview
| Aspect | Details |
|---|---|
| .env Files | Environment variable files containing API keys, database URLs, and service credentials |
| .env.* Variants | Environment-specific files like .env.production, .env.staging, .env.local |
| Secrets Directory | Dedicated directory for certificates, private keys, and other secret materials |
| Credentials JSON | Application-level credential configuration files with authentication details |
Deny Rule Architecture
+---------------------------+
| Claude Code Read Request |
+---------------------------+
|
v
+---------------------------+
| Deny Rule Check |
+---------------------------+
| .env -> BLOCKED |
| .env.* -> BLOCKED |
| secrets/** -> BLOCKED |
| config/ | |
| credentials | |
| .json -> BLOCKED |
+---------------------------+
|
blocked / allowed
| |
v v
REJECT Continue to
request allow list
evaluation
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
| permissions.deny | array | [] | List of file read patterns to block from Claude Code access |
| Read(./.env) | string | N/A | Block reading the root .env file containing environment variables |
| Read(./.env.*) | string | N/A | Block reading all .env variant files like .env.production |
| Read(./secrets/**) | string | N/A | Block reading any file within the secrets directory tree |
| Read(./config/credentials.json) | string | N/A | Block reading the application credentials configuration file |
Best Practices
- Apply this setting as a base layer for all projects - Sensitive file protection should be the first setting applied, before any allow rules. Deny rules take precedence over allow rules, ensuring credentials are always protected.
- Extend the deny list for your project structure - The default list covers common patterns. Add project-specific entries for files like service-account.json, .npmrc with auth tokens, or private key files.
- Use .env.example for configuration reference - Create a .env.example file with placeholder values that Claude Code can read. This provides configuration context without exposing actual credentials.
- Audit deny rules against your file structure - Run a file listing of sensitive files in your project and verify each one is covered by a deny pattern. New developers may add credentials in unexpected locations.
- Combine with gitignore alignment - Your deny rules should generally mirror your .gitignore entries for sensitive files. If a file is too sensitive to commit, it is too sensitive for Claude Code to read.
Common Issues
- Claude Code cannot help with environment configuration - When deny rules block .env files, Claude Code cannot diagnose configuration issues. Temporarily share specific variable names without values or use .env.example files.
- Wildcard pattern too broad - The pattern Read(./.env.*) blocks all files starting with .env. If you have non-sensitive files matching this pattern, use more specific deny entries.
- Secrets directory not at expected path - If your project stores secrets in a non-standard location, the default deny rules will not cover them. Add custom entries for your project's actual secrets paths.
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Project Standards Config
Claude Code settings preset that enforces consistent coding standards. Configures TypeScript strict mode, ESLint rules, Prettier formatting, and naming conventions.
Bedrock Configuration Blueprint
All-in-one setting covering configure, claude, code, amazon. Includes structured workflows, validation checks, and reusable patterns for api.
Refined Corporate Preset
Production-ready setting that handles configure, proxy, settings, corporate. Includes structured workflows, validation checks, and reusable patterns for api.