Playbooks · Coding tasks
Check where your coding agents store API keys on your own machine
Written October 31, 2026
For a developer with one or more coding agents installed: find every file on your own machine that holds an agent login or API key, check who can read it, and fix the permissions — before anything else running as your user reads it first. No step below prints a key value.
Why this check exists
On 15 October 2026, Symantec's Threat Hunter team reported that the newest samples of the Aoki infostealer steal credential and session files used by AI coding assistants, including Claude, OpenAI's Codex, Cursor, Codeium, and Gemini. Earlier versions of the malware did not target AI-related files, which Symantec reads as a recent addition. The newest sample it analyzed targeted .claude.json, Claude desktop cookies, ChatGPT cookies, and the Codex config.toml and .env files, and also stole tokens for GitHub Copilot, Cursor, Google Gemini, JetBrains AI Assistant, and Kiro, along with Amazon Web Services credentials. Aoki reads files that are already on disk after it is already running as you: it is not a flaw in Claude Code or Codex, and there is no patch for it. The defense on your machine is knowing which files hold secrets, and keeping them readable only by you.
This page covers local files only, for two agents whose storage locations their own documentation states: Claude Code and Codex. Other agents are not covered here, because their credential paths were not checked against their own documentation for this page — a path copied from a summary table is not a path you should act on. If you use another agent, check its own documentation for where it stores its login before adding it to this audit.
A separate incident is not part of this audit. On 17 October 2026, OpenCode disclosed a breach of its hosted Console system in which provider API keys saved in Console workspaces were exposed for about 1.4% of Console users. That was keys saved in a hosted workspace, not files on your machine, and OpenCode stated that keys added locally through the command-line tool never came to OpenCode. Nothing below audits a hosted console, and a clean result here says nothing about keys you saved in one.
Before you start
Work in your own terminal, on your own machine, with no one watching the screen. Every command below lists files or permissions, or names files that match — none of them displays file contents. If a command would print a key, stop: do not run cat, do not run plain grep without -l, and do not paste any of these files into a chat, a ticket, or an agent session. A credential file is useful to an attacker precisely because it can be read as your user; treat every file in this audit as a secret from the moment you find it.
Steps
- List the Claude Code credential file and its permissions. Anthropic's authentication documentation states that on Linux, credentials are stored in
~/.claude/.credentials.jsonwith file mode0600(owner read and write only), and on Windows in%USERPROFILE%\.claude\.credentials.json, inheriting the access controls of the user profile directory. On macOS, credentials are stored in the encrypted macOS Keychain instead. List the file without reading it:
On Linux, the permissions column should readls -l ~/.claude/.credentials.json 2>/dev/null-rw-------. If it reads anything more open, fix it in step 5. If the file exists on macOS, Anthropic's documentation states the Keychain write was rejected — for example, when the Keychain was locked in an SSH session — and Claude Code stored the login in the file instead, with the same0600mode. That fallback file deserves the same treatment as the Linux file. - Check the Claude Code state file Symantec names. Symantec's report names
.claude.jsonin your home directory among the files Aoki takes. It holds project entries for Claude Code sessions. Check that it exists and who can read it, the same way, without reading its contents:
Apply the same owner-only standard as in step 1. If the file is group- or world-readable, fix it in step 5.ls -l ~/.claude.json 2>/dev/null - List the Codex credential and config files. Codex keeps its configuration in
~/.codex/config.toml— the file Symantec's report names — and its sign-in in~/.codex/auth.json, the file Codex integrations read credentials from. A provider entry inconfig.tomldoes not hold the key itself: itsenv_keysetting names the environment variable that supplies the key, per OpenAI's configuration reference. The one field that does hold a literal token isexperimental_bearer_token, which the same reference calls discouraged — a token typed there sits in the file as plain text. List both files without reading them:
Either file may be absent if you have never signed in to Codex on this machine, or if your Codex setup stores its login in the operating system's credential store instead. Absence of a file is a clean result for that file, not a reason to create one. Codex keepsls -l ~/.codex/auth.json ~/.codex/config.toml 2>/dev/nullauth.jsonandconfig.tomlunder$CODEX_HOMEwhen that variable is set, defaulting to~/.codex(OpenAI Codex authentication documentation), and Claude Code keeps.credentials.jsonunderCLAUDE_CONFIG_DIRwhen set instead of~/.claude(Anthropic authentication documentation). If either variable is set, run the steps 1 and 3ls -lchecks against that directory. - Find
.envfiles in your projects, by path only. Symantec's report names.envfiles among the files Aoki takes, and.envfiles are where project API keys commonly live. Find them without reading them:
This prints paths only. For each path it returns, check its permissions withfind "$HOME" -maxdepth 4 -name '.env' 2>/dev/nullls -lon that path alone, and check whether it is inside a project folder that is shared, synced, or committed to version control. A.envfile that is tracked by git has already left the machine in every clone of that repository — fixing its permissions does not unshare it, and the key in it must be rotated. - Name the files that contain key material, without printing any of it. To find which settings and config files mention a key, search for key names and report filenames only:
Thegrep -rl 'ANTHROPIC_API_KEY\|OPENAI_API_KEY' ~/.claude/settings.json ~/.codex/config.toml 2>/dev/null-lflag prints filenames only, never matching lines. Any file it names holds a key reference and belongs in the owner-only set from the steps above. Never rerun this search without-l: the matching lines are the secrets. - Fix permissions on every file you found. For each credential or key-bearing file from the steps above, restrict it to owner read and write only. On Linux and macOS:
Run the command only for the files that exist on your machine, and add eachchmod 600 ~/.claude/.credentials.json ~/.codex/auth.json ~/.codex/config.toml.envpath from step 4 that holds a key. On Windows, the Claude Code credential file inherits the user profile directory's access controls; confirm the file sits under your own profile folder and has not been copied elsewhere. Rerun thels -lcommands from steps 1–3 afterwards and confirm the permissions changed. - Rotate anything that was readable by others. If any credential file was group- or world-readable, or sat in a shared, synced, or committed location, assume the credential in it is known and replace it: sign out and back in for a subscription login (
/logoutthen/loginin Claude Code;codex logoutthencodex loginfor Codex), and revoke and reissue API keys at the provider's own dashboard for keys stored in.envfiles or configs. Removing a key from a file does not stop someone who already copied it. Deleting the file does not revoke the credential.
What can go wrong
- Printing a key while auditing. A plain
catorgrepon a credential file puts the secret on screen, in shell history, and in any transcript of the session. Every command above avoids that by design; a command that prints contents is the audit failing, not the audit working. - Checking only one agent. A machine with Claude Code and Codex has two credential stores, plus project
.envfiles. Checking one and assuming the other is clean leaves the other readable. - Fixing permissions but not rotating.
chmod 600stops future reads by other users on the same machine. It does nothing about a credential already copied, synced, or committed. A file that was ever readable by others needs its credential replaced, not just its permissions fixed. - Treating a clean local audit as covering hosted keys. This audit covers files on your machine. Keys saved in a hosted console, such as OpenCode Console workspaces, are a different store with a different disclosure history, and this page does not audit them.
Limits
- This page covers Claude Code and Codex only, plus project
.envfiles. It does not cover Cursor, Gemini, Copilot, JetBrains AI Assistant, Kiro, or Codeium, even though Symantec's report names some of them as Aoki targets — their credential paths were not checked against their own documentation for this page. - Permissions stop other users on the same machine from reading a file. They do not stop malware already running as your user, which reads files with your own permissions. The audit reduces exposure; it does not make a compromised account safe.
- Credential storage varies by operating system and by how each agent was configured. If your setup uses an operating-system credential store instead of a file, there is no file to find for that login, and the steps above correctly return nothing for it.
Related playbooks
- PACT-Check: benchmark gains without information flow
- Fingerprinting AI coding agents from 33,580 PRs
- Use your own Anthropic API key with an agent: what it costs, and the billing trap to check first
- Check a Cursor machine for the tampered Claude Code extension
Sources
- https://www.security.com/threat-intelligence/aoki-infostealer-ai-targeting
- https://code.claude.com/docs/en/iam
- https://pydantic.dev/docs/ai/models/openai-codex/
- https://developers.openai.com/codex/auth
Back to: Coding playbooks hub · Also: Check a Cursor machine for the tampered Claude Code extension · Vet a skill before you install it