Find API keys in .env files across all your projects
By Flavio
Audit every .env and .dev.vars file in your projects folder with Secrets Free, and see which keys a push would publish and which only sit on your Mac.
After a few years, your projects folder holds dozens of .env files. Some belong to apps you still deploy. Others sit in prototypes you abandoned, still holding a live Stripe key or a database password. You don’t remember which keys are where, which are still valid, or whether every one of those files is ignored by Git.
Checking by hand means opening each file, which prints every key on your screen. And .gitignore mistakes are easy to miss: a .env rule doesn’t cover .env.production.
Secrets Free has a command, secretsfree, that reads those files for you and prints each key masked. By the end you’ll have a list of every key in every project, split into the ones a push would publish and the ones that only live on your Mac, and you’ll know how to fix each kind.
What you need
Secrets Free runs on macOS 14 or later, on Apple silicon and Intel Macs. After purchasing, download it from your Polar receipt. The receipt has two zips: Secrets-Free-1.1.0.zip with the Mac app, and Secrets-Free-1.1.0-source.zip with the full MIT-licensed source. It always has the latest version of both.
This tutorial uses the secretsfree command, which you build from the source zip. That needs Xcode 26 or a Swift 6.2 toolchain. Check yours before you start:
swift --version
It should report Swift 6.2 or later. Git needs to be on your PATH, because the scan asks Git which files are tracked and which are ignored. The ordinary Git from the macOS command-line developer tools is enough.
You also need jq for two of the steps, to turn the JSON report into short lists. macOS 15 and later include it at /usr/bin/jq. On macOS 14, install it with Homebrew.
Everything runs locally. The scanner reads folders on your Mac, doesn’t clone anything, and uploads nothing.
In the examples, recipe-box, hostingpicker, weather-worker and old-landing are example projects in /Users/flavio/dev, with random fake keys I generated for this page. The output is from real runs of secretsfree 1.1.0, with only those paths changed.
Install the command
The Mac app has an Ignored files option that does the same wider scan, one folder at a time. For a whole projects folder, the command is the better tool: you can loop over projects, filter JSON, and compare two scans. The app bundle doesn’t contain it, though. It lives in the source zip, and an install script builds it in release mode and links it into a folder of your choice. Without this step, every command below fails with “command not found”.
Unzip the source, open a terminal in its folder, and run:
./Scripts/install-cli.sh
The script runs swift build, then links the binary into ~/.local/bin and prints the link it made, in this shape:
Installed /Users/flavio/.local/bin/secretsfree -> /Users/flavio/Downloads/Secrets-Free-1.1.0-source/.build/release/secretsfree
If ~/.local/bin isn’t on your PATH, it adds a line saying so. Pass another folder to link it elsewhere, like ./Scripts/install-cli.sh /opt/homebrew/bin. The link points into the source folder, so keep that folder where it is. Check the install:
secretsfree version
1.1.0
Scan every project from the parent folder
Here’s the trick that makes a full audit one command. Inside a Git repository, secretsfree scan asks Git for the tracked and untracked files and leaves out ignored ones, because that’s what a push would publish. That’s why a normal scan of a project never shows its .env. Your projects folder itself isn’t a repository, though. There the scanner walks every file, skipping only .git and heavy folders like node_modules, .next, .venv and vendor. Ignored or not, every .env in every project gets read.
Example 1: auditing the whole projects folder. Point the scan at the parent folder:
secretsfree scan ~/dev
Secrets Free · /Users/flavio/dev
hostingpicker/.env.example
CRITICAL OpenAI API key line 1
sk-p••••••••••••••••••24 #3bbc283ab91c
OPENAI_API_KEY=sk-p••••••••••••••••••24
hostingpicker/.env.production
CRITICAL .env file file name
/.en••••••••••on #04e88391ef80
CRITICAL OpenAI API key line 1
sk-p••••••••••••••••••iN #3b4631fc413b
OPENAI_API_KEY=sk-p••••••••••••••••••iN
old-landing/.env
CRITICAL .env file file name
•••••• #cc229c2a72b9
CRITICAL Resend API key line 1
re_u••••••••••••••••••h8 #dd4f75c119ad
RESEND_API_KEY=re_u••••••••••••••••••h8
recipe-box/.env
CRITICAL .env file file name
•••••• #e0d8a70bc00b
CRITICAL Stripe secret key line 1
sk_l••••••••••••••••••UZ #981cb417f398
STRIPE_SECRET_KEY=sk_l••••••••••••••••••UZ
CRITICAL Database URL with password line 2
9382••••••••••••Mn #69292253c3f8
DATABASE_URL=postgres://recipes:9382••••••••••••[email protected]:5432/recipes
weather-worker/.dev.vars
CRITICAL Wrangler .dev.vars file file name
•••••• #b0953fc46edf
CRITICAL Cloudflare API token line 1
YK0f••••••••••••••••••qQ #3bd4e8601167
CLOUDFLARE_API_TOKEN=YK0f••••••••••••••••••qQ
10 critical · 14 files · 0.0s
Each environment file shows up twice. The .env file finding fires on the file name alone, and the next lines are the keys inside it, matched by provider rules. Masking keeps the first four and last two characters, so you can still tell a Stripe live key from a test key by its prefix. The .dev.vars file is Wrangler’s local secrets file for Cloudflare Workers, and it gets the same treatment.
Two files are missing, on purpose. recipe-box/.env.example has empty values, and the scanner treats .env.example, .env.sample and .env.template as safe names. The other one is a .env.test inside recipe-box/node_modules, skipped with the rest of that folder. The command exits with status 1, because the findings reach the default threshold of high.
Turn the findings into an inventory
Ten findings across four projects is readable. Two hundred across sixty projects isn’t. What you want is one line per key: the project, the kind of key, and the file. That’s the list you’ll work through when you decide what to rotate. The JSON report has everything you need. Each finding has a ruleName, a path relative to the scan root, and a location. Keys found inside a file have a workingTree location. File-name findings have a fileName location, so filtering on workingTree keeps the keys and drops the duplicates.
secretsfree scan ~/dev --no-identity --json --fail-on never \
| jq -r '.findings[] | select(.location.workingTree) | "\(.path | split("/")[0]) \(.ruleName) \(.path)"'
hostingpicker OpenAI API key hostingpicker/.env.example
hostingpicker OpenAI API key hostingpicker/.env.production
old-landing Resend API key old-landing/.env
recipe-box Stripe secret key recipe-box/.env
recipe-box Database URL with password recipe-box/.env
weather-worker Cloudflare API token weather-worker/.dev.vars
--no-identity skips the email, home path and private IP rules, which get noisy across a real projects folder. --fail-on never keeps the exit status at 0, so the pipe never looks like a failure. The secret field in the JSON stays masked unless you add --reveal, and there’s no reason to here.
Add --min-severity critical to see only the critical ones, and --quiet to drop the header and the summary line. Running the same scan again gives the same fingerprints, because a fingerprint is a hash of the rule, the path and the value. The path is relative to the folder you scanned, though. Scanned from inside hostingpicker, the same .env.example key is #829b555c6734, not #3bbc283ab91c.
That matters for allowlisting. secretsfree ignore writes to .secretsfree.json in the folder you scanned, and each scan only reads the one in its own root. An entry you add from ~/dev does nothing when you scan the project. I wouldn’t allowlist .env files at all: they’re exactly what this audit is for.
Split what would ship from what stays local
The inventory treats every key the same, but they aren’t the same risk. A key in an ignored .env stays on your Mac unless the Mac itself leaks it. A key in a .env that Git doesn’t ignore goes out with your next git add -A and push. So for each repository, compare two scans. The default one shows what a push would publish. Adding --include-ignored reads ignored files and heavy folders as well. The difference is what only lives locally.
Run this from ~/dev:
cd ~/dev
for dir in */; do
name=${dir%/}
if [ ! -d "$dir/.git" ]; then
printf '%-16s not a Git repo, check it by hand\n' "$name"
continue
fi
ships=$(secretsfree scan "$dir" --no-identity --json --fail-on never | jq '.findings | length')
total=$(secretsfree scan "$dir" --include-ignored --no-identity --json --fail-on never | jq '.findings | length')
printf '%-16s %s would ship, %s local only\n' "$name" "$ships" "$((total - ships))"
done
hostingpicker 3 would ship, 0 local only
old-landing not a Git repo, check it by hand
recipe-box 0 would ship, 5 local only
weather-worker 0 would ship, 2 local only
hostingpicker is the one to fix today. recipe-box and weather-worker keep their keys in ignored files, which is how it should be. The recipe-box count includes the .env.test inside node_modules, because --include-ignored also turns off the heavy-folder skipping. A per-project --include-ignored scan can be slow on a large node_modules, which is why the folder-wide audit above doesn’t use it.
old-landing has no Git repository, so “would ship” means nothing there. From the parent scan you know it holds a Resend key. If the project is dead, revoke the key in the provider’s dashboard and delete the file. Deleting is permanent and Secrets Free never deletes anything for you, so revoke first: once the file is gone, the masked prefix in your inventory is the only clue to which key it was.
Fix a .env file that Git doesn’t ignore
hostingpicker ignores .env, but someone created .env.production next to it. A .gitignore line matches names, not prefixes: .env doesn’t cover .env.production, .env.local or .env.staging. The scanner’s rule is wider than that. It flags any file whose name starts with .env, apart from the safe example names. That gap between your ignore rules and the scanner’s rule is what the “would ship” count catches. Leave it alone and the next git add -A stages a production key.
Example 2: an .env variant that slipped through. Ask Git whether it ignores the file:
cd ~/dev/hostingpicker
git check-ignore -v .env.production
It prints nothing and exits with 1, which means “not ignored”. Add a wildcard rule and keep the example file visible. Open .gitignore and make it read:
.env
.env.*
!.env.example
node_modules
The ! line re-includes .env.example, because .env.* would hide it too. If the order of those lines confuses you, Glob patterns explained covers how .gitignore reads them. Check again:
git check-ignore -v .env.production
secretsfree scan
.gitignore:2:.env.* .env.production
Secrets Free · /Users/flavio/dev/hostingpicker
.env.example
CRITICAL OpenAI API key line 1
sk-p••••••••••••••••••24 #829b555c6734
OPENAI_API_KEY=sk-p••••••••••••••••••24
1 critical · 3 files · 0.1s
The production file is ignored now. The scan still finds a real-looking OpenAI key in .env.example, a file that’s meant to be committed. It’s a different key from the production one, probably pasted while setting up the project. The safe name doesn’t protect it, because the provider rules check the content of every file. Empty the value, so the line reads OPENAI_API_KEY=, and scan again:
Secrets Free · /Users/flavio/dev/hostingpicker
✓ No findings. 0 findings · 3 files · 0.1s
That example file is already committed, so its key is in the history. Treat it as published if the repository was ever pushed, and rotate it.
Stop tracking a .env file that’s already committed
The opposite case is worse and more common in old projects. The .env file was committed before anyone added a .gitignore. Adding the rule afterwards changes nothing, because .gitignore only applies to untracked files. Git keeps tracking a file it already knows, and the default scan keeps reporting it, since it reads tracked files. If you don’t untrack it, every push keeps publishing the current values. Untracking fixes the future only, since earlier commits still carry the key.
Example 3: a .gitignore that doesn’t work. Say you turn old-landing into a repository, commit everything, and only then add .env to .gitignore. The scan still reports the file:
cd ~/dev/old-landing
secretsfree scan --quiet --fail-on never
.env
CRITICAL .env file file name
•••••• #867ca56c343e
CRITICAL Resend API key line 1
re_u••••••••••••••••••h8 #6ab903a2c5bb
RESEND_API_KEY=re_u••••••••••••••••••h8
git ls-files confirms it: .env is listed next to index.html. Remove it from the index, not from the disk, and commit:
git rm --cached .env
git add .gitignore
git commit -m "Stop tracking .env"
secretsfree scan
Secrets Free · /Users/flavio/dev/old-landing
✓ No findings. 0 findings · 2 files · 0.1s
--cached keeps your local .env in place, so the project still runs. The old commit still has the key, though. A history scan shows it with the commit that added it:
secretsfree scan --history --quiet --fail-on never
.env
CRITICAL .env file history only · commit 197843c9 by Flavio, 2026-11-17
•••••• #867ca56c343e
CRITICAL Resend API key history only · line 1, commit 197843c9 by Flavio, 2026-11-17
re_u••••••••••••••••••h8 #6ab903a2c5bb
RESEND_API_KEY=re_u••••••••••••••••••h8
If that commit was ever pushed, rotate the key. Scan your Git history for leaked API keys before you push walks through history scans and a pre-push hook that stops this before it happens. Once your keys are sorted, a manager like 1Password can hold them outside your projects folder entirely: see How to manage environment variables with 1Password.
Hand the audit to a coding agent
The masked output makes this safe to delegate. An agent can run the inventory and the loop, then fix .gitignore files and untrack committed .env files, without any key reaching its context. Two rules keep it that way: it never opens a .env file, and it never passes --reveal. Rotation stays with you, because it happens in each provider’s dashboard. Let a coding agent check your project for API keys without seeing them has the AGENTS.md rules for that setup.
If something looks wrong
- If a project’s
.envdoesn’t show up in a per-project scan, Git ignores it, which is the default behavior. Add--include-ignored, or scan the parent folder. - If the parent scan misses a
.envyou know exists, check whether it sits inside a skipped folder likenode_modules,.venvorvendor. Scan that project with--include-ignoredto read those too. - If you see
secretsfree: /Users/flavio/dev/recipe-bx is not a folder.with exit status3, the path has a typo or the folder moved. - If you see
Unknown option --include-ignore. Run 'secretsfree help' to see the options., the flag is misspelled. It’s--include-ignored, and the command exits with2. - If a key still shows up after you added the file to
.gitignore, the file is tracked. Rungit ls-files, thengit rm --cachedon it. - If an ignored fingerprint keeps coming back, check which folder you scanned when you ran
secretsfree ignore. The allowlist lives in the scan root, and fingerprints change with it. - If
.env.examplegets flagged, it holds a value that matches a provider rule. Empty the value, and rotate the key if the file was ever pushed. - If
secretsfreeisn’t found after the install,~/.local/binisn’t on yourPATH. Add it to your shell config, or rerun the script with a folder that is.
Get Secrets Free
Find API keys, tokens, credentials files and identity leaks before they ship. A native Mac app and CLI with full MIT source.
See Secrets Free → · Read the docs · $20. See the app page for tax details, with full source code.
Want me to talk about your product? You can sponsor this site.