Skip to content

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

Closed as not planned

Description

@alexbachlej

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • 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

Activity

  1. Bladed3d commented on Jan 15, 2026

    @Bladed3d

    I have reported this 3 times! Fix it!

  2. stevenelliottjr commented on Feb 2, 2026

    @stevenelliottjr

    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!

  3. github-actions commented on Mar 3, 2026

    @github-actions

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

  4. github-actions commented on Mar 12, 2026

    @github-actions

    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.

  5. locked as resolved and limited conversation to collaborators on Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstaleIssue is inactive

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions