Agent Upstart

Cool things people are building with agents — and practical help getting the most out of them.

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

  1. List the Claude Code credential file and its permissions. Anthropic's authentication documentation states that on Linux, credentials are stored in ~/.claude/.credentials.json with file mode 0600 (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:
    ls -l ~/.claude/.credentials.json 2>/dev/null
    On Linux, the permissions column should read -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 same 0600 mode. That fallback file deserves the same treatment as the Linux file.
  2. Check the Claude Code state file Symantec names. Symantec's report names .claude.json in 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:
    ls -l ~/.claude.json 2>/dev/null
    Apply the same owner-only standard as in step 1. If the file is group- or world-readable, fix it in step 5.
  3. 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 in config.toml does not hold the key itself: its env_key setting names the environment variable that supplies the key, per OpenAI's configuration reference. The one field that does hold a literal token is experimental_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:
    ls -l ~/.codex/auth.json ~/.codex/config.toml 2>/dev/null
    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 keeps auth.json and config.toml under $CODEX_HOME when that variable is set, defaulting to ~/.codex (OpenAI Codex authentication documentation), and Claude Code keeps .credentials.json under CLAUDE_CONFIG_DIR when set instead of ~/.claude (Anthropic authentication documentation). If either variable is set, run the steps 1 and 3 ls -l checks against that directory.
  4. Find .env files in your projects, by path only. Symantec's report names .env files among the files Aoki takes, and .env files are where project API keys commonly live. Find them without reading them:
    find "$HOME" -maxdepth 4 -name '.env' 2>/dev/null
    This prints paths only. For each path it returns, check its permissions with ls -l on that path alone, and check whether it is inside a project folder that is shared, synced, or committed to version control. A .env file 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.
  5. 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:
    grep -rl 'ANTHROPIC_API_KEY\|OPENAI_API_KEY' ~/.claude/settings.json ~/.codex/config.toml 2>/dev/null
    The -l flag 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.
  6. 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:
    chmod 600 ~/.claude/.credentials.json ~/.codex/auth.json ~/.codex/config.toml
    Run the command only for the files that exist on your machine, and add each .env path 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 the ls -l commands from steps 1–3 afterwards and confirm the permissions changed.
  7. 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 (/logout then /login in Claude Code; codex logout then codex login for Codex), and revoke and reissue API keys at the provider's own dashboard for keys stored in .env files 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

Limits

Related playbooks

Sources

Back to: Coding playbooks hub · Also: Check a Cursor machine for the tampered Claude Code extension · Vet a skill before you install it