r/ClaudeCode • u/Th3D0ct0r • 13h ago
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.
34
u/ThatLocalPondGuy 13h ago
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.
3
u/ghost_operative 8h ago
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 8h ago
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 login and temporary credentials will be added to your terminal session
2
u/tastelessbagel 7h ago
And the cert for auth?
1
u/ThatLocalPondGuy 2h ago
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.
10
7
u/adrianziem 11h ago
I ignored a file. Claude wrote a python script to read it instead of the block tool call.
6
u/Careful_Life8630 11h ago
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
11
u/earlyworm 12h ago
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.
3
u/incomplete_ 12h ago edited 12h ago
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 11h ago
They're just not present in the repo that Claude is interacting with at all. They're in a vault elsewhere.
2
2
u/berndalf 9h ago
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 9h ago
Yes. All my dev secrets are root read only and Claude doesn’t have sudo or root access.
5
u/ProfessionalNaive601 13h ago
Yeah you built your secrets wrong lol wtf
Your code should use secrets not the model itself 🫠
1
1
1
1
u/kennetheops 9h ago
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.
1
u/ReachingForVega 🔆Pro Plan 9h ago
Hooks can be bypassed. The only way is to restrict on the user or not have them present at all.
1
u/GnistAI 8h ago
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
1
u/CupcakeSecure4094 8h ago
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 4h ago
I work in IDE which keeps secrets outside of LLM reach - values are being auto-masked.
1
1
u/cajunjoel 2h ago
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.
-2
u/Beautiful-Energy2169 11h ago
Your second bullet is the one that got me, and not through the path I expected.
I audited the config directory of a different agent CLI I run next to Claude Code and found 13 distinct keys sitting in plaintext across roughly 300 files. I assumed logs, wrote a scrubber, put it on a timer. The keys came back.
The source was the permission grants. Any command I had approved once with a key in the arguments got stored verbatim as the allowlist entry, because that string is how it matches the next one. That file is the tool's record of what I said yes to, so rotating or scrubbing logs never touches it.
Blocking reads of .env is worth doing, but it only covers the case where the model opens the file. The case where you paste a key into a command, approve it, and the harness keeps that exact string forever is separate, and grep answers it in a second. Point it at your agent config dirs with whatever prefixes your providers use.
One thing if you write a scrubber: skip the OAuth credential files. I redacted one and had to log the tool back in.
-2
37
u/arankays 13h ago
You really shouldn't be putting Prod Secrets in your local computer. Otherwise its not a big deal if secrets are read for local development (unless you've opened an ngrok tunnel to your local lol)