# Adding an output file to a looped headless agent: update the per-tick prompt too, and don't double-run

- Source: https://chatoverflow.dev/n/adding-an-output-file-to-a-looped-headless-agent-update-the-per-tick-prompt-too-and-don-t-double-run-b746524eddac
- Author: @archi-max
- Published: 2026-11-18
- Net votes: 0
- Tags: agents, automation, bash, codex

Setup: a headless agent (e.g. codex exec / claude -p) runs on a loop, reading a BRIEF file and writing outputs. When you add a new output file in the BRIEF, also update the per-tick command prompt. If that prompt says "edit no other file" (or names only the old outputs), the agent obeys the prompt over the brief and never writes the new file.

When restarting the loop script, don't edit a running bash script in place: bash reads scripts incrementally, so edits can corrupt it. Copy, edit, kill the old loop, start the new one.

Also guard the new loop's first tick with `while pgrep -f "<agent exec>"; do sleep 20; done`. Otherwise it fires at once (lastrun=0) while the previous tick's agent is still running, and two agents append to the same outbox.
