Secure env variables by adding .claudeignore
Should add .claudeignore to prevent env content being read or overwrite. For your safty and mine.
i added this but it still sees my env, bug ?
Also seeing this issue, on Windows.
can you read my .env file?
● Read(.env) ⎿ Read 9 lines (ctrl+r to expand)
● Your .env file contains API keys for various services:
- HuggingFace token
- Groq API key
- Gemini API key
- Anthropic API key
- Database URL for PostgreSQL
aren't you support to honor my .gitignore and .claudeignore files?
● Read(.gitignore) ⎿ Read 4 lines (ctrl+r to expand)
● Read(.claudeignore) ⎿ Read 2 lines (ctrl+r to expand)
● You're absolutely right - I should not have read your .env file. Both your .gitignore and .claudeignore files explicitly exclude .env files, and I should honor those restrictions. I apologize for that oversight.
why is this happening?
● I'm not sure why the .claudeignore and .gitignore files weren't being honored when you asked me to read the .env file. This appears to be a bug or limitation in how Claude Code processes these ignore files.
You should report this issue at https://github.com/anthropics/claude-code/issues since the tool should respect your .claudeignore and .gitignore files to prevent reading sensitive files like .env.
Also seems there is a problem with deny rules in settings JSON?
can you read my .env file?
● Read(.env) ⎿ Read 9 lines (ctrl+r to expand)
● Your .env file contains API keys for:
- HuggingFace (HF_TOKEN)
- Groq (GROQ_API_KEY)
- Gemini (GEMINI_API_KEY)
- Anthropic (ANTHROPIC_API_KEY)
- Database URL for PostgreSQL
shouldn't my settings.local.json stop you from doing that?
● Read(.claude\settings.local.json) ⎿ Read 10 lines (ctrl+r to expand)
● You're absolutely right! Your settings.local.json has "deny": ["Read(**/.env*)"] which should have blocked me from reading your .env file. This appears to be a bug - the permission system should have prevented that read operation.
Also seeing this issue, on Windows.
can you read my .env file?
● Read(.env) ⎿ Read 9 lines (ctrl+r to expand)
● Your .env file contains API keys for various services:
- HuggingFace token
- Groq API key
- Gemini API key
- Anthropic API key
- Database URL for PostgreSQL
aren't you support to honor my .gitignore and .claudeignore files?
● Read(.gitignore) ⎿ Read 4 lines (ctrl+r to expand)
● Read(.claudeignore) ⎿ Read 2 lines (ctrl+r to expand)
● You're absolutely right - I should not have read your .env file. Both your .gitignore and .claudeignore files explicitly exclude .env files, and I should honor those restrictions. I apologize for that oversight.
why is this happening?
● I'm not sure why the .claudeignore and .gitignore files weren't being honored when you asked me to read the .env file. This appears to be a bug or limitation in how Claude Code processes these ignore files.
You should report this issue at https://github.com/anthropics/claude-code/issues since the tool should respect your .claudeignore and .gitignore files to prevent reading sensitive files like .env.
The deny in settings.json eventually worked for me, had a chat with the bot on anthropic website. There was an ignorePatterns cmd that is getting deprecated.
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
I have also got this issue: Claude Code .claudeignore Bug Report Issue Summary Claude Code is able to read files that are explicitly listed in .claudeignore, bypassing the intended security mechanism. Environment Tool: Claude Code (VS Code Extension) OS: Windows 10/11 Date: 2025-12-18 .claudeignore Configuration
Prevent Claude from reading sensitive files
**/.env */.env. **/.env.local /.env .env .env. .env.local .env Expected Behavior Claude Code should be blocked from reading .env.local and should return an error or empty response when attempting to access this file. Actual Behavior Claude Code was able to successfully read the contents of .env.local, including: Variable Type ANTHROPIC_API_KEY API Secret Key NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY Auth Public Key CLERK_SECRET_KEY Auth Secret Key DATABASE_URL Database Connection String (with password) DIRECT_URL Database Connection String (with password) NODE_ENV Environment Variable Security Impact Severity: High Sensitive credentials (API keys, database passwords) were exposed despite .claudeignore rules Users relying on .claudeignore for security may unknowingly expose secrets Steps to Reproduce Create a .claudeignore file with patterns to block .env files Create a .env.local file with sensitive data Ask Claude Code to read the .env.local file Observe that the file contents are returned successfully Recommendation Rotate any credentials that may have been exposed Investigate pattern matching logic in .claudeignore parser
This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.