Paper-cut illustration of glowing keys locked in a small safe above a desk of scattered loose papers and folders

Quick answer

To store AI API keys safely, keep them in one place you control, never inside the files you share. Use a password manager or secrets store as the master copy, load keys into tools through environment (.env) files that are excluded from code repositories and shared folders, and never paste a key directly into a skill, prompt or plugin setting you did not write. Give each app its own key, delete the ones you no longer use, and check new plugins before installing them. A 30-minute tidy-up removes most of the easy ways a key leaks.

Key takeaways

  • Keep a master copy of each key in a password manager, not in a text file
  • A .env file is fine for local tools if it never reaches GitHub or a shared folder
  • Search for keys hiding in skills, prompts and notes, and move them out
  • Only give plugins keys from makers you trust, and use a separate key for each
  • Use one key per app so a leak can be shut down without breaking everything
  • Pair good storage with a spending limit, because no storage method is perfect

📘 Main article: This guide supports The OpenCode Breach: How to Protect Your AI API Keys Now. It covers the “skills, env files and plugins” risks from that article in practical detail.

Most leaked keys are not stolen by clever hacking. They sit in a file, a note or a plugin setting that someone else can reach.

This guide answers one question: how do you store AI API keys safely in env files, skills and plugins? It builds on our main article, The OpenCode Breach: How to Protect Your AI API Keys Now, where Mark Kashef warns that people have stopped checking where their keys end up.

Where do AI API keys usually leak from?

From convenience. Mark lists three quiet risks: skills with a key written straight into them, env files holding every key you own, and plugins nobody checked. We would add a few more common ones:

PlaceWhy it is risky
Skills and prompt filesThey get shared, copied into other tools, or published with the key still inside
.env filesEasy to commit to a code repository or sync into a shared folder by accident
Plugins and add-onsYou hand the key to someone else’s code, which may store or send it
Notes, chats and docsKeys pasted “just for a minute” stay searchable for years
Third-party dashboardsAs OpenCode showed, a provider holding your key can itself be breached

How do you store AI API keys safely?

  1. List every key you have created, by provider, and what each one is for.
  2. Save the master copy of each key in a password manager or secrets store.
  3. Search your computer and cloud drive for key patterns, such as text starting sk-, and for words like “api_key”.
  4. Move any key you find out of skills, notes and documents, then delete it from that file.
  5. Replace any key that was ever shared or committed, by deleting it at the provider and creating a new one.
  6. Give each app its own key and name it after the app.
  7. Set a spending limit on every provider, following How to Set an AI API Spending Limit and Usage Alert.

⚠️ Warning: Removing a key from a file does not make it safe if the file was already shared or pushed to GitHub. Copies may exist elsewhere, so delete the key at the provider and make a new one.

How should you handle .env files?

Keep them local, minimal and out of anything you share. A .env file is a plain text file that tools read for settings such as keys.

  • Add .env to your .gitignore so it is never committed to a repository
  • Keep it out of synced folders such as Dropbox, OneDrive or Google Drive
  • Only include the keys that project needs, not every key you own
  • Share a .env.example file with blank values if others need to know the format
  • If you ask an AI coding agent to set up a project, check it has not written keys into other files

💡 Tip: If you use Codex or Claude Code, our guide to auditing your Claude and Codex setup is a good moment to check old projects for leftover .env files too.

How do you check skills and plugins for keys?

Read before you install, and never paste your main key into something you cannot inspect.

  • Open the skill file and look for anything that looks like a key or a web address it sends data to
  • Check who made a plugin, when it was last updated and what permissions it asks for
  • Use a separate, low-limit key for any plugin you are trying out
  • Remove plugins you no longer use, and delete their keys at the provider

Our three-question test for new AI skills and plugin checklist give you a quick routine. Mark also mentions Lockpick, a free scanner built by his own team, which is one option among several.

Which storage option fits you?

OptionGood forWatch out for
Password managerMaster copies, solo users, small teamsCopying keys out into insecure places
.env fileLocal scripts and coding toolsAccidental commits and synced folders
Platform secrets settingsHosted apps and automations, such as a hosting dashboard’s environment variablesWho else has access to that dashboard
Dedicated secrets managerTeams with several apps and peopleMore setup than most solo users need

What mistakes should you avoid?

  • Pasting keys into chats, emails or shared docs
  • Using one key across every tool and plugin
  • Assuming a private repository is a safe place for keys
  • Forgetting old projects that still hold working keys
  • Skipping the spending limit because storage “feels” secure

Frequently asked questions

Is it safe to put an API key in a .env file?

Generally yes for local tools, as long as the file is in .gitignore, not in a synced folder, and only holds the keys that project needs.

Can I put my API key inside a custom GPT or skill?

Avoid it. Skills and prompts are easy to share or copy, and the key travels with them.

What should I do if I committed a key to GitHub?

Delete the key at the provider straight away and create a new one. Removing it from the code alone is not enough.

Are AI plugins safe to give API keys to?

Only if you trust the maker and can limit the damage. Use a separate key with a low spending limit for each plugin.

How often should I rotate AI API keys?

Rotate straight away after any suspected leak, and review your keys at least every few months.

The bottom line

Storing AI API keys safely is mostly about tidiness. Keep one master copy in a password manager, keep .env files local and out of repositories, take keys out of skills and notes, and give each plugin its own low-limit key. Then add a spending cap, because even good storage can fail.

author avatar
Garry Knight
I'm Garry Knight, the person behind Prodify Digital. I write about email list building, email marketing, SEO, AI search and the tools that connect them. My aim is to make online marketing easier to understand, so creators and small business owners can make informed decisions about building an audience and keeping people engaged. Here you'll find straightforward guides and product reviews that explain what something does, where it fits and which limitations matter. The focus is on clear explanations and useful next steps—not hype, shortcuts or promises of easy earnings.
3 thoughts on “How to Store AI API Keys Safely in Env Files, Skills and Plugins”

Leave a Reply