dotenv duplicate keys — does last win? (Aura's deterministic resolver)
Most dotenv parsers say "last duplicate key wins" — but the answer depends on which library you load. Aura uses a deterministic last-wins resolver and warns on every collision.
Short answer: in almost every popular dotenv loader, the last occurrence of a duplicate key wins. But the behaviour is not universal, and the silent override has caused enough production incidents that Aura treats it as a first-class warning.
Library matrix
| Library | Behaviour on duplicate | Warns? |
|---|---|---|
dotenv (Node) | last wins | no |
dotenv-flow | last wins (after layering) | no |
python-dotenv | last wins | no |
godotenv | first wins (!) | no |
dotenvy (Rust) | first wins by default; last wins with from_filename_override | no |
aura env | last wins | yes: every collision logged |
Why the inconsistency matters
When an AI agent generates a .env patch, it may unintentionally append a duplicate DATABASE_URL instead of editing the existing one. Whether that breaks production depends on which loader your runtime ships. Aura normalises the rule and surfaces the collision so the agent (and you) can decide intentionally.
Aura's deterministic rule
- Files are read top to bottom.
- For each duplicate key, the last occurrence wins: matching the Node and Python ecosystems most teams already expect.
- Every collision emits a structured warning: file, line of first occurrence, line of override, both values (redacted if matched against the secret patterns).
- If
AURA_ENV_STRICT=1is set, duplicates fail the load instead of warning.
Recommendation
Treat duplicate dotenv keys as a code smell, not a feature. Use aura env doctor in CI to fail builds when a collision sneaks in via an agent-generated diff.
In a .env file, does the last duplicate key win?
In most parsers yes — later assignments overwrite earlier ones as the file is read top to bottom. It is not guaranteed, though: the behaviour is per-library, and a few keep the first occurrence. Duplicate keys are worth avoiding rather than relying on.
What happens if you define the same variable twice in .env?
You get one value, usually the last, with no warning that the other existed. The failure mode is a variable edited near the top of the file that appears to have no effect because a stale copy sits further down.
Does .env override an existing environment variable?
Usually not. Most loaders will not overwrite a variable already present in the process environment, so a shell export silently beats the file. Overriding is generally an explicit option you have to turn on.
Aura Crew vs Claude Code Loops: the autonomous work-loop, compared
Claude Code defines four loop types — turn-based, goal, time, and proactive. Aura Crew is the same idea productized: a dependency-ordered work-loop with proof, collision-safety, and any agent. Full comparison.
Autonomous coding agent loops, explained: turn-based, goal, time, and proactive
A coding agent loop is an agent repeating cycles of work until a stop condition is met. The four types explained — turn-based, goal-based, time-based, proactive — with when to use each and how to keep quality high.
How to run multiple coding agents in parallel without merge conflicts
Running several AI coding agents at once collides on shared files. The fix: a worktree per agent, a live team radar, and soft-to-hard zone claims so parallel agents never touch the same symbol. How Aura Crew does it.
Goal-based agent loops: giving a coding agent a definition of done
A goal-based loop keeps a coding agent iterating until a success criterion is met. The trick is a deterministic definition of done — tests, a score, a proof — not an LLM guessing at "good enough." How to write one.