Have you ever watched an AI assistant do something you explicitly did not want it to do, and then just… kept watching it happen session after session because you hadn’t gotten around to fixing it yet? That’s where I was with Claude Code and my API keys. And the honest answer to why I eventually fixed it is not some noble security principle. I just got tired.
Claude Code never printed my API keys in chat at first. For a while it was fine. Then it started doing it, and once it started, it wouldn’t quit. I’d be in the middle of building something, working through a problem with it, and there it was — a raw API key sitting in plain text in the chat session. Every time it happened I had to go rotate the key. Then re-wire whatever project was using it. Then keep going. I did that enough times in a single session that it stopped feeling like a minor annoyance and started feeling like a part-time job I didn’t sign up for.
That’s the actual reason I spun up Infisical. Not a threat model. Not a security audit. Friction. Plain, stupid, repetitive friction.
Infisical is a secrets manager — open source, self-hostable, and once it’s running it basically pulls your secrets from one central place on every deploy instead of you scattering .env files across six different project directories like breadcrumbs. I wired it into every project I had going. That part took some time, but it was a one-time investment, not a recurring tax.
The other half of the fix was a Secrets Guard I added to each repo. The idea is simple: if Claude Code tries to print a key into chat, the Secrets Guard strips it before it gets rendered. The LLM doesn’t get to decide whether your key shows up in the conversation. The guard makes that call before anything hits the screen.
Here’s the thing people don’t talk about much with AI coding assistants: they’re helpful in ways that can cost you if you’re not paying attention. Claude Code is genuinely good at what it does. That’s not the issue. The issue is that it operates on whatever context it has access to, and if your secrets are sitting in a plain .env file inside the project directory, they’re just… there. Available. The model isn’t trying to expose you. It doesn’t have a motive. It’s just working with what’s in front of it, and sometimes that includes things you’d rather it not repeat back to you in a chat window.
Pulling secrets out of the project directory entirely and into Infisical closes that loop. The project no longer has the keys sitting in a file. It fetches them at runtime. Claude Code can’t print what isn’t there.
The Secrets Guard is a backup for the cases I haven’t thought of yet. Belt and suspenders. I’ve been in IT long enough to know that the thing you didn’t account for is always the thing that bites you, so I’d rather have both layers and never need the second one than skip it and find out the hard way.
What I didn’t expect was how much cleaner the whole workflow would feel after. I’m not thinking about keys anymore. I’m not rotating them. I’m not updating four .env files when a key changes. It’s just handled. The mental overhead of managing secrets had apparently been sitting in the background taking up space, and I didn’t fully realize how much until it was gone.
If you’re running multiple projects locally and working with any kind of AI coding assistant, the .env file approach will eventually let you down. Not because it’s inherently bad, but because it scales terribly and it assumes a level of control over your context window that you don’t always have. A secrets manager isn’t overcomplicated for a homelab setup. It’s just the right tool.
Stop rotating keys. Fix the source.