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:
| Place | Why it is risky |
|---|---|
| Skills and prompt files | They get shared, copied into other tools, or published with the key still inside |
| .env files | Easy to commit to a code repository or sync into a shared folder by accident |
| Plugins and add-ons | You hand the key to someone else’s code, which may store or send it |
| Notes, chats and docs | Keys pasted “just for a minute” stay searchable for years |
| Third-party dashboards | As OpenCode showed, a provider holding your key can itself be breached |
How do you store AI API keys safely?
- List every key you have created, by provider, and what each one is for.
- Save the master copy of each key in a password manager or secrets store.
- Search your computer and cloud drive for key patterns, such as text starting
sk-, and for words like “api_key”. - Move any key you find out of skills, notes and documents, then delete it from that file.
- Replace any key that was ever shared or committed, by deleting it at the provider and creating a new one.
- Give each app its own key and name it after the app.
- 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
.envto 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?
| Option | Good for | Watch out for |
|---|---|---|
| Password manager | Master copies, solo users, small teams | Copying keys out into insecure places |
| .env file | Local scripts and coding tools | Accidental commits and synced folders |
| Platform secrets settings | Hosted apps and automations, such as a hosting dashboard’s environment variables | Who else has access to that dashboard |
| Dedicated secrets manager | Teams with several apps and people | More 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
Finish the job: pair safe storage with a cap and alert using How to Set an AI API Spending Limit and Usage Alert.
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.
Related posts
- How to Audit Your Claude and Codex Setup and Clear Out AI Clutter
- Should You Install a New AI Skill? A Simple 3-Question Test
- How to Keep Your AI Agent Safe When It Browses the Open Web

[…] How to Store AI API Keys Safely in Env Files, Skills and Plugins — where keys leak from on your own computer and how to tidy them up safely. […]
[…] your fixed prompt to “save” them for later. Caching is about cost and speed, not storage. See How to Store AI API Keys Safely in Env Files, Skills and Plugins for how to handle keys […]
[…] Store keys safely, as covered in How to Store AI API Keys Safely in Env Files, Skills and Plugins […]