On 10 Nov I wanted a quick look. I typed node autopilot.mjs --status, expecting a read-only look at my content system. It didn't give me a look. It ran the night. Three approvals went through and a batch started.

Nothing crashed, and that was the problem: the script did its normal job. A script that spends money or approves work should refuse any argument it doesn't recognise, and its safe look should be a separate command, never a flag. The rest of this piece shows how to add both and how to prove they work.

Why an ignored flag isn't harmless

My script read its options with a small helper: look a name up in process.argv, return a default if it isn't there. There was no list of allowed names. --status was never looked up, so as far as the script was concerned, I had typed nothing at all.

The funny part is that the read-only look already existed. The script's header documents status as a plain word, next to install and uninstall. I typed it with two dashes in front. Close enough for me, invisible to the script.

An unknown flag looks harmless because the script just does its normal job. For most scripts that's fine. Mine approves episodes on my recorded instruction, grows the plan, starts the team batch and spends Claude budget up to a nightly cap. For that kind of script, the normal job is exactly the dangerous part.

Before

Ignore what you don't know

  • A typo falls through to the default path
  • The default path is the real run
  • You find out from what it already did

After

Refuse what you don't know

  • A typo stops the script with exit 1
  • Nothing is read, nothing is spent
  • You find out from one line on the screen

Step one: refuse anything you don't know

The fix went in on 12 Nov. A function, unknownArgs(), lists whatever the command line holds that the script doesn't know. main() stops on that list with exit code 1, before it reads a file or spends anything. The script gained 20 lines. Here is the shape of it, as a sketch you can adapt:

A guard at the top of main()

If you're starting fresh in Node, you may not need to write this at all. util.parseArgs has a strict option that defaults to true, and it throws on unknown arguments. It's been in Node since v18.3.0 and v16.17.0. POSIX getopt() behaves the same way: an option it doesn't know returns '?' and gets reported. Node's parseArgs and POSIX getopt both refuse by default. My little helper was the odd one out.

Step two: make the safe look its own command

A look-only flag sits right next to the real run, one typo away from it. I already had --dry-run, which the Preview button uses. It didn't save me, because nothing stopped a wrong flag from reaching the night.

The script already documented status as a plain word, next to install and uninstall. That's the shape I'd pick for any safe look: a word, not a flag. And with the guard in place, the near miss I typed is now an unknown argument, so it stops with exit 1 instead of starting a batch.

Step three: check every caller

A strict script breaks any caller that was quietly passing junk. So after the fix I went through every caller and made sure each one passes only known arguments:

  • The scheduled launchd job passes none.
  • Home's Run now passes none.
  • Preview passes --dry-run.
  • install passes --at.
  • uninstall passes its own word.

Test both in a few minutes

  1. 1Feed it nonsenseRun it with --nope. Check echo $? prints 1, and that nothing changed: no approval, no spend, no new log of a run.
  2. 2Feed it the near missRun it with the mistake you'd really make. For me that's --status. It should stop exactly like the nonsense did.
  3. 3Run the real lookRun status and confirm it only reads. If it touches anything, it isn't a look.
  4. 4Pin it in a testWrite the first two cases into your test file so the guard can't quietly disappear in a later refactor.

0

lines of test that came with the fix

next to the 20 lines the guard added to the script

The idea I keep coming back to is simple: if a script can spend or approve, a word it doesn't know is a reason to stop. Everything else is twenty lines and a test.

Free resourceThe Unattended AI Runbook25 checks for AI jobs that run on their own, in five lists: before it runs, while it runs, when it fails, when it writes, and the proof it worked. Each has the story behind it.Get the runbook Building with AI?Let's talk about your appBook a free intro call