Keep secrets out of the path

Lesson 20 of 35 · Working with AI coding agents

A secret is information that grants access or must remain confidential: an API token, private key, password, or customer record, for example. The safest secret for an agent is one it does not need and cannot reach.

An agent may encounter a secret in a file, an environment variable inherited by a process, a command’s output, a log, a browser session, or a pasted message. Tool output can become part of the model’s context—the material supplied for a response—and may also be recorded in session history. If a remote model receives that context, the information leaves the local environment. Even with a local model, logs, backups, plugins and later exports can create additional copies.

A trace of an accidental disclosure

A developer asks the agent to diagnose a failed service. The agent reads a diagnostic log; the log contains an authorization header; the tool returns the line to the agent; the session records it. No one needed to commit the token for exposure to occur. Redacting the final answer does not undo earlier copies.

Reduce the paths: use sanitized sample logs and test data, keep secret files outside the agent’s reachable workspace, limit process environment and credentials, and configure actual filesystem and network controls. A version-control ignore file or search exclusion controls particular tracking or search behavior; it is not a reliable access control. A denied direct file-read tool may still leave a shell, plugin, or other process able to read the file.

Store configuration without plaintext credentials where supported, using an appropriate secret manager and short-lived, narrowly scoped credentials. This avoids embedding the value in configuration; it does not prevent an authorized process from using or revealing it. Check the provider’s handling of context, retention, logs and integrations before supplying sensitive data.

Tracking, search, and access are different

A Git ignore rule generally keeps matching untracked files out of ordinary discovery for adding to a repository. It does not stop Git tracking a file already tracked, remove its history, or prevent another program from opening it. Search tools can apply their own exclusions, honor ignore rules, or offer overrides; behavior depends on the tool and settings. A file missing from search results can still be read directly by a process with access. Use filesystem and service permissions to restrict access, and handle any already committed secret as exposed rather than relying on a new ignore rule.

If a secret appears

Stop further sharing. Follow the owner’s incident procedure: revoke or rotate the credential promptly, investigate its use and the systems and logs that may contain it, and remove or restrict copies where supported. Notify the responsible people. Deleting a chat message alone does not guarantee removal from every recipient or backup.