Orbit

So your agent pushed your API key to GitHub (and why deleting it doesn't fix anything)

Chris Rupp

You ask your agent to add some AI to your app, it works on the first try, you’re thrilled… and then you scroll through the code and notice it pasted your OpenAI key right in there in plain text, and already pushed the whole thing up to GitHub. That’s a real problem, cuz there are bots crawling GitHub all day long looking for exactly that, and if one found yours, somebody else can use it and the charges land on YOUR bill. I already spend around $600 a month on AI on purpose, so the idea of someone else adding to that on my key is… not great. It’s worth understanding before it happens to you, and if it already has, the fix is honestly pretty quick once you know which part actually matters.

An API key is basically a password for a service. Whoever has it can use that service as you, and spend your money doing it, which makes it a secret… and the one rule for secrets is that they never go inside your code. Code gets copied and shared and pushed all over the place (that’s kind of the whole point of it), and secrets shouldn’t be traveling along with it. Agents don’t always follow that rule on their own, since pasting the key right in is the quickest way to get the thing working, so it’s on you to know it even if you never write a line of code yourself.

If it already leaked

The natural first move is to delete the key from the file and push again, and that doesn’t fix it. Git keeps every save point (the same thing that makes it so useful when your agent breaks something), so the key is still sitting in your project’s history where anyone who can see the repo can dig it up. The real fix happens over at the service that gave you the key. Go into the provider’s dashboard (for OpenAI that’s the API keys page), revoke the old key so it stops working, and make a new one… swapping an old key for a new one like that is called rotating.

Once the old key is revoked it doesn’t matter who copied it, it’s useless to them. While you’re in the dashboard, check the usage or billing page for anything you don’t recognize. You can go back and scrub the key out of your Git history too if you want, but once it’s revoked that part’s optional… revoking is what actually protects you.

Where keys actually go

Keys go in a separate file called .env (you say it “dot env”). Your code doesn’t hold the key itself, it just asks for it by name, and the value comes from that file when the app runs… a named value like that is called an environment variable. Then a second file called .gitignore tells Git which files to never save, and you put .env on that list so Git leaves it alone. Your code goes to GitHub, and the key stays home on your machine.

# .env (stays on your computer)
OPENAI_API_KEY=your-key-goes-here

# .gitignore (tells Git what never to save)
.env

You don’t have to set any of this up by hand. Just ask your agent to move your keys into .env and make sure .env is listed in .gitignore, ideally before the first push on any project that uses a key, cuz that’s a lot less hassle than rotating after the fact. One more gotcha that catches people even after they’ve done all that is that if your app runs entirely in the browser, anything the browser can read is visible to your visitors, and that includes .env values that get baked into the frontend build. Anything that needs a secret key should go through a server or a serverless function instead, and again, your agent can move it there if you ask.

The .env file covers your own computer, but once your app is live on a hosting site like Vercel or Railway, you put the keys in that host’s settings as environment variables and your app reads them from there, so the key still never goes in the code.

This is a big part of why there’s a vault built into Orbit, the massive AI orchestration program I’ve been building since back in March (in Alpha now for free!). It keeps your API keys on your own machine, encrypted with AES-256-GCM, and they’re never sent to Sivants, my company. You can scope a key globally or to a single project, reveals are timed so a key isn’t just sitting on your screen, and there are backups plus a recovery phrase so you don’t lock yourself out. Orbit also checks every commit and every push in your projects now for API keys and other credentials, and blocks it if one slipped in, so the mistake from the top of this post gets stopped before anything reaches GitHub… and the push check looks at every commit going out, not just the latest one, so even a key your agent added and then deleted still gets caught (cuz like we covered, it’s still sitting in the history).

If you wanna go deeper, the Learning Atlas path for this one walks through the rest of the words in order (environment variable, Git history, revoke, rotation, vault, and least privilege, which is the idea of giving every tool only the access it actually needs), along with the full video. It’s free and you don’t need Orbit for any of it: the Learning Atlas path

And if you’re curious about Orbit itself, it’s a desktop app for Windows and macOS, and it can run your Ubuntu projects too, free for everyone who joins during the alpha… you can grab an invite here: grab an invite

Always happy to hear what people think.