[BUG] API keys in .env files are sent into the conversation when a file Claude has edited changes on disk

Status Open
Maintainer reply None cached
Activity 0 comments · opened Sep 26, 2026

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?

When Claude has read or written a file during a session, and that file is later changed outside Claude (for example in the user's own editor), Claude Code automatically adds the changed lines to the conversation. Nothing masks secrets in those lines first. If the file is a .env file, any API keys the user adds are sent to the model and saved in the session transcript, even though the user deliberately edited the file themselves to keep the keys private.

What Should Happen?

At least one of:

  • Changes to files that commonly hold secrets (.env, .env., .pem, *.key, credentials files) are not attached to the conversation, or
  • Values that look like secrets (such as sk-ant-…, sk-…, AKIA…, ghp_…, or any KEY=/TOKEN=/SECRET= values) are masked before the content is added, or
  • The user is warned that editing this file will show its contents to Claude.

Error Messages/Logs

Steps to Reproduce

  1. In a Claude Code session, have Claude create or edit .env.local (for example, "add placeholder entries for my API keys").
  2. Outside Claude Code, open .env.local in a separate editor and paste real API keys into the placeholders. Save.
  3. Send any message to Claude in the same session.

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.7032.0

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Windows Terminal

Additional Information

_No response_

View original on GitHub ↗