All posts 🔄

The Best dotenv Alternatives in 2026 — And Why .env Files Need to Go

Let's be honest: dotenv is a plaintext file sitting in your project directory with no encryption, no authentication, and no access control. It has 22 million weekly npm downloads. That's 22 million projects where every secret is one cat .env away from exposure.

We used .env files for years. Then we counted them — 47 across our projects. Same Stripe keys copy-pasted everywhere. Same database URLs. Any process running as our user could read all of them, including AI coding agents that now have full file system access.

So we replaced them. Here's what we tried and what we actually think about each option.

Why dotenv stopped being good enough

Dotenv came out of the Ruby community as a way to stop hardcoding credentials in source files. Move secrets to .env, add it to .gitignore, read values with process.env. Simple. Genuinely better than what came before.

But the world changed. In 2012, the main risk was accidentally committing a file to git. In 2026, the problems are bigger:

Dotenv was never a security tool. It was a convenience pattern. That's fine for 2012. It's not fine when AI agents are reading your project directory.

6 dotenv alternatives, compared honestly

We tested each of these as a replacement for .env files in local development. Not CI/CD — that's a different problem with different tools. This is about the secrets sitting on your laptop right now.

1. NoxKey — macOS Keychain + Touch ID

Full disclosure: we built NoxKey. So take this section with that in mind. We'll be honest about the limitations.

NoxKey stores secrets in the macOS Keychain, protected by the Secure Enclave and Touch ID. It's a menu bar app with a built-in MCP server — Claude Code, Cursor, and other MCP-aware agents call its tools directly, no shell wrapper required.

// Agent stores a secret — raises a Touch ID approval sheet
noxkey_set(account: "myorg/project/STRIPE_KEY", clipboard: true, field_type: "api_key")

// Agent retrieves it — value lands in the shell env, never in chat
noxkey_get(account: "myorg/project/STRIPE_KEY")
// → "Run this in Bash: source '/tmp/noxkey-handoff-…sh'"

// Import an existing .env file — drag onto the menu bar app,
// or run a two-step MCP scan + admin import for an agent-driven migration
noxkey_scan(path: "~/code/api", suggested_org: "myorg", suggested_project: "project")
noxkey_admin(action: "import", entries: […])

The thing we're most proud of: when an agent calls noxkey_get through the MCP server, the response is shaped to keep the secret out of the conversation transcript. The agent gets a one-shot handoff path it has to source in its shell — value lands in the process environment, file self-deletes, raw bytes never reach the model. For non-MCP shell callers, the menu bar app falls back to walking the process tree and applies the same handoff response if it spots an agent runtime.

And, unique to this list: NoxKey ships an end-to-end-encrypted share. Right-click any secret, pick "Share," and you get a single .noxkey file you can hand off through iMessage, AirDrop, Signal — anything you already trust. The recipient double-clicks it into their NoxKey, with their Touch ID, into their Keychain. No shared vault, no NoxKey backend in the loop. For higher-risk handoffs the Medium tier wraps the content key under a passphrase you tell the recipient out-of-band.

Pros: Free and open source. No account, no cloud. Hardware encryption via Secure Enclave. Touch ID on every access. MCP-native agent integration with encrypted handoff. End-to-end-encrypted share files for handing a secret to a specific teammate. Fast — secrets load in milliseconds.

Cons: macOS only. Full stop. If you're on Linux or Windows, this isn't an option. No shared team vault either — sharing is a one-shot encrypted file, not continuous sync. If you need server-backed access control and audit logs across a whole team, you'll want one of the cloud options below.

Price: Free, open source.

2. 1Password CLI (op)

If your team already pays for 1Password, their CLI is a solid choice. It lets you reference secrets from your vault in shell commands and config files without maintaining separate .env files.

# Reference a secret
$ op run --env-file=.env -- npm start

# Inject into a command
$ op read "op://Development/Stripe/secret_key"

We've used this on projects where the team was already on 1Password. It works well. The op run command is genuinely nice — point it at an .env template with 1Password references and it resolves them at runtime.

Pros: Cross-platform. Team sharing with real access control. Secret rotation and audit logs. Solid CI/CD integrations. Actively maintained by a company that takes security seriously.

Cons: Requires a 1Password subscription ($36/year per user). Your secrets live in 1Password's cloud — not local-first. The CLI can be sluggish on first invocation (it phones home). No awareness of AI agents reading your environment.

