Agent deleted my .env.local and CI still passed
Spent Friday night chasing why staging had no DATABASE_URL.
Turns out Claude Code "cleaned up unused files" and yanked .env.local out of the working tree. Diff looked fine in the chat. CI on main still green because GitHub Actions injects secrets.
Only caught it when the preview deploy returned PrismaClientInitializationError: Environment variable not found: DATABASE_URL.
Anyone else gating agent commits behind a git status screenshot now? Or am I just paranoid.

5 comments
Join the discussion
Log in to comment.
yeah that one got me last month. agent decided
.env*was "noise" and wiped the whole pattern.now i run
git status --shortbefore every accept. if anything outside the files i named shows up, reject. boring but cheaper than a friday night.We added a pre-push hook that fails if any of these vanish from the tree:
.env.local,docker-compose.yml,fly.toml.Also log agent file deletions to a Grafana panel — last week we saw 14 silent removals across 3 repos. Staging only caught 2 of them. The Prisma error is a gift; the quiet ones are worse.
the pre-push hook idea is good but mine still fired after the file was already gone from my working tree.
i ended up with a tiny
git ls-files --error-unmatch .env.localin the hook — if the path isn’t tracked/present it aborts before push. ugly, works on mac and linux.do you keep .env.local in the repo as a tracked empty stub or is it fully gitignored?
Same PrismaClientInitializationError here last Wednesday. Staging was fine for two deploys because Actions injects DATABASE_URL; my laptop was a brick.
I added a Makefile target
check-local-envthat fails if.env.localis missing any of DATABASE_URL / REDIS_URL / STRIPE_SECRET_KEY. Wired it into the agent’s “done” checklist so it can’t finish a session without that passing.Still doesn’t stop a delete mid-session, but it catches the silent ones before I open a PR.
Accept-all is how I lost a Friday too. Claude Code and Cursor both scored high on my “helpful” board until one of them treated
.env*like temp junk.I now run agents with a deny list: no deletes under
.env*,secrets/, or*.pem. Slower, but I haven’t chased a missing DATABASE_URL since.Paranoid? maybe. Cheaper than another staging mystery though.