Sign in

At least 8 characters.

Already have one?

Free checkBy Yusuf, VXSec

Is Claude Code saving your API keys?

I put a made-up API key in a small app and never typed it to Claude Code. A minute after it fixed a bug for me, the full key was sitting in a saved chat on my computer.

Fastest way to know: run the one-line check below in a terminal. It lists every key sitting in Claude Code's saved chats.

Only check apps you own or have permission to test.

110K+
views on my bank statement reel
507
people sent the free check from a reel comment
1,395
people follow along on Instagram

Counted from Instagram and my DM log.

What I found

The bug made the app say "API key missing", so Claude went looking for the key.

My message had no key in it. Claude opened the .env file to find the bug, which is exactly what you'd want it to do. And the full key was in the saved chat on my computer right after.

That's normal. Claude Code keeps a plain-text copy of every chat so you can pick it back up later. That copy holds what Claude read and what your commands printed, not just what you typed.

Then I ran the check below on my own work laptop. It found real keys in both the saved chats and the typed history. Ones I'd forgotten about.

Why it matters

The files sit in your home folder, ~/.claude. Anything that can read your home folder can read them: a bad extension, a synced backup, a stolen laptop. A key in there is a key that's out of your hands.

Check yours in 1 minute

Open a terminal. Terminal on a Mac, any terminal on Linux, Git Bash on Windows (inside WSL if that's where you run Claude Code). Paste this and press Enter. It only reads and sends nothing.

D="${CLAUDE_CONFIG_DIR:-$HOME/.claude}"; set --; for p in projects history.jsonl file-history paste-cache uploads; do [ -e "$D/$p" ] && set -- "$@" "$D/$p"; done; if [ $# -eq 0 ]; then echo "ERROR: no Claude Code data in $D. If you moved it, set CLAUDE_CONFIG_DIR and run again."; else LC_ALL=C grep -rIoE '(^|\\[nrt]|[^A-Za-z0-9/+_-])(sk-ant-[a-z]{3,5}[0-9]{2}-[A-Za-z0-9_-]{80,}|sk-(proj|svcacct|admin)-[A-Za-z0-9_-]{40,}|sk-[A-Za-z0-9]{20}T3BlbkFJ[A-Za-z0-9]{20}|gh[pousr]_[A-Za-z0-9]{36}|github_pat_[A-Za-z0-9_]{80,}|AKIA[0-9A-Z]{16}|[rs]k_live_[0-9A-Za-z]{20,}|xox[abpors]-[0-9A-Za-z-]{20,}|sb_secret_[A-Za-z0-9_-]{20,}|eyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]*(c2VydmljZV9yb2xl|NlcnZpY2Vfcm9sZ|zZXJ2aWNlX3JvbGU)[A-Za-z0-9_-]*\.[A-Za-z0-9_-]{20,}|gsk_[A-Za-z0-9]{48,}|xai-[A-Za-z0-9]{70,}|hf_[A-Za-z]{34}|r8_[A-Za-z0-9]{37}|npm_[A-Za-z0-9]{36}|glpat-[A-Za-z0-9_-]{20}|SG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}|re_[A-Za-z0-9]{8}_[A-Za-z0-9]{24}|nfp_[A-Za-z0-9]{36,}|ntn_[A-Za-z0-9]{40,}|apik_[A-Za-z0-9_]{40,}|sk_[a-f0-9]{48}|[0-9]{8,10}:AA[A-Za-z0-9_-]{33}|(postgres(ql)?|mysql|mongodb(\+srv)?|rediss?)://[A-Za-z0-9_.%-]+:[^@ "'"'"'\\/(){}$<>+]{6,}@[A-Za-z0-9_.-]+|-----BEGIN ([A-Z]+ )?PRIVATE KEY-----((\\[rn]| )*(MII|b3Blbn)[A-Za-z0-9+/]{20,}))|[= '"'"']AIza[0-9A-Za-z_-]{35}' "$@" 2>&1 | awk -v d="$D" '/^grep: /{print; e++; next} {i=index($0,":"); f=substr($0,1,i-1); k=substr($0,i+1); sub(/^(\\[nrt]|[^A-Za-z0-9-])/,"",k); sub(/[^A-Za-z0-9_-]$/,"",k); if(k ~ /xxxxxx|XXXXXX|[Yy][Oo][Uu][Rr]|EXAMPLE|[Ee]xample|[Pp]laceholder|[Dd]ummy|[Rr]edacted|00000000|AAAAAAAA|abcdefgh|ABCDEFGH|12345678|c3VwYWJhc2UtZGVtb|1cGFiYXNlLWRlbW|zdXBhYmFzZS1kZW1v|^sb_secret_N7UND0Ugj|@(localhost|127\.|0\.0\.0\.0|host|HOST|postgres$|mysql$)/) next; u=(k ~ /:\/\// || k ~ /^(eyJ|-----)/) ? k : substr(k,1,32); if(u in s) next; sub(d,"~/.claude",f); s[u]=1; m=substr(k,1,14) "..."; if(k ~ /:\/\//){split(k,a,"@"); m=substr(k,1,index(k,"://")+2) "...@" a[length(a)]} printf "%-24s %s\n", m, f; n++} END{if(n) print "FAIL: " n " saved key(s) found" (e ? " (" e " file(s) could not be read)" : "") ". Change each one, then clear the saved copies."; else if(e) print "INCOMPLETE: " e " file(s) could not be read. Nothing found in the rest."; else print "PASS: no saved keys found."}'; fi

It prints only the start of each key, so the full keys don't end up anywhere new. It skips the obvious fakes like your-key-here. PASS means nothing found.

Found keys?

Changing them is the fix and you can do it yourself. If it's a lot of keys across a team's laptops, send it to me. I fix one finding from $150, and you get the price in writing before I start.

Get it fixed

Let your AI run it, free

This one runs on the computer where you use Claude Code. Put your email in and your check link shows right here, with a copy in your inbox.

  • Free
  • No card
  • No password

Sent by VXSec, 2967 Dundas St. W. #1754, Toronto, ON M6P 1Z2. [email protected]

Your AI runs it on your side. VXSec never sees your code or data, only which check ran, when, and how many holes it found. Use a test copy for checks that change data. Nothing gets fixed until you say yes.

How to fix it

1. Change the key first. Deleting the file doesn't make a key safe, because something may already have read it. Make a new key in the service's dashboard, put it where your app reads it, check the app works, then delete the old one.

2. Clear the saved copies. Claude Code has a built-in command. See what it would delete first:

claude purge ~/path/to/your-project --dry-run
claude purge ~/path/to/your-project

It asks before removing anything. You lose those chats from /resume, so only do it after you've changed the keys. It doesn't touch ~/.claude/paste-cache/ or ~/.claude/uploads/, so delete any file the check listed there yourself. Then run the check again.

3. Optional: stop Claude reading your .env. Add this to ~/.claude/settings.json, merged in if it already has a permissions block. The cost: Claude can no longer open those files to help you debug.

{
  "permissions": {
    "deny": ["Read(//**/.env)", "Read(//**/.env.*)"]
  }
}

What still catches people

  • Deleting the chat and keeping the key. The key is still out.
  • Keys printed by commands. env, printenv and debug logs land in the chat too.
  • Running it once. If Claude reads a key again, it's saved again. Run the check now and then.

Questions

I never pasted my key. How is it in there?

Claude read a file with it, or a command printed it. Both are saved with the chat.

Does this send anything to Anthropic or to you?

The check runs on your computer and sends nothing anywhere.

Is this a Claude Code bug?

No. Saving chats is how resume works. It just means the folder needs the same care as your .env.

Before you launch

This is one check. Launch Gate runs six in one go on a test copy of your app, this one included, and gives you one page of results with proof. Members get it inside their own AI.

VXSec Membership

$19a month, or $190 a year

  • Workspace Setup
  • AI Reach Map
  • Agent Brakes
  • Launch Gate
  • Leaver Check
  • Every new helper, the day it's out
Join VXSec

Rather have it done for you? I fix it $150 and up, 20% off for members · Launch Review $297 once, I check and fix the top 3 · Built for you $1,500 a month and up

Want to practise on an app built to be broken first? Open the practice lab.