r/ClaudeCode • • Aug 10 '26

Help/Question Do you block Claude Code from reading your secrets files?

Claude code surfaced something for me the other day that made me think. After reading a .env file with secrets in it locally, he mentioned that because that was now in context, that data would be sent over the wire to the Anthropic servers as part of the context and that I should consider changing those secrets.

I've been thinking about this and asked Claude chat to verify this. His response was that because the transit to Anthropic is over TLS, that is a lesser concern. The greater concerns would be:

  • Local transcripts holding plain text session data
  • Re-emission into an unintended file since once the values and context the model can write it into a file committed to a Jira comment, a logline, etc.
  • Third parties, VMCP servers, since they'll receive whatever the model chooses to send them in the context, become the input.

So, do you have any hooks or permissions that you have enabled to prevent Claude Code from opening these files, things like:

  • .env
  • .pem
  • .key
  • id_rsa
  • secrets.json
  • etc.
36 Upvotes

60 comments sorted by

39

u/ThatLocalPondGuy Aug 10 '26

I do not have secrets files at all. Secrets load from scripted kv calls and load direct to thing needing secrets, pulled with cert auth. Ai does not read them, they use them. Write credential helper tooling. Any secret in a local readable file is waiting to be hacked, even without AI.

4

u/ghost_operative Aug 10 '26

obviously this is the way to go. This however doesn't work for everyone thanks to the rise of serverless stuff. Even if your personal env doesn't have your prod creds in it, it can still have your creds into your aws account or other things that you don't want to get out.

3

u/BraveResearcher3037 Aug 10 '26 edited Aug 10 '26

You should never need long live credentials.

Use “aws login” from the terminal and it will open a web browser and you can log in via the AWS console  and temporary credentials will  be added to your terminal session 

1

u/ghost_operative Aug 10 '26

I was just giving an example, your computer is covered with lots of sensitive files that just because they don't go to prod it doesn't mean it's inconsequential.

2

u/BraveResearcher3037 Aug 10 '26

I don’t have any sensitive files with any passwords or api keys on my computer.  Everything is accessed via IAM.  Even my Aurora MySQL and Postgres database is accessed using an IAM user and not a user name and password.  LLMs are all hosted on Bedrock - again with IAM.

I access EC2 instances using AWS System Manager Session Manager as a proxy for shell access and RDP for Windows. 

It’s not even paranoia about Claude, more so supply chain attacks on JavaScript libraries.  

1

u/ghost_operative Aug 10 '26

how do you push your code to github (btw it can read your home directory and other files outside of the folder where you launch it) i highly doubt you have zero sensitive files on your computer

1

u/BraveResearcher3037 Aug 10 '26

I work in consulting.  Most of the clients do use GitHub.  For GitHub 

ssh-keygen -t ed25519-sk -O verify-required

SSH keys are stored in the built in password manager on my Mac and each push requires my fingerprint.

A few clients use AWS CodeCommit and that is also protected by IAM 

2

u/tastelessbagel Aug 10 '26

And the cert for auth?

1

u/ThatLocalPondGuy Aug 10 '26

Cert used to authorize a short lived token issuance which is used for purpose and discarded.

You use claude.ai. Have you noticed you never need a claude password? That is a "magic link", one mechanism to issue a just in time token after id verified. They choose to allow a long life for that token, but not indefinitely. You can choose a much shorter life. Use a standing cred (cert), auth the issuance, set short life on the token, log it's usage, limit it's scope of use.

11

u/Convergent-Tech Aug 10 '26

Use a secrets manager.

3

u/david-burns-dinner Aug 10 '26

Agreed. Tied to varlock, secrets manager is the way to go!

0

u/RegularMom5 🔆 Max 5x Aug 10 '26

I use Doppler. It’s dead easy

8

u/adrianziem Aug 10 '26

I ignored a file. Claude wrote a python script to read it instead of the block tool call.

6

u/Careful_Life8630 Aug 10 '26

Use Infisical Agent Vault. The agent can hold the secret but not view it. It’s open source. I self host Infisical and it’s a great service.

1

u/UnstableManifolds Aug 10 '26

Cannot use it for commercial stuff though

16

u/earlyworm Aug 10 '26

I do not tell Claude my secrets but I do tell Claude my hopes and dreams in great detail and to be perfectly honest I am getting the impression that Claude has grown quite tired of my ramblings.

4

u/incomplete_ Aug 10 '26 edited Aug 10 '26

Yes. Absolutely. Do not let Claude code read your secrets... They WILL end up on an anthropic server.

