If you let an AI coding agent write and commit code, it can also commit your secrets. That stopped being a theoretical risk this week. Together AI disclosed that a coding agent pushed a working credential into a public repository, and an outsider used it before the commit was reverted. Attackers are now using their own AI agents to find exactly these mistakes, faster than most teams can react.

This guide gives you a layered setup you can put in place today, whatever agent you use: Claude Code, Codex, Cursor, Copilot or anything else.

What actually happened at Together AI

On 21 November 2026, Together AI published a security notice about prompt samples from its serverless inference service in June and July 2026. According to the company's own disclosure:

  • The team had stored prompt samples, collected for software testing, in a private Hugging Face repository.
  • While working on Together AI's public GitHub repository, xorl, an AI coding agent committed a credential that gave access to that private repository.
  • Automated scanning caught it and the commit was reverted, but during that window an unauthorised party grabbed the credential and downloaded the samples.

Together AI says it has since moved to scoped or short-lived credentials and keyless access where possible, and has updated its rules for using AI coding agents in development.

Notice the detail that matters most: they had scanning, and it still wasn't fast enough. Reverting a commit does not un-publish a secret. Once it is pushed, assume it has been seen.

Why "a few minutes" is now too long

On 5 November 2026, Microsoft Threat Intelligence reported that threat actors have been using an agentic offensive framework called ARTEX to search public GitHub repositories for exposed credentials, app secrets and AI API keys. In one case Microsoft observed, an attacker's agent went from searching GitHub to pulling data out of an Azure Key Vault in about five minutes.

Put those two stories together and the picture is clear:

  • Your agent can create the leak.
  • An attacker's agent can exploit it within minutes.
  • Humans reviewing a pull request the next morning are far too late.

So the fix is not "review harder". It is to stop secrets reaching the remote at all, and to make any secret that does escape worth very little.

Layer 1: Keep secrets out of the agent's reach

The simplest secret to protect is the one the agent never sees.

  • Never paste keys into the chat. Anything in the conversation can end up in a file, a log or a commit message.
  • Use a .env file that is git-ignored from day one, and commit a .env.example with placeholder values instead.
  • Tell the agent the rules in its project instructions file (CLAUDE.md, AGENTS.md, .cursorrules or equivalent). A starter block you can copy:
## Secrets policy - Never write real API keys, tokens, passwords or connection strings into any file. - Read configuration from environment variables only. - If a value looks like a secret, stop and ask before committing. - Never modify .gitignore to un-ignore .env or credential files.
  • Check the agent's own config and settings files. Tools that remember approved commands or store connector settings can quietly capture a token you typed once. Add those files to .gitignore unless you have read them.

Instructions help, but treat them as a seatbelt, not a guarantee. Agents follow them most of the time, and "most of the time" is the problem. That is why the next layers exist.

Layer 2: Block secrets before they leave your machine

A pre-commit hook scans what is about to be committed and refuses the commit if it finds a secret. It runs for you and for the agent, because the agent uses the same git.

A minimal setup with the open-source pre-commit framework and Gitleaks:

# .pre-commit-config.yaml repos: - repo: https://github.com/gitleaks/gitleaks rev: v8.24.2 # run `pre-commit autoupdate` for the latest hooks: - id: gitleaks

Then run pre-commit install once per clone. Now a commit containing something that looks like an AWS key or GitHub token fails locally, before any push.

Two habits make this work with agents:

  1. Don't let the agent bypass hooks. Add "never use --no-verify or SKIP=" to your project instructions, and watch for it in the agent's command history.
  2. Keep the agent's git permissions narrow. If your tool lets you require approval for git push, turn that on.

Layer 3: Block secrets at the server

Local hooks can be skipped or missing on a new machine. Server-side protection catches what slips past.

  • Turn on GitHub secret scanning and push protection. Push protection rejects a push that contains a recognised secret pattern. GitHub's documentation says it is available for public repositories at no cost, and you can enable it from the repository's code security settings. Private repositories need GitHub Secret Protection.
  • Scan every pull request in CI. Together AI added credential checks on all pull requests after the incident. Do it before yours.
  • Review agent pull requests as untrusted input. Look at the diff for config files, test fixtures and scripts, which is where agents tend to paste "temporary" values.

Layer 4: Make leaked secrets worthless

Assume one will eventually get out. Limit the damage.

  • Use short-lived, scoped credentials. A token that expires in an hour and can only read one bucket is a much smaller problem than a long-lived admin key.
  • Prefer keyless access such as OpenID Connect from CI to your cloud provider, or managed identities, so there is no static key to leak.
  • Give agents their own credentials, separate from your personal ones, with the minimum permissions the task needs. If something goes wrong, you revoke one token, not your whole account.
  • Write down your rotation steps now. If a key leaks, the first job is to revoke and replace it, not to rewrite git history. Cleaning history comes second.

We publish a new practical AI post every day, and agent safety keeps coming up because agents are now part of everyday tooling. If you are deciding which jobs to hand to agents at all, read AI Agents Are Now Inside the Tools You Already Use: What to Hand Over First (and What to Keep). For the bigger picture on how this is changing engineering work, see How AI Is Changing the Daily Life of IT Professionals.

Recommended tools and resources

  • Gitleaks: free, fast secret scanner that drops into pre-commit and CI. Good for most teams. Trade-off: its maintainer has said it is now feature-complete and will get security patches only, so watch for successor tools.
  • TruffleHog: open-source scanner that can check whether a found credential is actually live, and scans beyond git (S3, Docker images, filesystems). Best for auditing existing repos and history. Trade-off: heavier to set up than a simple hook.
  • GitHub secret scanning and push protection: server-side blocking that works even when local hooks don't run. Ideal for anyone on GitHub. Trade-off: private repositories need a paid add-on.
  • pre-commit: the framework that makes hooks easy to share across a team, so every clone gets the same checks.

Your 15-minute checklist

  • [ ] .env and credential files are in .gitignore; .env.example uses placeholders
  • [ ] Project instructions file includes a secrets policy and bans --no-verify
  • [ ] Gitleaks (or similar) runs as a pre-commit hook
  • [ ] GitHub push protection is turned on for the repo
  • [ ] Secret scanning runs on every pull request in CI
  • [ ] Agents use their own scoped, short-lived credentials
  • [ ] Agent git push requires your approval
  • [ ] You know exactly how to revoke and rotate each key you use

Over to you

Has an AI coding agent ever tried to hard-code a key or token in your project? Tell us what happened, and how you caught it, in the comments below. If this checklist would save a teammate from a bad week, share the post with them.

Get one practical AI post every day. Join the JosephDevelop community using the "Join Our Community" form at the bottom of this page and hit "Subscribe Now". We'll keep you up to date on the tools, risks and workflows that actually matter.