AI Coding Agents Are Leaking Secrets: 7 Ways to Protect Your API Keys

Laptop in a garage workspace showing an exposed API key highlighted in red in a code commit

Written by

in

On November 21, 2026, AI company Together AI revealed an uncomfortable truth: an AI coding agent, not a human, leaked the key that exposed months of customer prompts.

It isn’t a one-off. Researchers have found thousands of passwords and API keys that AI coding tools pushed into public code. So if you vibe code or use an AI coding agent, your secrets could be next.

Here’s what happened, and seven simple ways to protect your API keys starting today.

Key Takeaways

  • What happened: An AI coding agent committed a credential to Together AI’s public GitHub repository, and an attacker used it to download stored customer prompts.
  • The bigger trend: Researchers found 2,539 exposed credentials across 1,994 public GitHub repositories linked to an AI coding tool’s settings files.
  • The risk is rising: AI-assisted commits leak secrets at roughly twice the rate of normal commits.
  • Deleting isn’t enough: Once a key goes public, you must replace it, not just remove it.

What Happened at Together AI?

Together AI stored samples of customer prompts in a private Hugging Face repository for software testing. Meanwhile, an AI coding agent was helping build one of the company’s public GitHub projects, called xorl.

During that work, the agent committed a credential that unlocked the private repository. Together AI’s automated scanning caught it and reverted the commit. However, an unauthorized party had already copied the key and downloaded the stored prompt samples.

The lesson is simple: undoing a commit doesn’t undo a leak. The moment a secret appears in public code, bots can find and copy it.

It’s Not Just One Company

This month brought two more warning signs:

  • Apiiro’s research (November 2026): Security firm Apiiro found 2,539 exposed credentials across 1,994 public GitHub repositories, including database passwords, cloud keys, API tokens and SSH logins. The leaks came from settings files created by Claude Code, Anthropic’s coding agent. When developers approved a command with “Yes, and don’t ask again,” the tool saved that command, secrets included, to a project file that later got committed.
  • GitGuardian’s 2026 report: Commits made with Claude Code leaked secrets at about 3.2%, roughly double the 1.5% average across all public GitHub commits. Overall, about 29 million secrets leaked on GitHub in 2025, a 34% jump from the year before.

In short, AI agents write code fast, and they copy whatever they can see, including your keys.

7 Ways to Protect Your API Keys From AI Coding Agents

Lockbox labeled .env holding keys, representing keeping API keys out of code

1. Never Paste Secrets Into Prompts or Code

Avoid typing passwords or API keys into an AI chat or directly into your code. Instead, store them in environment variables or a .env file, and have your code read them from there.

2. Add Secret Files to .gitignore

A .gitignore file tells Git which files never to upload. Add your .env file, along with any local AI agent settings, transcript or memory files your tools create. For example, Apiiro’s research found secrets in Claude Code’s .claude/settings.local.json file.

3. Review Every Change Before You Push

Always read the list of changed files before you commit. If you see a file you don’t recognize, or a line that looks like a password, stop and check it. Also, be careful with “don’t ask again” approvals for commands that contain secrets.

4. Turn On Secret Scanning

GitHub’s secret scanning and push protection can block a commit that contains a known key format before it goes public. Turn them on for every repository. Tools like GitGuardian add an extra layer of protection.

5. Use Limited, Short-Lived Keys

Give each key only the access it needs, and set it to expire when possible. Similarly, set spending limits on AI and cloud accounts, so a stolen key can’t run up a huge bill.

6. Keep Your Repository Private Until It’s Clean

If you’re experimenting with an AI agent, start in a private repository. Then, scan it for secrets before you make it public.

7. Check Your Agent’s Hidden Files

AI agents create transcripts, memory files and settings in hidden folders. Apiiro found secrets in these files too, which almost no one checks. So look through them occasionally, and keep them out of Git.

Leaked a Key? Do This Right Now

Phone alert at night warning that a secret was detected in a repository, with a Revoke key now button
  1. Revoke the key immediately in the service’s dashboard, such as your AI provider, cloud or database account.
  2. Create a new key and store it safely in an environment variable.
  3. Check for unusual activity, like unexpected charges, logins or data downloads.
  4. Remove the secret from your Git history, because deleting it in a new commit leaves it visible in older ones.
  5. Find the cause, whether that’s a missing .gitignore rule or an agent settings file, so it doesn’t happen again.

Remember, revoking the key comes first. Cleaning up your code can wait a few minutes; a live, leaked key can’t.

Frequently Asked Questions

Can AI coding agents leak my API keys?

Yes. AI coding agents can copy secrets from your files into code, commands or settings files, and then commit them to GitHub. Researchers found thousands of real examples in 2026.

What should I do if my API key leaked on GitHub?

Revoke it immediately, create a new key, check for unusual activity and then remove the secret from your Git history.

Does deleting a commit remove a leaked secret?

No. Bots scan public repositories constantly, and the secret may already be copied or remain in your Git history. Always replace the key.

How do I keep API keys out of my code?

Store keys in environment variables or a .env file, add that file to .gitignore and turn on GitHub’s secret scanning and push protection.

The Bottom Line

AI coding agents make building faster, but they don’t know which strings are secret. As the Together AI leak shows, one careless commit can expose months of data.

Fortunately, the fix is simple: keep keys out of prompts and code, review every change and turn on secret scanning. And if a key ever leaks, replace it first and ask questions later.

Related reading:

Sources


Moiz Danishmand Khan Avatar

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *