Find and hide the API keys in your app
The prompt from the reel. Paste it into Claude Code and it'll find every key in your project, move the secret ones to your server, and tell you which ones you've got to replace.
How to use it
- Open your project in Claude Code (Cursor, Codex or any AI coding tool that can read your files works too).
- Copy the prompt and paste it in.
- Read the list of keys it finds before you let it change anything.
- For every key on the "exposed" list: open the provider's dashboard (for example the API keys page in the Anthropic Console or on the OpenAI platform), delete the key and create a new one. Put the new one only in your server's environment variables. That's about 1 minute per key.
The prompt
Find every API key and secret in this project and make sure none of them can reach a browser, an app bundle or a public repo. 1. Search the whole project for anything that looks like a secret: API keys (for example ones starting sk-, sk-ant-, sk_live_, AIza, ghp_ or xox), access tokens, passwords, private keys and database connection strings. Look in source code, config files, .env files and build output. List each one with its file and line, and say whether it can reach a browser, the app bundle or a public repo. 2. Some keys are meant to be public, like Stripe publishable keys, Supabase anon keys and Firebase web config. Say which ones those are and leave them, but check that the database rules behind them are switched on. 3. Search the git history too (git log -p), not only the current files. A key that was committed once is still in the history, even if a later commit deleted it. 4. Move every secret the browser or the app can see onto the server: a server-side environment variable, used only by a server route or function that makes the call on the app's behalf. Never put secrets in variables the framework sends to the browser, such as NEXT_PUBLIC_, VITE_, EXPO_PUBLIC_ or REACT_APP_. 5. Make sure that new server route can't be used by strangers as a free pass to the AI provider: require a signed-in user and add a rate limit, for example 20 requests a minute per user. 6. Add .env files to .gitignore, and add a .env.example that lists the variable names with no values. 7. Finish with a list of every key that was ever exposed (in app code, a public repo or the git history), so I can cancel it in the provider's dashboard and make a new one. Moving a leaked key is not enough; it has to be replaced. Show me each change before you make it, and never print the value of a secret in your replies.
Why a key in your app is public
When someone opens your site or app, their phone or laptop downloads everything it needs to run, and that includes any key you put in the code. Check your own site in Chrome: press Cmd+Option+I (Ctrl+Shift+I on Windows), open the Sources tab, press Cmd+Option+F and search for the first 6 letters of your key. If it shows up for you, it'll show up for anyone.
The hotel, decoded
- The hotel
- The AI provider (Anthropic, OpenAI). It runs the service and sends you the bill.
- Your key card
- Your API key. Anything ordered with it goes on your bill.
- Dropping it in the lobby
- Putting the key in your app or website code. Anyone who opens the app can read it.
- Someone ordering 6 lobsters
- A stranger using your key. You pay for every request they make, and you won't know until the bill comes.
- The safe behind the desk
- Your server. The app asks your server, and only the server holds the key and talks to the provider.
- Cancelling the card
- Deleting the key in the provider's dashboard and making a new one.
This is a starting point, not a security audit
It catches the most common way keys leak. It doesn't prove an app is safe. If your app takes payments or holds sensitive data, have someone who does this for a living review it. For a wider list, see 25 security checks.