Give an AI coding assistant a small, sanitized code sample and keep real credentials outside the context it can read. Check the assistant's file access and the account's data rules before sending the request. I'd start with a separate working copy: removing a token from the message won't help if the agent can read the same token from a configuration file or terminal output.
Prepare a useful sample without the secret
Keep the code needed to explain the problem, the relevant language or library version, and the behavior you expected. Replace credentials with clearly labeled placeholders. Use the same placeholder wherever the same value appears so the assistant can follow the relationship without receiving the value.
For an authentication problem, the assistant can often reason about the header name and token-loading code without seeing a working token. Describe the response status and the point where the request fails. If the question depends on the credential's permissions or expiration, check those properties in the service's own account controls and share only the permitted findings.
Inspect the surrounding material too. A database connection string can contain a password; a copied request can include an authorization header or a session cookie. An error report may contain customer records. Remove private hostnames and identifiers when they aren't needed, while preserving the structure the question depends on.
Keep the original file in its approved location. Don't overwrite a production configuration with placeholders or commit a secret-bearing backup to make the example recoverable. A sanitized sample belongs in a separate file or workspace.
Check everything the assistant can receive
Read the attachments and context indicators before sending. An editor assistant may include files beyond the text you typed, and an agent can obtain more context through its tools. Check the active workspace, connected services, and the permissions granted to the current session.
Pay particular attention to terminal output. Printing the environment, opening a credentials file, or running a verbose authenticated request can place a secret in the tool result. Moving the value into an environment variable doesn't prevent that output from reaching the assistant.
These controls address different parts of the workflow:
| Control | Check its actual scope |
|---|---|
.gitignore | Keeps matching untracked files out of normal Git tracking. It doesn't impose file-read permissions on an assistant. |
| Assistant content exclusion | Limits supported context and tools according to the product's rules. Check the client and indirect-access exceptions. |
| Read-only access | Restricts changes. Files readable by the session can still contain secrets. |
| No-training terms | Limit use for training. Check processing, storage, human review, and deletion separately. |
The Git ignore rules apply to intentionally untracked files; files already tracked aren't affected. Adding a credentials file to an ignore list after committing it doesn't remove its earlier contents from the repository.
Configure Copilot exclusions and verify the intended route
For an organization using Copilot Business or Copilot Enterprise, an authorized administrator can configure content exclusions. GitHub's current support table includes chat and agents in Visual Studio Code, Visual Studio, JetBrains IDEs, the Copilot app, Copilot CLI, and Copilot in the cloud. Check your actual client in that table; older advice that all agent modes lack support is no longer a sound basis for the decision.
- Ask the administrator to open the repository's Settings → Copilot → Content exclusion, or the appropriate organization or enterprise control. Repository rules cover that repository. Organization rules apply to users assigned a Copilot seat by that organization; enterprise rules apply to all Copilot users in that enterprise. Inherited rules must be changed by the owner of that policy.
- List the actual files that must be excluded using GitHub's documented path format. Include relevant variants such as
.env.localand copies in other directories. An entry for one path doesn't establish coverage for a different path. - Reload the policy in the client, then verify the affected feature using a harmless sample file. Keep real secrets out of the test, including the ordinary control file. If the expected exclusion result is missing, check the signed-in account, policy scope, path pattern, and client support before using confidential files.
GitHub's exclusion checks use an ordinary file as a control, then an excluded file. For inline suggestions, make the same suggestion-triggering edit in each: the ordinary file should offer a suggestion and the excluded file should not. For chat, the documented check opens the excluded file, closes other editor files, attaches that file as context, and asks for an explanation. The excluded file should not be used or appear as a reference. In VS Code, Developer: Reload Window reloads the policy; in Visual Studio and JetBrains IDEs, close and reopen the application.
The documented Visual Studio 2022 example shows the notice above. A successful exclusion check confirms the route you checked. It doesn't prove that every other tool is blocked.
GitHub says exclusions guard its tools and check identifiable file paths in agent commands, but indirect access can be missed. The IDE can also supply semantic information from an excluded file indirectly, such as a symbol's type or a build setting. Third-party Model Context Protocol (MCP) servers or clients aren't guaranteed to respect exclusions. Symlinks and repositories on remote filesystems also fall outside the stated support. I'd keep a credential out of the reachable environment whenever the task can proceed without it.
Limit agent access before starting the task
Give the agent the workspace and tools needed for the change. For a question about a function, a separate sanitized sample may be enough. For a repository task, review access beyond the repository too, including connected accounts and any secrets manager the agent can call.
Check read permissions independently of write permissions. OpenAI's Codex approval and security controls explicitly allow reading files in read-only mode. The same documentation distinguishes command networking from model requests and other service connections. Turning off command network access doesn't make a hosted assistant an offline system.
Runtime injection can keep a credential out of source code, but the consuming process still receives it. If an agent can launch that process or inspect its output, review that access before granting it. An approved development task that needs authentication should use appropriately scoped development credentials, with the owner controlling how they are provided.
The OWASP secrets guidance recommends least privilege and supports short-lived credentials where practical. A secrets manager helps only when its access rules also keep unnecessary credentials out of the agent's reach.
Check the account's data handling separately
Confirm the exact product, signed-in account, and plan your organization permits. A personal account in the same editor can have different terms from the organization's account. Ask the account owner to confirm the relevant controls before using confidential code.
Read training rules separately from storage and review rules. GitHub's Copilot Trust Center says Business and Enterprise customer data isn't used to train AI models under its Data Protection Agreement, which prohibits that use without customer authorization. That statement doesn't mean the service never processes the prompt or stores any operational data.
For the service and connected tools you intend to use, establish the retention and deletion process, any human-review conditions, and the people who can see a shared conversation or workspace. Check feedback submissions too. If the relevant terms or organizational permission remain unclear, continue with public code or a synthetic example.
Review the exact request and the files it creates
Before sending, read the final message with its attachments. Check that the sample still explains the failure after sanitation. A placeholder that changes the type or structure of a value can create a different problem and lead the assistant toward the wrong fix.
This constructed request preserves a Python authentication question without including a token:
I need help locating an authentication failure in a Python 3.12 service.
Expected: the documented read-only endpoint accepts the request.
Observed: the service returns HTTP 401.
I will attach only sanitized token-loading and request-building code.
The real token, cookies, private hostnames, and customer data are omitted.
The same [TOKEN_A] placeholder refers to the same omitted value.
Identify the code and configuration properties I should inspect locally.
Do not request the token value or a full environment dump.
Explain any proposed change and the evidence that would confirm it.
The request tells the assistant to work with the supplied context. Enforced permissions still determine the files and tools it can access. Keep that distinction when adding reusable repository guidance.
Inspect saved commands and agent configuration as well as the proposed code. In The Hacker News's account of Apiiro's investigation, credentials appeared inside approved commands saved in Claude Code settings files on public GitHub. The report didn't establish that every discovered credential remained usable. The practical check is to keep credential values out of saved approval rules and inspect agent files before including them in a commit or package.
Use any approved local secrets scanner on the sample before sending and on the resulting files before sharing them. A scanner can help find known secret patterns, but a clean scan doesn't prove the request or change is free of sensitive data. Review the actual diff and newly created files, including configuration and logs, before accepting or sharing the result.
Respond to an exposed secret before continuing
Stop the task and notify the credential owner or your security team through the approved private channel. Don't paste the exposed value into another chat or an ordinary issue report. Record the affected service, time, and destinations without creating another copy of the secret.
Follow the service's incident process to revoke the exposed credential and replace it where needed. OWASP's revocation guidance covers potentially compromised secrets. Have the responsible owner verify that the old credential no longer authorizes access and review the relevant activity records. Coordinate changes to shared credentials so dependent services are handled deliberately.
Then address stored copies through the appropriate owners: the conversation, uploaded files, agent settings, and any repository or package that received them. Preserve required evidence privately before cleanup. Deleting a message or file doesn't revoke a credential or erase copies held elsewhere. Resume with a sanitized sample after the owner has contained the exposure.

