The Help Flag That Published a Blog Post: Writing Scripts for Coding Agents
· 10 min read
A session in my agent loop ran a script with --help to read its usage. The script had no help flag, ignored the argument and published a blog post. It was one of six calls in eleven weeks where an argument a script did not know ran something for real. Here is what those incidents say a script should do before an agent calls it.
On 2026-11-26 a session in my agent loop wanted to know how the blog publisher worked. It ran node loop/blog-publish.mjs --help. The script had no help flag. It ignored arguments it did not recognise, and with no argument it recognised it did its job: it committed the next scheduled post to this site, pushed it, waited for the page to answer and asked Google to index it.
Nothing went out that should not have. The post was due, its slot had opened 23 minutes earlier, and publishing it was that session's one task. But the session had not decided to publish yet. It had decided to read the manual. The post it published was last week's, which is about the loop being confidently wrong.
In the same run the same habit reached the scheduler. node loop/scheduler.mjs --help ran a real scheduling tick, which started nothing only because a run was already in progress.
The loop is a set of headless Claude Code sessions that run a few small products on a schedule (I have written about how it decides when to run). Much of what those sessions do, they do by calling small scripts that earlier sessions wrote: a scheduler, a queue, a publisher, a log reader, a mail sender. So the scripts are an interface, and they have an unusual user. It is capable, it guesses flag names from convention, and it starts every session with no memory of the last one beyond what was written down. This post is what the loop's incident record says a script should do before an agent calls it. Each item comes from something that happened.
1. An unknown argument stops the script
The publisher call was one of six, on five separate days.
- 2026-09-09. A coding subagent, testing a change to the scheduler, ran it with
--dry-run=false. The scheduler looked for the exact string--dry-run, did not find it, and did what it does with no arguments. It started a detached, real agent run against production. The subagent reported it and killed it within a minute, and the session that had delegated the work checked that nothing had been committed or pushed. - 09-14 and 09-16. Two sessions ran the scheduler with
--list, expecting to see the queue. Each got a real tick. - 09-18.
--help. A real tick. - 11-26.
--helpagain, on the scheduler and on the publisher.
Every one of these was written up the same day as a correction. The 09-14 entry says the hazard "is recorded, not fixed". After 11-26 the loop saved a standing note for future sessions: never probe these scripts with --help, read the source instead.
The dates show that a note was the wrong fix. Typing --help at an unfamiliar tool is correct behaviour, and a guessed --list should fail safely. The defect was in the scripts. Both checked their flags with the equivalent of args.includes("--dry-run") and looked at nothing else, which means every typo, every guess and every flag borrowed from another tool selects the default action.
On 2026-11-30, while this post was being drafted, both scripts were changed. They now check their arguments against a declared list first. --help prints the usage and exits 0. Anything else they do not recognise prints the problem and exits 64 before the script does any of its work. --dry-run=false is an error now. The change is a small shared parser wired into the top of both scripts. To check it, --help, -h, --list, --dry-run=false, a made-up flag and a bare word were each run against the scheduler. Its log and the queue file were byte-identical afterwards.
Two newer tools in the loop already refused unknown options and commands (an unknown command prints one usage line and exits 1). The scheduler and the publisher were older. Other old scripts in the repository still ignore what they do not recognise, and they have not all been audited.
2. The bare command is the safe one
With no arguments the publisher publishes. That is the dangerous half of the design, because it makes the safety flag the thing you must type correctly.
The scripts that send email were written two months later and work the other way round. Their sending commands default to a preview: without --send they print what would go and why anything would be refused. A session that forgets the flag gets a preview.
What made the 11-26 call harmless was that the publisher's default is fenced in other ways. It publishes one entry, only when that entry's time has come, only if the text passes a validator, and only from a clean checkout that matches the remote. The same stray --help on a script without those fences would have been a different story.
The publisher still publishes when called bare, because a queued job whose whole task is publishing calls it that way. So the fix in section 1 is partial. Unknown arguments now fail, but a call that leaves out an intended --dry-run still publishes whatever is due.
3. Do not wait on stdin
In early September the bridge to a second vendor's model, which the loop uses for independent review, began to hang. The signature was a 24-minute run that produced a 0-byte output file and no error. Three attempts to diagnose it found nothing.
The cause was one line of behaviour in the vendor's CLI (codex-cli 0.153.4 at the time). When stdin is not a terminal, codex exec treats it as more prompt input and reads to end of file. In this setup, a system timer starting a headless agent session, stdin was an inherited pipe that never closed. The CLI did say so: it printed "Reading additional input from stdin...". The wrapper sent stderr to /dev/null.
The fix had three parts. Redirect stdin from /dev/null. Add a hard timeout. Keep stderr in a log when the call fails, and tell a timeout apart from other errors. The fixing session proved it by running the bridge behind a FIFO that never closes (it returned in 7 seconds) and by forcing a 2-second timeout to see the failure logged.
An unattended session's shell is often not a terminal. A script that prompts, pages or reads stdin there can block for as long as its caller lets it, and a hang reports nothing.
4. Exit 0 means the request was carried out
The same bridge had a review mode that took a path. On 2026-09-09 the reviewer's sandbox timed out reading the repository three times. It did the honest thing and declined to rank findings it could not cite. What came back was a short paragraph asking for the files to be pasted, with exit code 0.
From the caller's side that is a successful review: a zero and some plausible prose. The session re-ran it with 30 kB of code pasted into the prompt, which worked. The wrapper still cannot tell a review from an apology. The rule the loop follows is that a review which cites no file and line is not a review, and the code goes in inline.
An exit code gives the caller a status it does not have to interpret from prose. The production log reader shows the pattern. It exits 0 when every project read cleanly with no errors, 3 when it found errors, and 1 when a read failed. A failed read is never reported as clean, and an empty result counts as clean only after the same query without its filter returned rows. That is the third state from last week's post, carried by the exit status.
5. If a session must write a file, give it a command
The scheduler has a cap that stops the loop from re-reading numbers that have not moved. It reads a log of "blocked" lines that runs are supposed to append. The cap shipped on 2026-09-21 with a reader and no writer. Sessions were expected to type the line by hand.
Two days later the cap had never fired. Six runs in a row had found the blocked state, written a full report and appended nothing, while the week's allowance for the loop's main model sat at 95% used. The instruction to append the line lived in a reference document and not in the prompt each run is given. And of the 24 hand-typed lines already in the file, one did not match the strict format. The parser scored it as unknown, which silently breaks the streak the cap counts.
The fix was a small command that writes the line. It sits next to the only parser of that format and throws when it would emit a line the parser cannot score. It refuses a second line from the same run. Independent review of its first draft found five bugs. One was the classic hand-rolled argument bug: a missing flag made indexOf return -1, the code read position 0 as that flag's value, and the first word of the message was eaten.
The parser had existed all along. What was missing was validation at the moment of writing, and a writer provides it.
6. Hard rules get a hook as well
Some rules must hold when nobody is watching: no access to my personal email, no printing the secrets file, no production deploy from the CLI in place of a pushed commit, no force-push to main. Until 2026-10-28 they were sentences in the prompt.
These runs disable permission prompts. Since that date the rules are also a hook that runs before every tool call, with a deny list beside it. The hook's header says why: with prompts off, those two are the only layer that can say no. It exits 2 with a reason on stderr, which the model sees and can act on. The session that built it verified that the hook still fires with permission prompts disabled.
It narrows risk and it is not a sandbox. A process the agent starts can still do any of those things, and the header says that too.
7. The scripts on disk are production
The 09-09 run produced a second incident. The scheduler is started by the operating system every 20 minutes, from the working tree. While the subagent was halfway through rewriting the scheduler's lock handling, a tick arrived and executed the uncommitted file. The new code read the lock held by the run that was writing it, saw an old format with no owner recorded, called it stale and cleared it. A second run did not start only because an unrelated minimum-gap rule said no.
Two rules came out of it. A change to any state format ships with a shim that honours what the running version wrote. And the scheduler is not run by hand with anything but the exact dry-run flag. The second one stayed a rule on paper: until this week any other argument still ran a live tick. Unknown arguments are refused now. A bare call still runs a live tick, because that is how the timer calls it.
The list
None of this is enforced everywhere in the loop yet. It is the standard the incidents point to.
- A script refuses arguments it does not know before it does any work, and
--helponly prints. - Called bare, it reads or previews. Sending, publishing and deleting need an explicit word. In this loop the scheduler and the publisher are still exceptions, because a timer and a queued job call them bare.
- It does not read stdin unless asked, it has a timeout, and it keeps its stderr.
- Exit 0 means the request was carried out. "Found something" and "could not look" get their own codes.
- Any file the loop's behaviour depends on has a command that writes it and refuses bad input.
- Rules that matter are also checked at the tool call, knowing that a hook filters calls and does not sandbox what they start.
- A change to a scheduled script assumes the timer may run the file halfway through the edit, so it stays compatible with the state the running version wrote.
The first item was asked for on 2026-09-09. That day's log calls it the first thing the next reliability run should fix. It was fixed nearly twelve weeks and five more calls later, on the day this post was drafted.