Originally published on ReclaimLLM.
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.
AI coding agents — GitHub Copilot, Cursor, and other autonomous tools — can end up writing secrets to files. When they do, the secret isn't just visible in the output; it can be persisted to disk and later leaked into terminal transcripts, shell history, or Git config.
If you find a token, API key, or password in a log, transcript, shell history, or config file, treat it as compromised and follow your provider's rotation guidance. Here's what we know about how this happens, and what you can do to fix it.
A command can receive an argument with your secret even if the terminal never shows the value. If the agent or tool writes its commands or output to a file, the secret ends up persisted on disk and becomes a liability.
How a masked token ends up in a file
Here's a simple explanation of how this can happen:
- An agent or plugin fetches a credential. This may be a token, an API key, or a password.
- It passes the credential to a command. That might be a
curlcommand with anAuthorizationheader, a CLI call with a token, or a script that runs with an environment variable set inline. - The value is masked in the terminal output, but is still included in the full command that the tool executes.
- The command and its full arguments are written to a file — such as terminal output, shell history, or a log.
- A file on disk now contains the secret in plain text.
What Cursor users reported
Cursor users have reported cases where the tool appears to have exposed credentials during remote SSH or shell command execution. This is a good example of how secrets end up written to disk.
In one report, a user said Cursor sent a GitHub API key to a shell command. The user claimed that after an agent command, the key was visible in the process list, even though the terminal output showed it masked. User report
A Cursor staff member explained that the command was likely executed by a shell plugin or by an agent that passed the credential as a command-line argument. In that case, the value is not hidden from the process list; only the terminal display masks it. Staff explanation
A follow-up from Cursor staff confirmed the underlying issue: if a tool writes its commands to a log or terminal history, the secret will be persisted on disk. Cursor staff follow-up
A second report described a similar issue during remote SSH sessions. A user said the API key was exposed in the process arguments while Cursor was running a command over SSH. Forum report
In that thread, a Cursor staff member explained that remote SSH sessions can expose credentials if the agent passes them as command-line arguments rather than using environment variables or a secure credential store. Cursor staff reply
Where to look for copies
If you suspect a secret was written to a file, check these locations first:
- Git config
- Terminal transcript files
- Shell history
- Log files
Git config
Check your global and local Git configuration for credential helpers or extra headers that may contain tokens:
git config --global --list | grep -i -E 'token|credential|helper|extraheader'
git config --local --list | grep -i -E 'token|credential|helper|extraheader'
Look for entries such as:
http.extraheader=AUTHORIZATION: basic ***
credential.helper=osxkeychain
If you see a credential helper entry, check what it stores. Some helpers store secrets in plain text or in a system keychain. The Git credential helper documentation explains how this works.
Terminal transcripts and shell history
Check your shell history files for commands that may have included a secret as an argument:
grep -R -i -E 'ghp_|github_pat_|sk-|api[_-]?key|token' ~/.bash_history ~/.zsh_history 2>/dev/null
Also check for transcript files created by terminal recording tools, such as script, asciinema, or IDE terminal logs. If you use an AI coding agent that logs its output, check those logs as well.
What to do next
If you find a secret in a file:
- Rotate it immediately. Don't just delete the file — the secret may have been copied elsewhere.
- Remove the secret from the file. Use
git filter-repoor BFG Repo-Cleaner if the secret was committed to Git. - Check for other copies. Search your entire home directory and any shared folders for the secret value.
- Review your agent's configuration. Make sure it doesn't pass secrets as command-line arguments.
- Use environment variables or a secure credential store. Avoid passing secrets inline in commands.
Learn more in our guide to preventing API key leaks in AI coding tools.
Also see our guides on secrets in transcripts, secret leaks in Antigravity and Codex, and detecting suspected secret exfiltration.
See how ReclaimLLM flags sensitive Cursor sessions
Sources
Originally published at ReclaimLLM.
Top comments (0)