The short version
- A secret is a password for software: an API key, token or database login that lets a program use a paid or private service as you.
- Common leaks are simple: a key pasted into a chat, typed into the code, or printed in a log, after which copies can sit in saved history.
- If a key leaks, revoke it and issue a new one first; GitHub says scrubbing it from code history is time-intensive and often unnecessary once the key is revoked.
- You can lower the risk by giving each key the least power it needs, keeping keys out of chat and code, and replacing them regularly.
- Ask your team three questions: where do keys live, who can read them, and how fast can we replace one?
On this page
- The short version
- What is an API key or secret?
- How do secrets leak when AI writes the software?
- What does it cost if a key leaks?
- What do you do the moment you find a leak?
- How do you keep secrets safe from the start?
- What can the tools do about it?
- Three questions to ask your team this week
- Conclusion
- Questions people ask
If you are wondering how to keep API keys and secrets safe when an AI agent builds your software, the short answer is this: keep them out of the chat, out of the code, and in a proper store. And know in advance how you would replace one quickly. A leaked key is a problem you can fix, but only if you know what it can do and how to switch it off.
This guide explains what a secret is, how one leaks in AI-assisted work, and what you can ask your team to do about it. No coding is needed to follow it.
What is an API key or secret?
A secret is a password that a program uses instead of a person. Your app needs one to send email, take card payments, read a database or call an AI model. ("API" just means a way for one program to talk to another.) The most common kinds are:
- API keys: a long string of characters that says "this request comes from this customer account". The company behind the service bills that account for whatever the key does.
- Tokens: a similar string, often short-lived, that grants access to something.
- Passwords and connection strings: the login for your database, with the address of where it lives.
The key point: anyone who holds the string can act as you. There is no second check. If someone finds your email-service key, they can send mail in your name, and the bill lands with you.
GitHub, which hosts much of the world's code, treats this as a real problem. Its secret scanning documentation says the scanner looks for hardcoded credentials, including API keys, passwords and tokens, and that it scans a project's entire Git history on all branches.
How do secrets leak when AI writes the software?
AI agents do not leak secrets out of malice. They leak them because the easiest way to make something work is to put the key right where it is needed. Four paths are worth knowing.
1. Someone pastes a key into the chat
You want the agent to connect to your payment provider, so you paste the key into the conversation. That is natural, and it is risky. A chat is a record of text, and the key is now part of it. Treat that key as exposed.
2. The key ends up written in the code
A key typed straight into a file is called "hardcoding". The OWASP secrets management guide notes that organisations often have secrets hardcoded in plaintext in their source code. Code gets copied, shared and stored with its full history. A key in code travels with it.
3. The key shows up in logs or screenshots
Agents run commands and print results. If a command prints a key, the output may end up in a log, a comment on a code change or a test screenshot. This is the least obvious path, because nobody typed the key anywhere.
4. The agent is tricked into revealing it
Text from outside, such as a web page or an issue someone filed, can contain hidden instructions aimed at an AI agent. This is called prompt injection. If keys are within the agent's reach, that is the risk. The best defence is that the agent cannot see the key at all.
What does it cost if a key leaks?
It depends on what the key can do. Think of three levels:
- Low: a key that can only read public data. Annoying to replace, little harm.
- Medium: a key for a paid service. A stranger can run up your bill.
- High: a key to your customer database or your cloud account. This can mean exposed customer data, deleted data or a stopped service.
Some help exists. GitHub says that when a secret from one of its partner companies is found, it notifies that provider, who can act on it, for example by revoking the credential. That covers only partner secrets, so do not count on it. Treat any key that touched a chat or a code file as possibly exposed.
What do you do the moment you find a leak?
Order matters. GitHub's advice is to rotate (replace) an affected credential as soon as you get an alert, and OWASP says exposed keys should "undergo immediate revocation".
- Revoke the key. In the service's dashboard, switch the old key off.
- Issue a new key and put it in the proper store, not in the chat or the code.
- Check usage. Look in the provider's dashboard at what the key was used for and when. This tells you whether anyone else used it.
- Clean up. Remove the key from files and logs. GitHub's page says that removing a secret from Git history is time-intensive and often unnecessary once you have revoked the credential. OWASP warns that rewriting history will break other links to a given commit, so weigh it first.
The common mistake is to delete the key from the file and stop there. The old key still works, and it is still in the history. Deleting does not undo exposure; only revoking does.
How do you keep secrets safe from the start?
You do not need to read code to apply these. They are decisions and questions.
Keep keys out of the chat
Ask your team or tool to give you a separate place to enter keys. If a tool offers a secret store, use it. Never paste a key into a free-text conversation as a shortcut.
Give each key the least power it needs
OWASP's principle is least privilege: give each secret only the minimum access its job needs. In practice, ask for a key that can only do the one job. A key that can send email but not read your contacts is a smaller loss than one that does everything.
Use separate keys for testing and for real customers
Many services offer test keys that connect to a practice account with fake data. If one leaks, nothing real is at risk. Ask that your agent builds and tests with test keys, and that the real keys exist only at release.
Plan to replace keys regularly
OWASP says to rotate secrets regularly so that stolen credentials only work for a short time. Ask your team how long it would take to change each key. If the answer is "we are not sure", fix that before you need it.
Keep a short list of what exists
For each key: what service, what it can do, who set it up, where it lives. One page is enough. Without it, a leak becomes a guessing game about what to revoke.
What can the tools do about it?
Good tools help. Claude Code's security page says its API keys and tokens are stored in the macOS Keychain when available. In its manual mode, most tools that make network requests need your approval by default, and you can add rules that block commands such as curl and wget. Those controls limit what a misled agent can do, but the page is clear that no system is completely immune to all attacks.
On Atlas, a secret pasted into the chat goes to a secret store first, and engineers never see cloud sign-ins. Its security scan also looks for passwords or keys committed in what changed on main. Atlas never decides spending, deleting data or sending anything outside for you; those wait for your say-so. Atlas does not replace the habit of using least-power keys and a quick replacement plan, which stay your job. You can read more on the Atlas home page.
Three questions to ask your team this week
- Where do our keys live? The answer should be a secret store or the hosting service's settings, never a chat or a code file.
- Who and what can read them? The answer should be a short list, and the AI agent should not be on it unless there is a reason.
- How fast can we replace one? A good answer is "quickly, and we have done it once as practice".
Conclusion
A secret is a password for software, and AI agents make it easy to put one in the wrong place. Keep keys out of chat and code, give each the least power it needs, and know how to revoke and replace one fast. If a leak happens, revoke first and tidy up after. That order is the difference between an annoying afternoon and a serious incident.
Questions people ask
What is an API key in simple terms?
It is a password a program uses to talk to a service on your behalf. Whoever holds it can act as your account, and the service bills or acts as if it were you.
What should I do if I pasted an API key into an AI chat?
Treat it as exposed. Revoke it in the provider's dashboard, create a new one, and store the new one in a proper secret store instead of the chat. Then check the provider's usage records for anything unexpected.
Is deleting the key from the code enough after a leak?
No. The old key still works until you revoke it, and it may remain in saved history. GitHub's guidance says removing a secret from Git history is time-intensive and often unnecessary once the credential is revoked.
Can an AI coding agent see my passwords and keys?
It can if they are in the chat, the code or files it can read. Keep keys in a secret store, use the least-power key for each job, and use test keys while building.
How does Atlas handle secrets?
A secret pasted into the Atlas chat goes to a secret store first, engineers never see cloud sign-ins, and its security scan looks for passwords or keys committed in what changed on main. Choosing least-power keys and replacing them stays with you.
Sources
Researched and drafted with Claude, then checked against the sources above. Atlas is an independent product, not affiliated with Anthropic or OpenAI. Claude and Claude Code are trademarks of Anthropic; Codex is a product of OpenAI.