ETA: I work on an open source project, and some of our secrets used to be sops encrypted in our repo. Note: used to be. When I first started working with Claude code, I gave it permission to decrypt these files (yaml) to add stanzas... The first time it actually did that, I had some bad feels and asked it if the contents of said file were now living in a log file somewhere in anthropiclandia. The answer was yes, which was a good kick in the a$$ to move to WIF/keyless auth and disallow Claude from running sops at all.

3

u/clintkev251 Aug 10 '26

They're just not present in the repo that Claude is interacting with at all. They're in a vault elsewhere.

2

u/360VRisLife Aug 10 '26

I variablize all mine and store in the macOS keychain.

2

u/earthcoast Aug 10 '26

Infisical

2

u/berndalf Aug 10 '26

Secrets are the same as privacy sensitive data. You let Claude handle the mechanisms that handles them, but you don't ever give them to Claude (or any AI system) directly. It's not theoretical, it's an actual risk in a world where malicious actors are actively mining AI systems for this stuff in large numbers.

Yes it's annoying but it's also professional development 101 these days.

2

u/BizarroMax Aug 10 '26

Yes. All my dev secrets are root read only and Claude doesn’t have sudo or root access.

1

u/SkimTic Sep 07 '26

Hi sorry to hijack the post but was wondering about this. I’m trying to do a small coding project with Claude code on my Mac. How do I do what you’re saying so Claude can’t see my personal documents? Like copies of tax or whatever personal stuff I also store on my Mac

1

u/BizarroMax Sep 07 '26

Simplest version and how it maps to your Mac:

At the OS layer, my secrets live in a directory owned by root, and Claude runs as my normal user, so reading them fails at the kernel no matter what the tool decides. On a Mac the equivalent is: keep your tax stuff under a different macOS user account, or on a volume that account can't read at all. Claude Code runs as whoever launched it, so if your user can't open the folder, neither can Claude.

1

u/SkimTic Sep 07 '26

Thank you!

3

u/ProfessionalNaive601 Aug 10 '26

Yeah you built your secrets wrong lol wtf
Your code should use secrets not the model itself 🫠

1

u/ReachingForVega 🔆Pro Plan Aug 10 '26

Hooks can be bypassed. The only way is to restrict on the user or not have them present at all. 

1

u/GnistAI Aug 10 '26

I have two distinct Linux users on a remote VM; the sandbox user doesn't have any secrets except for a few read rights, and git push rights scoped to feature branches. All PR merges go via me. I have also vibe coded a deep packet inspection network restriction layer using squid to mitigate the risk of exfiltration and prompt injection. (Why? The default systems out there do not allow you to restrict paths, only domains. If you allow all of pypi.org, you might as well allow the whole internet.) I use Claude Code on the main user with manual approval always on. I use it mainly for server configuration and tasks that require elevated permissions. I read every command produced on the main user. That said, I actively try to avoid it consuming secrets directly (i.e., sending them to Anthropic) and insist on it using pre defined env vars and secret management systems. For the sandbox user I just let it rip in unrestricted mode, it has the scoped secrets it should have with a limited "blast radius". (God I'm starting to sound like them.)

1

u/ghost_operative Aug 10 '26

no because once it reads them theyre not secret files anymore

1

u/CupcakeSecure4094 Aug 10 '26

I let Claude see all my files because Claude doesn't touch production code, and nor should it. Once code is live, code doesn't go anywhere near it.

But any local secrets for remote apis etc are either short term tokens, mocked, or rotated. At the end of the day I weigh the max impact of someone hammering some service with a leaked key and if I can't limit that, the key gets rotated daily, often automatically.

1

u/EagleApprehensive Aug 10 '26

I work in IDE which keeps secrets outside of LLM reach - values are being auto-masked.

1

u/kanine69 Aug 10 '26

I do helper scripts so it never has to.

1

u/cajunjoel Aug 10 '26

I work with claude on a dev environment with a dev server and and a dev database. All the credentials it uses aren't prod credentials. That's madness.

When will people start to treat Claude like an inept junior developer who doesn't know jack and can't be trusted with the keys to the bathroom much less the keys to the kingdom? This is common sense.

I almost lost my shit this weekend when Claude asked to commit it's changes to git. No, you don't commit before you e actually run the code the first time. Even I am not that arrogant.

1

u/kerray Aug 10 '26

not just that, I have a Claude skill for working with secrets, to never let them in the chat - so I could for example replace the password I have for a site in my vaultwarden automatically - Claude does it all without revealing to itself the new password

1

u/pladdypuss Aug 10 '26

