Should you let Claude Code see your env or config file?

The answer is no. Claude Code should never be looking in your environment file, your configs or anything else that stores secrets.

Here's why

The first and simplest problem. When reading files, Claude Code sends the contents to Anthropic's servers. It is encrypted over HTTPS in transit but the files are potentially readable by Anthropic. Any file or folder Claude has read will have been sent to Anthropic's servers.

The second problem. Claude Sonnet, Opus and Fable are very capable models but they can occasionally make mistakes. There is a chance that the model might leak your credentials accidentally somewhere. For example, it might try to contact an API using a key from your env file. If the API URL is incorrect then Claude will have inadvertently given your API key to whoever is on the other end of that API.

The third problem. Whenever Claude makes any changes to files on your system, it stores a backup copy of the files in the Claude folder: ~/.claude/file-history. Any secret Claude reads is stored in plain text in the project transcript, and again in file-history if Claude edits the file.

Another less common, but potentially more severe issue is prompt injection. This is a hidden instruction within something Claude reads. For example Claude might read something on a web page somewhere with an instruction telling it to send passwords to a specific API endpoint. If Claude reads this, it might simply carry out the instruction and send the credentials on.

How to stop it

The simplest way is to ask Claude to block itself from reading your env or config file. It will add a setting to .claude/settings.local.json to block itself from viewing the file. That file is just for you and stays out of git. If you want the block shared with everyone who uses the project, it goes in .claude/settings.json instead.

It's also worth mentioning that if you're using Claude Remote Control or SSH, Claude uses the settings.json of the remote computer, not the computer you're in front of.

If you want to pre-block all env and config files, try this tool and place the result in your .claude/settings.local.json file yourself: Secrets lockout generator

Note that these blocks aren't airtight. The rules for Claude's own file tools hold, but the command rules only block the commands they list. Claude could still use something like "more" or "sed", run a one-line Python script, or copy the file under another name. It could also edit the settings file to remove the block, though Claude Code normally asks you before it does. This isn't perfect. If you're storing nuclear launch codes, I'd probably just not store them in plain text or put them somewhere outside the folder Claude can see.

What to do if Claude reads your env

No need to panic, but you will need to rotate any key or reset any password Claude has seen. Claude will often tell you this itself. I've made this mistake more than once and Claude has advised me to rotate the keys it's seen.

I write every post myself. AI only helps fix typos and tidy repetition.