Price: $36/year (Individual), $60/year (Families), $96/year (Teams).

3. direnv

We love direnv for what it does. It loads and unloads environment variables based on the current directory — cd into a project and your env is set, cd out and it's gone. Elegant.

# .envrc
export STRIPE_KEY="sk_live_..."
export DATABASE_URL="postgresql://..."

Here's the thing though: direnv isn't a secrets manager. It's a loading mechanism. Your .envrc is still a plaintext file on disk with the same problems as .env. We still use direnv — but we pair it with NoxKey so the .envrc calls a secrets manager instead of containing secrets. More on that below.

Pros: Elegant directory-scoped loading. Works with any shell. Can source secrets from other tools (combine with op or noxkey). Free and open source.

Cons: Not a secrets manager. Your .envrc is still plaintext on disk. No encryption. No authentication. Solves the loading problem, not the storage problem. Same AI agent risk as .env if you put actual values in it.

Price: Free, open source.

4. HashiCorp Vault

Vault is the enterprise standard for secrets management. Dynamic secrets, encryption as a service, fine-grained access policies. If you run production infrastructure at scale, you probably already have it — and your security team definitely has opinions about it.

# Read a secret
$ vault kv get -field=api_key secret/myproject/stripe

We respect Vault, but we'd never recommend it for local development unless your org already runs it. The operational overhead is enormous. You need a Vault server, you need to configure auth backends, you need to manage policies. It's infrastructure, not a dev tool.

Pros: Dynamic secrets that auto-expire. Comprehensive audit logging. Encryption as a service. Fine-grained access policies. Every compliance team loves it.

Cons: Massive overkill for local development. You need to run a Vault server (or pay for HCP Vault). Complex setup with a steep learning curve. It solves enterprise problems, not "I have 47 .env files on my laptop" problems.

Price: Free (self-hosted, OSS), HCP Vault starts at ~$0.03/secret/month, Enterprise pricing on request.

5. Doppler

Doppler is a cloud SaaS for managing secrets across environments. It syncs secrets to your local machine, CI/CD, and cloud providers through one dashboard. For small teams that want a managed solution without running their own infrastructure, it's well-designed.

# Run a command with secrets injected
$ doppler run -- npm start

# Set a secret
$ doppler secrets set STRIPE_KEY sk_live_...

The dashboard is clean, the CLI is straightforward, and the environment syncing (dev/staging/prod) actually works well. Our concern is the same one we have with any cloud-hosted secrets tool: your secrets live on someone else's servers. For some teams that's fine. For us, it's a dealbreaker.

Pros: Clean dashboard. Team sharing with roles and permissions. Environment syncing that actually works. Good CI/CD integrations. Version history on secrets.

Cons: All your secrets live in Doppler's cloud. Free tier limited to 5 team members. Vendor lock-in — migrating away means extracting everything. No offline access. No AI agent awareness.

Price: Free (up to 5 users), Team $6/user/month, Enterprise pricing on request.

6. macOS Keychain (native security CLI)

Here's the thing nobody talks about: you already have a hardware-encrypted secrets manager on your Mac. The Keychain is backed by the Secure Enclave, and you can access it from the terminal with the security command.

# Store a secret
$ security add-generic-password -a "$USER" -s "myproject-stripe-key" \
    -w "sk_live_..." -T ""

# Retrieve it
$ security find-generic-password -a "$USER" -s "myproject-stripe-key" -w

We tried this before building NoxKey. The security is genuinely good — hardware encryption, Touch ID, the whole stack. The developer experience is genuinely terrible. No namespacing, no import/export, no session management. The security CLI feels like it was designed for system administrators in 2005, not developers in 2026. (We wrote about the experience in detail.)

Pros: Free. Already installed. Hardware encryption. No third-party dependencies. Touch ID support (when you get it configured correctly).

Cons: Awful DX. The security CLI wasn't designed for managing developer secrets. No namespacing, no bulk import, no session management, no AI agent detection. You'll spend more time fighting access control groups than writing code.

Price: Free (built into macOS).

Comparison table

