.env · transform🔒 100% client-side — never leaves your browser

ENV Cleaner: remove duplicate keys and empty values

Clean up a .env file in one paste: the ENV cleaner removes duplicate keys (the last definition wins, like dotenv), drops empty values, optionally strips comments, and leaves every remaining line exactly as you wrote it.

By Aliniyaz Mamat · last reviewed

Be the first to rate
# My env file

API_KEY=def
DEBUG=true
# this is a comment
PORT=3000

Key takeaways

  • ✓Duplicates: only the last definition of a key is kept, at its own position. That is the value dotenv would load anyway.
  • ✓Values are never rewritten: quotes, export and spacing inside values stay byte-for-byte the same.
  • ✓Comments are kept unless you switch on strip comments; then full-line and inline comments are removed, but a # inside quotes stays.
  • ✓Always on: trailing whitespace is trimmed and runs of blank lines collapse to one.

What it does

  • ▸Removes duplicate keys, keeping the last definition (dotenv behaviour)
  • ▸Drops keys with empty values
  • ▸Optionally strips full-line and inline comments
  • ▸Trims trailing whitespace and collapses blank lines
  • ▸Never changes quotes, export prefixes or values. 100% client-side

Privacy

Runs 100% in your browser. Your .env never touches our servers.

client-side only

Usage examples

Case 1 · Duplicate key, last one wins
API_KEY=abc
DEBUG=true
API_KEY=def
DEBUG=true
API_KEY=def
Case 2 · Empty values and blank lines
NODE_ENV=production


SENTRY_DSN=
PORT=3000   
NODE_ENV=production

PORT=3000
Case 3 · Strip comments, keep # in quotes
# mail settings
SMTP_PASS="a#b" # rotated 2026-10
SMTP_HOST=mail.example.com
SMTP_PASS="a#b"
SMTP_HOST=mail.example.com

When to use this tool

  • →An old .env full of copy-pasted blocks and keys defined twice
  • →After merging files from several developers or environments
  • →Before sharing a .env with a teammate or attaching it to a ticket (still: share secrets through a vault, not chat)
  • →Cleaning a CI-generated .env before it is uploaded as an artifact

Common mistakes

  • ⚠Assuming the first duplicate wins. In dotenv the last one does, and so does this tool. Check which value you really want before deleting
  • ⚠Removing empty values your app needs: FEATURE_FLAG= can mean "set but empty", which is different from missing
  • ⚠Stripping comments from a shared file: they often explain why a key exists
  • ⚠Cleaning instead of validating: syntax errors (missing =, bad key names) are not fixed. Run the .env validator first

Why duplicate keys in .env are dangerous

A duplicated key does not throw an error. The loader silently picks one value, and which one depends on the tool:

LoaderDuplicate key in the same fileAlready set in the environment
dotenv (Node.js)last value winsenvironment wins (unless override: true)
node --env-filelast value winsenvironment wins
python-dotenvlast value winsenvironment wins (unless override=True)
Docker Compose env_filelast value winsenvironment: in compose.yaml wins

The typical bug: someone adds DATABASE_URL at the bottom of a long file to "try something", forgets it, and staging talks to the wrong database for a week. The cleaner keeps the effective value and removes the dead line, so what you read is what the app gets.

What the cleaner changes and what it leaves alone

InputDefault resultOption
second API_KEY= further downfirst one removeddedupe
SENTRY_DSN=removedremove empty values
# comment linekeptremoved with strip comments
PASS="a#b" # notekept as isbecomes PASS="a#b" with strip comments
export TOKEN='x'kept as isnever changed
trailing spaces, 3 blank linestrimmed, one blank linealways

To sort keys or align the = signs, run the result through the .env formatter. To combine several files first, use the ENV merger and then clean the merged output.

Finding duplicates on the command line

# list keys defined more than once
grep -oE '^(export )?[A-Za-z_][A-Za-z0-9_]*=' .env \
  | sed -E 's/^export //; s/=$//' | sort | uniq -d

Add it to a pre-commit hook or a CI step that runs on .env.example to stop duplicates from coming back.

Frequently asked questions

Does the cleaner keep the first or the last duplicate?

The last one, at its own line. With API_KEY=abc on line 2 and API_KEY=def on line 8, line 2 is removed and API_KEY=def stays on line 8, the value dotenv loads at runtime.

Will it change my values or quotes?

No. Kept lines are copied exactly, including single or double quotes and the export prefix. Only whole lines are removed, and with strip comments the trailing comment is cut off.

Are comments removed?

Only with strip comments switched on. A # inside quotes, like PASS="a#b", is part of the value and is never treated as a comment.

Does it handle export KEY=value?

Yes. export lines are recognised for duplicate detection and kept unchanged in the output.

Is it safe to paste a production .env?

The cleaning runs in your browser and nothing is uploaded. If you prefer not to paste real secrets anywhere, run it on the .env.example or use the shell command above.

Related tools

Learn more

coming soon

Get notified when env syncing launches

We're building a tiny tool to keep .env files in sync across teammates and environments. Leave your email — no spam, just a single launch ping.

We use your address only for this launch email. You can ask us to delete it at any time. Privacy policy