Skip to content

Analysis

NextChirp

Let an AI Coding Assistant Write Code, Not Passwords

Published

Updated

AI tools make it easy to paste a working API key into code. Here are the checks that catch a key before it reaches a shared repository, and what to do if one gets through.

The fix is mostly old-fashioned: keep keys out of code, scan before pushing, and rotate any key that leaks. AI coding assistants can produce working code, and "working" sometimes means a password or API key typed straight into a file. Whether a human or an assistant put it there, the same guardrails apply.

Where secrets slip in

These are common patterns to check for, not measured rates:

  • Pasting a real key into a chat with an assistant so it can "make the call work," then accepting code that includes it.
  • Example or test files that contain live credentials.
  • Configuration files (`.env`, settings files) committed by accident.
  • Logs or error messages that print a token.
  • Sharing a code snippet, including keys, with an AI tool whose data terms you haven't checked.

Checklist

Before anyone writes code

  1. Use a secrets store or environment variables. Code reads keys from the environment; the values live in a password manager, your cloud provider's secrets service, or your hosting platform's settings.
  2. Ignore secret files. Add `.env` and similar files to `.gitignore` in every repository. Ignoring a file does not untrack or erase a secret already committed; check tracked files and history too.
  3. Don't paste live keys into AI chats. Use placeholders ("YOUR_API_KEY"). If a key has been pasted, treat it as exposed.
  4. Give keys the least access they need and separate test from production keys, so a leaked test key can't move money or read customer data.

When code is pushed

  1. Turn on push protection where your platform offers it. GitHub documents "push protection," which blocks pushes containing detected secrets before they reach the repository and explains why. GitHub says push protection for users is on by default on GitHub.com and stops you pushing secrets to public repositories; push protection for repositories is off by default, requires GitHub Secret Protection, and can be enabled by an admin.
  2. Control bypasses. GitHub says that by default anyone with write access can bypass a repository block by giving a reason, which creates an alert and an audit-log entry; "delegated bypass" lets you restrict who can do that. Decide who may bypass, and review every bypass alert.
  3. Know the limits. GitHub's detection covers partner patterns, generic patterns and custom patterns you define; detecting unstructured secrets such as passwords with AI is listed as a public preview feature. No scanner catches everything, so the habits above still matter.

If a secret leaks

  1. Revoke and rotate the key first, at the provider. Deleting the commit isn't enough: the key may already have been copied, and it can remain in history.
  2. Check the provider's logs for use you don't recognize.
  3. Then clean up the repository history if needed, and note what happened and what changed.

Costs and permissions

We are not quoting a price. GitHub states repository-level push protection requires GitHub Secret Protection, and points to its GitHub Advanced Security license billing page for how AI-detected secret blocking is billed; check your plan. Other costs: setting up a secrets store, and the time to rotate keys. Only repository admins, organization owners, security managers or enterprise owners can enable repository push protection, per GitHub.

Measuring whether it's working

  • Number of push-protection blocks and bypasses per month, and the reason given for each bypass.
  • Time from a leaked key being found to it being revoked.
  • Share of repositories with secret files ignored and protection enabled.

Review any bypass marked "I'll fix it later": GitHub says that reason creates an open alert, which is a to-do, not a resolution.

Sources

Sources checked November 7, 2026. GitHub's documentation describes GitHub's own product; NextChirp has not tested its detection rates.

Disclosure: NextChirp has no sponsorship, affiliate arrangement or free products from GitHub for this article.

NextChirp homepageSave this story