The email

I was hacked recently.

One day I woke up to an OpenAI email notification, telling me that there was suspicious activity in my account.

Worrying notification

It’s the kind of notification where you go, oh, crap, it’s me who’s the fool now, I got hacked.

I quickly logged in to my account, went to the project overview and got hit with the lovely fella of “Hey, you’ve gone beyond your limit, didn’t you know that hard limits are not a default option, moron? Anyway, you owe us 40 bucks now”.

The Bill

Luckily, I use OpenAI only for a handful of custom projects, no real scale, so I was only in a $100 spending tier, thank god. It’s not the largest chunk of money, but enough to quickly understand that the way I used to manage security on my local computer, especially with all the agentic stuff, was not appropriate and ridiculously naive.

After digging around the shell history and clauding my way through all things that could happen I was able to pinpoint the likely cause of the API key exposure.

What happened

See, beyond Claude Code I also use pi to access OpenAI models and DeepSeek (to play around and get some idea about the state of different models and their capabilities). To access DeepSeek I use OpenRouter, an LLM router that handles a myriad of different models and allows you to use a single API key to access all of them in one go. Convenient, fairly priced, a dream. A dangerous dream, if you think about it. Basically it’s the gateway to get all of the data your agent was able to read to any kind of a provider, and Zero Data Retention may be a difficult thing to tackle and check, what’s more important.

I don’t usually run this set-up for anything important, but I was careless and stupid, and did not have any protection for my lovely Pi terminal, so one day, a month before the hacking incident, during one of the Pi sessions a DeepSeek model reached for one of my .env files, that contained an OpenAI key I was using for running some local evals (that, of course, did not have a hard limit, had a pretty long expiration time and was lying in plaintext because comfort).

The agent read it, it went through the OpenRouter infrastructure, reached one of the providers for DeepSeek and somewhere along this way was exposed.

What happened after that is a mystery, but after a month my key became the property of some Chinese guy(s?) doing their not even nasty things with that key for their coding and work purposes. Of course with OpenAI Astra model.

Definitely not my API comms

Where I was wrong

Well, I was wrong with a lot of things, in a very stupid manner. I ran coding agents in YOLO mode, able to access almost everything on my machine. I had a bunch of projects with .env files, like I’m vibe-coding an Uber-Tinder clone for horses. I had my SSH private keys lying in plaintext (well, with proper permissions, but who cares if an agent runs with your permission anyway?), some of them without passphrases. I allowed agents to curl https://random-cool-shit.sh | bash. I installed some skills from the internet without checking them first and ran playwright installations and uv / pnpm installations like it’s normal and it’s not 2026. I brew install’ed some weird crap. I have a gazillion local projects I vibed my way out of w/o even knowing the languages and the tooling they were written in. I’m sorry for myself, I was ruthless, and I paid for it, luckily not the largest price. And I consider myself a tech-savvy person, yeah.

Yeah

The redemption arc

Chronic remorse, as all the moralists are agreed, is a most undesirable sentiment. If you have behaved badly, repent, make what amends you can and address yourself to the task of behaving better next time. On no account brood over your wrongdoing. Rolling in the muck is not the best way of getting clean.

As Aldous Huxley once wrote.

I spent the next several days auditing my machine, building and executing a plan for a better, more secure me (w/ Claude Code by my side OF COURSE).

What I was able to accomplish:

Damage control

  • OpenAI support confirmed the leak and replied no to a refund. Fair enough, it’s a $40 lesson.
  • Every OpenAI key that was on my or any other machine (especially in any .env file or agent transcript) is revoked.
  • Hard limits are now on for the organization and for every project. There’s also a model allow-list, so even a stolen key can only call the handful of models. At least no more Astra for you, my lovely hacker.
  • My OpenRouter key has a guardrail: an allow-list of providers, zero data retention only, and a budget. The old keys are gone.
  • I logged out of Claude Code everywhere and logged back in. During the audit I found a little menu-bar usage tracker that kept my Claude OAuth tokens in a plaintext configuration. In itself it’s not scary, but no more plaintext secrets.

No secrets on disk

  • 1Password is the only place secrets live. Every project’s .env became a .env.tpl that only holds op:// references, and secrets get injected at runtime with op run / op inject. Deploy configs are rendered straight to the server and never touch the disk in plaintext. (I will think how to harden servers themselves later). I’ve already been paying for 1Password for years, so it was only logical to proceed with it. It’s a SPOF, but at least a trusted one.
  • SOPS/age. For some infra projects where I use Ansible I also use SOPS + age, but I stored my private encryption key locally. It now lives in 1Password and is protected by Touch ID.
  • SSH keys live in the 1Password SSH agent, so the private keys aren’t files on disk anymore. Every use needs Touch ID, once per session.
  • Anything that was plaintext and nearby got rotated: bot tokens, SaaS keys, SSH keys, any keys or credentials. That was really, really, really boring and long.

Agents are on a leash

Well, leash is too strong of a word. These clankers are too smart and can break out of anything, given enough time and effort, so don’t be fooled by any security gates that aren’t a physically separated, network-isolated machine in the bunker.

  • Claude Code has deny rules for every secret file it could reach: .env and its variants, SSH keys, transcripts, auth files, and commands like op, sops and security find-generic-password. I could have sandboxed Claude Code as well, but auto mode combination, lack of secrets access on the machine and deny rules feels enough of a compromise for me right now between the comfort and security.
  • Pi only runs inside a sandbox (srt). It can only touch my personal projects, minus .env* and key files, and all of its network traffic goes through a local proxy that logs every host it talks to.

Supply chain

On top of that in light of all the recent and not so recent supply chain attacks I decided to secure my machine a little bit more as well:

  • I checked about 30k installed package versions (laptop, dev box, server) against a catalogue of 144 supply-chain incidents from the last year. There were zero exact matches, a few uncomfortably close ones, and no known campaign indicators on disk.
  • Cooldowns everywhere. npm has min-release-age=7 and strict-allow-scripts=true, so no install scripts run unless I approve them. pnpm has minimumReleaseAge, and uv has exclude-newer = "7 days". Most malicious releases get caught and pulled within days, and I’m fine being a week behind.
  • MCP servers are pinned to exact versions. A Claude Code hook blocks curl | sh and any unpinned npx / uvx / pnpm dlx, so “just run the latest thing from the internet” isn’t an option anymore.
  • Homebrew got audited. Anything I couldn’t explain is gone, sketchy taps are removed, and what’s left is in a Brewfile.
  • SHA pinning for containers. I self-host a bunch of services and now I pin SHA hashes for all of them.
  • SHA pinning for GitHub Actions. Same goes for GitHub Actions.

Guard rails for future me

  • A global gitleaks pre-commit hook in every repo (git’s config-based hooks, so repo-local hooks keep working). I also scanned the history of every repo once. It found an ancient Docker Hub password in a public repo from 2018. Dead, thankfully.
  • Dotfiles are in chezmoi (private repo): the Brewfile, shell config, the sandbox policy, the package-manager cooldowns, the hook. If the laptop dies tomorrow, the hardened setup comes back with it.
  • Agent transcripts that had secrets in them are deleted.

Is it enough?

Well, no. 1Password can get hacked. RCE 10 or whatever can be in my macOS kernel. The sandboxes could get their escapes. Human errors are still possible. My remote machines can have crazy backdoors.

But I feel at least a little bit safer against the specific threat I faced. I’ve stopped rolling in muck; I’ve got my bar of soap.

Be safe, don’t blindly trust your agents, or the $40 bill could be $4,000.