Tool Encryption at rest Authentication AI agent safe Platform Team sharing Price
dotenv (.env) None None No Any Copy files Free
NoxKey AES-256 at rest (Keychain) · ChaChaPoly for handoff & shares Touch ID Yes (MCP-native) macOS E2E share files (no server) Free
1Password CLI AES-256 Master password / biometrics No Any Yes $36+/yr
direnv None None No Any (Unix) No Free
HashiCorp Vault AES-256-GCM Tokens / OIDC / LDAP No Any Yes Free (OSS) / $$
Doppler AES-256 SSO / password No Any Yes Free–$6/user/mo
macOS Keychain AES-256 (Secure Enclave) Touch ID / password No macOS No Free

Which one should you actually use?

Here's how we think about it:

Solo developer on macOS who values privacy: NoxKey. Free, local-first, hardware encryption, AI agent detection. Get it on the Mac App Store, import your .env files, delete them. Done in an afternoon.

Team already paying for 1Password: 1Password CLI. You're paying for it anyway — use it. op run integrates cleanly into existing workflows, and you get team sharing without adding another tool.

Enterprise with compliance requirements: HashiCorp Vault. It's overkill for local dev, but if your security team requires it, it checks every box they care about.

Small team that needs cloud sync: Doppler. Clean experience, reasonable pricing, good integrations. You're trusting them with your secrets, but for many teams that trade-off makes sense.

Already using direnv: Keep it — but pair it with a real secrets backend. Use direnv for loading and 1Password's op for the storage layer (1Password keeps a CLI, NoxKey doesn't ship one). Your .envrc should call a secrets manager, not contain secrets:

# .envrc — resolves at shell load, no plaintext on disk
export STRIPE_KEY="$(op read 'op://Development/Stripe/secret_key')"
export DATABASE_URL="$(op read 'op://Development/Postgres/url')"

If you're on NoxKey instead, the equivalent flow is per-agent: open the menu bar app once, enable session unlock, and let your agent call noxkey_get(account: "myorg/project/STRIPE_KEY", session: "4h") at the start of its task. The first call takes Touch ID; subsequent reads in the same workspace skip biometric auth for the window you set.

Cross-platform team (Linux + macOS + Windows): 1Password CLI or Doppler. NoxKey and native Keychain are macOS-only. Vault works everywhere but the setup cost is steep.

How to migrate away from .env files

Whatever tool you pick, the migration follows the same pattern:

  1. Find every .env file on your machine. You probably have more than you think.
    $ find ~/dev -name ".env" -not -path "*/node_modules/*" -not -path "*/.git/*" | wc -l
  2. Import each one into your chosen tool.
  3. Update your workflow — replace source .env or dotenv calls with your tool's CLI equivalent.
  4. Delete the .env files. Not archive. Delete. A plaintext file you're "not using anymore" is still a plaintext file on disk.
  5. Update .env.example files in your repos to document which keys are needed, without values.

We did this across 47 projects in one afternoon. Here's the full story.

Key Takeaway
dotenv stores production credentials as plaintext files with zero protection. In 2026, with AI agents reading project files and supply chain attacks targeting credentials, that's not good enough anymore. Pick a real secrets manager — any of the six above — and delete your .env files. It takes an afternoon. The risk of not doing it gets worse every month.

Frequently asked questions

What's the best dotenv alternative in 2026?
Depends on your setup. For solo macOS developers, NoxKey gives you free, hardware-encrypted storage with Touch ID and AI agent detection. For teams, 1Password CLI or Doppler handle cross-platform secrets with sharing built in. For enterprises, HashiCorp Vault remains the standard.
Why should I replace .env files?
.env files store secrets as plaintext with no encryption, no authentication, and no access control. AI coding agents (Claude Code, Cursor, Copilot) can read them and expose secrets in their context windows. Supply chain attacks target them. And once you have dozens of them, rotating a key becomes a nightmare. More on why .env files are a liability.
Is direnv a good replacement for dotenv?
direnv solves a different problem — it loads environment variables per directory, which is genuinely useful. But it still stores secrets in plaintext .envrc files. Use direnv for the loading mechanism, but pair it with a real secrets manager (NoxKey, 1Password, etc.) for storage.
Can I use dotenv alternatives with AI coding agents?
Most secrets managers protect secrets at rest but expose them as plaintext environment variables at runtime — which means an AI agent can still read them. NoxKey is the only tool on this list that actively detects AI agents via process tree inspection and blocks raw secret values from entering the agent's context.
How do I migrate from .env files to a secrets manager?
Find every .env file on your machine, import them into your chosen tool, then delete the originals. With NoxKey: drag each .env onto the menu bar icon, confirm the keys it found, and delete the file. We migrated 47 projects in one afternoon.