[BUG] Claude displayed sensitive .env credentials (API keys, secrets) in output when it should have redacted them.
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Description:
When asked to read or verify environment configuration, Claude Code displays full contents of .env files including sensitive API keys and secrets in its output, without any redaction.
Steps to reproduce:
- Have a project with .env or .env.local containing API keys (e.g., STRIPE_SECRET_KEY, CLERK_SECRET_KEY)
- Ask Claude to check environment configuration or restart a service
- Claude runs commands like cat .env or grep on config files and displays full key values in response
Expected behavior:
- Sensitive values should be redacted (e.g., sk_live_****)
- Or Claude should use quiet checks (grep -q) without displaying values
- Warning before displaying any .env content
Actual behavior:
- Full credentials displayed in chat output
- Keys saved to ~/.claude/projects//tool-results/.txt log files
- No warning or redaction
Security impact:
- Credentials exposed in terminal history
- Credentials persisted in Claude's local cache files
- Potential exposure if screen shared or logs accessed
Affected: Claude Code CLI (Opus 4.5)
What Should Happen?
Keys Should not be displayed or logged
Error Messages/Logs
Steps to Reproduce
Description:
Steps to reproduce: eg.
- Create a project with a .env file containing secrets: STRIPE_SECRET_KEY=sk_live_abc123xyz CLERK_SECRET_KEY=sk_live_def456
- Start Claude Code in that directory: claude
- Ask Claude to check the environment: "show me what's in .env"
- or "verify the stripe key is configured"
- or "restart the docker service and check env vars"
- Observe: Claude runs cat .env or grep and displays full key values in output without redaction
- Check Claude's cache: grep -r "sk_live_" ~/.claude/projects/
- Keys are persisted in tool-results files
Claude Model
None
Is this a regression?
I've noticed this before, so this is ongoing bug
Last Working Version
No response
Claude Code Version
2.1.7 (Claude Code)
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Other
Additional Information
Description:
Workaround: User must manually delete cached files: grep -r -l "sk_live_|pk_live_|whsec_" ~/.claude | xargs rm -f
Related concerns:
- No prompt asking user before displaying .env contents
- No .claudeignore or similar mechanism to protect sensitive files
- Secrets remain in cache even after session ends
- Screen sharing / pair programming risk
Suggested fix:
- Auto-detect common secret patterns (sk_live_, pk_test_, whsec_, API_KEY=, SECRET=)
- Redact values or require explicit confirmation before display
- Add .env* to a default "sensitive files" list
I have reported this 3 times! Fix it!
I've created a plugin that addresses this issue: PR #22594
The secrets-scanner plugin provides real-time detection of exposed secrets in Claude Code output:
- Detects 35+ secret patterns (API keys, tokens, private keys, database connection strings)
- Displays an immediate warning when credentials are detected
- Logs detections (without actual secret values) for security review
- Warns when accessing sensitive file paths (.env, credentials, etc.)
While this doesn't redact the actual output (which would require core changes), it provides defense-in-depth by alerting users immediately when sensitive data appears.
Happy to iterate based on feedback!
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
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.