claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Claude displayed sensitive .env credentials (API keys, secrets) in output when it should have redacted them.

Open Inthrabachlej opened this issue 10 months ago • 1 comments

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:

  1. Have a project with .env or .env.local containing API keys (e.g., STRIPE_SECRET_KEY, CLERK_SECRET_KEY)
  2. Ask Claude to check environment configuration or restart a service
  3. 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.

  1. Create a project with a .env file containing secrets: STRIPE_SECRET_KEY=sk_live_abc123xyz CLERK_SECRET_KEY=sk_live_def456
  2. Start Claude Code in that directory: claude
  3. Ask Claude to check the environment: "show me what's in .env"
  4. or "verify the stripe key is configured"
  5. or "restart the docker service and check env vars"
  6. Observe: Claude runs cat .env or grep and displays full key values in output without redaction
  7. Check Claude's cache: grep -r "sk_live_" ~/.claude/projects/
  8. 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

Inthrabachlej avatar Jan 14 '26 21:01 Inthrabachlej

I have reported this 3 times! Fix it!

Bladed3d avatar Jan 15 '26 00:01 Bladed3d

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!

stevenelliottjr avatar Feb 02 '26 19:02 stevenelliottjr

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

github-actions[bot] avatar Mar 03 '26 10:03 github-actions[bot]

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.

github-actions[bot] avatar Mar 12 '26 14:03 github-actions[bot]