← Back to Blog

guide

By ReclaimLLM Team

How AI coding agents copy secrets into files

See how an agent can write a masked token into Git config or shell history, where to look for copies, and how to rotate and clean up.

A Grok Bot user reported finding six copies of a GitHub token on the bot's computer. Five copies were in Git configuration files, including one in a throwaway clone. The sixth was in shell history. The bot had put the token directly into Git remote URLs. Cursor forum staff explained that the secure input card masked the token in command output while still passing its value to shell commands through an environment variable. Those commands could write the value to a file. User report · Staff explanation

If you find a credential in a file after an agent run, revoke or rotate it first. Then investigate the machine where the command ran, including temporary clones and shell history. The visible chat gives you only one view of what the command did.

How a masked token gets written to disk

A command can receive a secret through its environment, expand it into an argument, and hand that argument to another program. When the argument is a Git clone URL with embedded credentials, Git can save the URL as the remote. The clone can succeed without ever printing the token in the terminal. A later copy of the directory or collection of diagnostic logs can widen the exposure.

An instruction to leave credentials out of remote URLs can steer the agent toward a safer command. Its effectiveness still depends on the agent following it. In the Grok Bot report, staff confirmed that bots were already instructed to avoid writing secret values and that the instruction did not enforce the restriction. Blocking this specific write requires a control that can constrain the command, its credentials, or where it can write. Cursor staff follow-up

Where to look for copies

LocationWhat to check
Git remote configurationThe active checkout, worktrees, audit clones, and temporary clones. Look at both fetch and push URLs.
Shell historyThe agent runner's account and shell, including any custom history file. A command with a literal credential in its URL can survive long after the clone is gone.
Shared runner credentialsCheck which processes can use the Git client or credential store under the runner's identity. A separate Grok Bot user reported concern about a long-lived GitHub CLI token on a machine shared by several bots. Forum report

Inspect the host that ran the command. For a remote workspace, that may be a VM or worker instead of your laptop. If you have several runners, use the job or session timestamps to narrow the search.

Check for credentials created by Cursor itself

In a separate Remote SSH report, staff identified a crsr_ value in a remote worker's process arguments as a personal Cursor API key created for that worker. At the time of the report, stopping the worker or revoking desktop sessions left the API key valid. Staff directed the user to the API Keys page to identify and revoke the matching worker key. Treat this as a recorded incident and check the current dashboard and worker behavior during an investigation. Cursor staff reply

Find copies without printing the credentials

Run this from each relevant checkout in a trusted terminal. The first check prints matching Git config keys. The second prints matching history filenames. Neither prints the matched credential.

git config --get-regexp '^remote[.].*[.](url|pushurl)$' |
  awk '$2 ~ /^https?:\/\/[^\/@[:space:]]+@/ { print $1 }'

for history_file in "${HISTFILE:-}" "$HOME/.zsh_history" "$HOME/.bash_history"; do
  [ -n "$history_file" ] && [ -r "$history_file" ] || continue
  if LC_ALL=C grep -aqE '(ghp_|gho_|github_pat_|sk-|crsr_|AKIA)' "$history_file"; then
    printf '%s\n' "$history_file"
  fi
done

The remote check flags HTTP URLs with user information, which may be an ordinary username. The history check covers a few recognizable prefixes and can miss other formats. A shell may also keep recent history in memory. Use a secret scanner with redacted output to examine the working tree, including untracked files, and the relevant dotfiles and temporary directories. Select those locations explicitly since a scan of Git history alone will miss Git metadata and files outside the repository. Keep scan output in your incident workflow and share only redacted findings.

Revoke the credential, then clean up the copies

  1. Revoke or rotate the exposed credential at the issuer. If a production integration needs it, coordinate the replacement and confirm the old credential is rejected. Check the issuer's audit records where available.
  2. Replace credential-bearing Git remotes. Set clean fetch and push URLs as applicable. Configure a Git credential helper appropriate to the runner, and verify it can authenticate without embedding the replacement token in a URL.
  3. Remove residual copies. Check shell histories, temporary clones, and artifacts. Preserve evidence under your incident policy. If the secret entered a commit, assess history cleanup and coordinate with collaborators who have clones.
  4. Repeat the checks. Confirm that the credential is revoked and the cleanup covered the hosts where the agent operated.

For future runs, give each agent identity the minimum repository access it needs and prefer short-lived credentials where available. Keep credential handling outside shell strings the agent assembles. When the environment supports it, test the approved Git workflow with a throwaway credential before using it against a production repository.

Related exposure paths

These checks cover copies an agent writes. For adjacent paths, see preventing API key and .env access, secrets in coding-agent transcripts, secret leaks in Antigravity and Codex, and detecting suspected secret exfiltration.

FAQ

Does output masking keep a token out of files?

A shell command can write a token that the interface masks in output. Test the file-writing path with a throwaway credential if you need to validate a particular workflow.

Can an agent rule prevent the copy?

A rule can direct the agent to use a clean Git remote and approved authentication path. Enforce the restriction where the agent gets credentials or runs commands if the workflow requires a guarantee.

Does revoking a desktop session revoke a Cursor worker key?

In the documented Remote SSH incident, staff said the worker key required separate revocation on the API Keys page. Check both when investigating this kind of exposure. Cursor staff reply