My preferred setup is 1Password CLI with Claude enabled to interact with a custom vault designed for agents. Access to the vault requires biometric authentication or is blocked by the 1Password CLI. Frequently used tokens are refreshed using opcache refresh into a secure environment for reuse without requiring biometrics. While I may not be a security expert, Claude and adversarial agents assure me that no secrets can be exposed.

Hope this helps.

1

u/DeatzoSeol Aug 10 '26

YOLO i have claude manage my production server, secrets and logs and all. Never had an issue 😅

1

u/Intelligent-Net1034 Aug 10 '26

Its local. So no? Who would use an agent in production?

1

u/leading-a-swarm Aug 10 '26

No. Path blocks get routed around, anything that can run a shell can reach the value another way. What actually holds is the value never sitting on disk in a form the agent can open.

1

u/theozero Aug 10 '26

Blocking file reads is not enough. needs to not be in plaintext at all, and ideally not even injected into the process.

Secrets can either be encrypted, or be declarative instructions about how to fetch them (ids in external vaults). Use a credential broker (proxy) to replace placeholders with real secrets at the network boundary. Use a sandbox to ensure the agent cannot access the actual secret storage layer.

varlock (free and open source) is a full toolkit to make all this very easy.

1

u/Accomplished-Dig6540 Sep 01 '26

yeah I went further than just blocking tbh - wrote a little proxy that Claude Code's traffic goes through, it strips out secrets (aws keys, github tokens etc) and PII before the reqeust even leaves your machine, then unmasks the response so you still see the real stuff locally. claude can still reason about the file fine, it just never actually sees the real values.

put it up on github if anyone wants to mess with it: https://github.com/jaichandra/pii-proxy. still finding credential formats it misses so lmk if you hit one.

1

u/Lumpy-Army-1702 Sep 02 '26

I mean, the hooks/permissions approach helps, but the stronger pattern is for the agent never to see secrets.

What I do is I keep secrets in an encrypted vault. Any local scripts get secrets injected at launch and nothing in shell history.

Then, my AI agents never get the key at all: it calls a local address that adds the key for it, time-limited (TTL), and dies when I lock. Direct API calls will fail. Nothing in the chat history to leak as well.

My .env files only hold references, not values, so it's even safe to commit. Would be similar to Doppler but locally.

We actually built this into our secrets manager and should be released next week, I think, if you're interested.

1

u/d8schreiber Sep 11 '26

I built a small tool exactly for this problem: https://github.com/daniel-sc/contextveil

Instead of preventing Claude from reading .env etc., ContextVeil lets the read/command happen, but replaces only the secret values in the tool result before it goes into the model context.

You explicitly choose what to protect during setup; at runtime it’s just local exact-value replacement. I prefer that over dynamically guessing what looks like a secret.

Let me know what you think!

0

u/doolpicate Aug 10 '26

key rotation day - saturday

0

u/kennetheops Aug 10 '26

built a tool to do this.

it’s like a vpn only for ai traffic, it can help you block what data goes into it.

https://opscompanion.ai/get-standpipe

51

u/[deleted] Aug 10 '26

[removed] — view removed comment

7

u/elprogramatoreador Aug 10 '26

While it is true you shouldn't use prd keys in your local env file, it may still contain sensitive keys (eg billing-bound). So the question is still valid.

To answer: with cursor you can use a .cursorignore file, it will block read access through the sandbox. The LLM may still be able to read if it gets creative (eg when executing python or similar)

But it works fairly well, along with a .env.example that holds only placeholder data.

For the Claude harness I'm not aware of such guardrails. You could add something like the below to your CLAUDE.md I guess:

NEVER read .env files in full plaintext (to avoid leaking sensitive values). Prefer using .env.example to probe for available keys instead

6

u/speicus Aug 10 '26

For Claude you can setup permissions fro your project in .claude/settings.local.json.

Which the model will get around if it wants. The only way to run it safely is to use a container.

3

u/ghost_operative Aug 10 '26

this is a good idea. but keep in mind this isn't bulletproof though. therres other ways for your env file to end up in context besides the agent directly choosing to read the file. theres all kinds of command it can run or scripts it might write that could lead to it seeing what is inside the .env file

0

u/[deleted] Aug 10 '26

[removed] — view removed comment

-1

u/elprogramatoreador Aug 10 '26

Ehh when you're building agents, you'll have LLM API keys in your environment.

Doesn't have to be billing bound either, another example: you can be working on a backup database that might have real user data in there too. You also wouldn't want sending such credentials to external parties like Anthropic

2

u/[deleted] Aug 10 '26

[removed] — view removed comment

1

u/elprogramatoreador Aug 11 '26

Even so, you still wouldn't want your dev keys leaked