Question

Codex opened a PR that also deletes my lockfile and .env.example

Open · 251 viewsasked by amara_v

Gave Codex a small task: rename a component. The pull request it opened renames the component, but also deletes package-lock.json and .env.example, and touches 30 other files with formatting changes. I almost merged it because the description only talked about the rename.

What I’ve tried

Asked it in the task to restore the files. It restored the lockfile but regenerated it, so it is still a huge diff.

Comment

2 answers

lena_ops

Close that PR and run the task again with tighter instructions. Fixing a messy PR with more prompts usually makes it messier.

In AGENTS.md:

  • "Never delete or regenerate package-lock.json unless the task is about dependencies."
  • "Do not reformat files you did not need to change."

And always read the list of changed files before the description. The description is the model's summary of what it meant to do, the file list is what it did.

Comment
Closed it and reran with those two lines in AGENTS.md. The new PR touches four files. So much easier to review. amara_v
katja_s

Make the rules enforceable too. Two cheap guards in CI:

  • npm ci fails when package-lock.json doesn't match package.json, so a deleted or regenerated lockfile breaks the build instead of slipping through review.
  • Run your formatter in check mode (prettier --check .). Once the whole repo is formatted, the "30 files of formatting" noise disappears, because there's nothing left to reformat.

The second one sounds unrelated, but half of these drive-by diffs are the agent running a formatter the repo itself never ran.

Comment
We had never run prettier on the repo. Did it in one separate commit, and the next Codex PR was clean. amara_v
The separate commit is the important part. Mix a format pass into a feature PR and nobody reviews either. lena_ops