keepcalculator

06 Numbers and Powers

AI Coding Assistants: Keep Secrets Out of Your Codebase

Card No. 06·57250 · Updated · Standard formula, shown below

AI coding assistants can accidentally bring passwords, API keys, tokens, and private configuration into prompts, generated code, logs, or commits. Reduce that risk by limiting what the assistant can access, keeping credentials outside source files, and checking changes before they are shared. Before you begin, identify the assistant’s data-sharing settings and the secret-scanning tools available in your development workflow.

What You’ll Need

  • Access to your coding assistant’s privacy, context, and file-exclusion settings.
  • A project-level ignore or exclusion file supported by the assistant, if available.
  • A secrets manager or environment-variable mechanism for local development and deployment.
  • A secret scanner, such as a repository-hosting platform’s built-in scanning or a compatible local scanning tool.
  • Permission to change repository settings and rotate credentials if a secret is exposed.

Step-by-Step

  1. Find where the assistant gets context. Check its settings and documentation for whether it reads the open file, the whole workspace, selected folders, terminal output, chat history, or remote repository content. Also check whether prompts or code may be stored or used to improve a service. These behaviors vary by tool and account configuration; do not assume that a local editor means all processing stays local.
  2. Choose safe data-sharing settings. Turn off optional use of your code or prompts for model improvement when that option exists, and select the most restrictive retention or sharing setting appropriate to your work. For sensitive repositories, follow your organization’s approved-tool policy. If the tool’s handling of data is unclear, do not feed it secrets or confidential files; ask the repository or security administrator for guidance.
  3. Keep credentials out of tracked source files. Put development credentials in environment variables or a secrets manager, and have the application read them at runtime. Keep local environment files out of version control with the repository’s ignore rules. Commit a placeholder file, such as an example configuration with names but no real values, so others know what to set. An ignore rule prevents ordinary tracking; it does not protect a file already committed or guarantee that an assistant cannot read it.
  4. Exclude sensitive paths from assistant context. Use the assistant’s documented ignore or exclusion mechanism for credential files, local environment files, private keys, production configuration, database dumps, and sensitive logs. Check whether exclusions apply to chat, indexing, terminal context, and background features, not just autocomplete. Keep exclusions narrow enough that the assistant can still work with safe source code. Verify the behavior with a harmless test file rather than placing a real credential in it.
  5. Minimize what you paste into prompts. Share only the smallest relevant code excerpt. Replace secret values with obvious placeholders such as API_KEY_REDACTED, and remove customer data, internal URLs, tokens, and identifying details from logs. Do not ask the assistant to inspect a credential file or paste a terminal command’s full output if it might include environment variables or authentication headers.
  6. Review generated changes before accepting them. Inspect every changed file, including new files, configuration, tests, documentation, and scripts. Search for likely credential patterns and for sensitive values copied from your environment. Check that code reads a secret from a variable or secret store rather than embedding a value. Review commands suggested by the assistant before running them, especially commands that print environment variables, upload files, or write credentials into the repository.
  7. Scan before committing and in the repository pipeline. Run an established secret scanner locally or use the repository host’s scanning feature, then review its findings. Enable scanning for pull requests or commits where available. A scanner can miss unfamiliar or encoded secrets and can flag harmless test strings, so use it as a safety net rather than proof that a change is clean. Avoid adding real credentials to test fixtures; use clearly fake values.
  8. Protect the path from editor to deployment. Use least-privilege credentials: give each development or automation task only the access it needs, and keep production credentials out of local development where possible. Store deployment secrets in the approved CI or hosting secret store, restrict who can view or change them, and avoid printing them in build logs. Do not pass secrets as command-line arguments when a safer supported mechanism is available, since process listings and logs can expose arguments.
  9. Respond promptly if a secret appears. Treat a real credential in a prompt, generated file, log, or commit as exposed. Revoke or rotate it through the system that issued it, check relevant access logs, and notify your security contact if required by your organization’s process. Remove it from the working tree and history as appropriate, but do not rely on deletion alone: copies may remain in clones, caches, logs, or assistant history. Confirm that the replacement credential is stored safely before resuming work.

Common Mistakes

Assuming ignored means invisible: Git ignore rules generally affect version control, not what an editor extension can read. Configure assistant exclusions separately and confirm their scope.

Removing a secret without rotating it: If it was shared or committed, deletion does not make the old value safe. Revoke or rotate it first, then clean up copies.

Trusting a clean scan: Scanners cannot identify every secret format, and some findings need context. Review diffs and investigate warnings rather than treating a passing check as a guarantee.

Using real credentials in examples: Sample code, tests, screenshots, and documentation are all easy places for a key to be copied. Use unmistakably fake placeholders.

Allowing broad access for convenience: Workspace-wide indexing or unrestricted terminal context may expose more material than a task needs. Limit access where the tool permits it.

Tips

  • Use a pre-commit secret scan as an early warning, and also scan on the server because local checks can be skipped.
  • Use separate, limited credentials for development, testing, and production; never reuse a high-privilege production key for routine coding.
  • Keep an example configuration synchronized with required variable names, but make its values obviously nonfunctional.
  • Review assistant and editor updates for changes to indexing, retention, or data-sharing settings.
  • Agree on a simple team rule: redact first, share the minimum context, and report accidental disclosure promptly.

Troubleshooting

The assistant still suggests a value from a private file: Stop using that conversation for sensitive work. Check the tool’s exclusion settings and whether the file was already indexed or included in earlier context. Remove the value from any generated change and rotate it if it was a real credential. Restart or refresh the assistant’s index only if its documentation describes how to do so; this may not remove previously stored prompt data.

A scanner reports a secret in a test or example: Verify that the value is fake and cannot authenticate. Replace it with a clear placeholder if possible. If you suppress a finding, use the scanner’s documented, narrowly scoped method and explain the reason; never blanket-disable scanning to clear a warning.

A credential was committed: Revoke or rotate it immediately, then follow your repository’s incident procedure. Removing it in a later commit does not erase it from earlier history or other copies. Coordinate history cleanup with repository administrators, especially when other people may have cloned the project, and check logs for use.

You cannot find an exclusion setting: Consult the assistant’s current documentation or ask an administrator. Until you can establish what the tool reads and retains, keep sensitive files out of its workspace and do not paste sensitive content. Use a different approved workflow if needed.

Frequently Asked Questions

Can an AI coding assistant read files I have not opened?
Some tools can index or retrieve workspace files beyond the active editor tab; others use narrower context. Check the specific tool’s settings and documentation, and configure exclusions rather than assuming.

Is it safe to put an API key in an environment variable?
It is generally safer than hard-coding it in source, but the variable can still be exposed through shell history, logs, process inspection, or assistant context. Use a secret store where appropriate and avoid printing its value.

Does a Git ignore rule stop an assistant from seeing a file?
No. Ignore rules control normal Git tracking behavior; an assistant may use its own file discovery and indexing. Set and verify assistant-specific exclusions separately.

What should I do if I pasted a key into a prompt?
Assume it may be exposed. Revoke or rotate the key, review access logs if available, and follow your organization’s response process. Deleting the conversation may not remove stored copies.

Are secret scanners enough to protect a repository?
No. They catch many known patterns but can miss secrets or produce false positives. Combine scanning with safe storage, restricted access, careful review, and prompt minimization.

Can I use real credentials in private repositories?
A private repository is not a suitable place for credentials. Access can change, and copies may exist in history, logs, or local clones. Store credentials in a secrets manager or approved runtime configuration instead.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →