Sub topic 4
Writing Prompts That Never Need to Ask a Question
This chapter assumes you have run an interactive coding agent in a terminal and know the wrapper script from the previous chapters, where the prompt file is piped to the agent on stdin.
Why unattended prompts are different
In an interactive session, the agent can stop and ask "Which file did you mean?" You answer, and work continues. In a headless run, nobody answers. The agent then either waits until the timeout kills it, or it guesses and continues. Both outcomes are bad on a schedule, because you find out hours later.
The fix is in the prompt. A self-contained prompt gives the agent everything it would otherwise ask about.
What a self-contained prompt contains
- Goal: one task, stated as an outcome.
- Scope: the directories or files it may read and change, and those it must not touch.
- Inputs: where the data comes from, with exact paths or commands. Do not say "the latest report".
- Decision rules: what to do in each ambiguous case.
- Output: the exact files, branch name, or JSON shape to produce.
- Stop condition: when the task is finished, and what to do if it cannot be finished.
A worked example
This is prompts/nightly.md, the file the wrapper script reads:
Goal: Find dependencies in package.json that have a newer patch version and update them.
Scope: Edit only package.json and package-lock.json. Do not touch any other file.
Steps:
1. Run `npm outdated --json` and read the result.
2. For each package whose newer version differs only in the patch number, update it.
3. Run `npm test`.
Decision rules:
- If a minor or major update is available, do not apply it. List it in the report.
- If tests fail after an update, revert that update and list the package in the report.
- If nothing needs updating, write a report saying so and stop.
- Never ask for confirmation. If you are unsure, take the more conservative choice and note it in the report.
Output: Write report.md with sections "Updated", "Skipped", and "Failed".
Finish when report.md exists.Each decision rule replaces a question the agent would have asked in a live session.
Turning questions into rules
Read your prompt and ask what a person would reasonably ask. Then write the answer into the prompt.
| Question the agent might ask | Rule to write |
|---|---|
| Should I update major versions too? | Never update major versions. List them instead. |
| What if the tests fail? | Revert the change and report it. |
| Which branch do I use? | Use `agent/deps-YYYYMMDD`, with the date given in the prompt. |
| Is this change big enough to ask about? | Make no change over 50 lines. Report it instead. |
Common errors
- Relying on memory. Phrases like "as we discussed" mean nothing to a fresh process. Every run starts with no history.
- Relative time. "Yesterday's failures" depends on a clock the agent may read wrongly. Have the wrapper pass the date in explicitly, or have the agent compute it with a named command.
- Vague success. "Clean up the code" has no end. Name a measurable stop condition.
- Missing failure path. If the prompt only describes success, the agent improvises when something breaks. Say what to write and where when it cannot finish.
- Silent guessing. Tell the agent to record every assumption in the report, so you can review it later.
Checking the prompt before you schedule it
Run the prompt once in a normal interactive session. Whenever the agent asks a question, add the answer to the prompt. Repeat until it finishes without asking. This also shows the structure you can ask for in the output, which a later chapter validates.
Exercise
A nightly prompt says "Fix the failing tests from the last run and tell me if anything looks wrong." Name two problems that would stall or derail a headless run, and rewrite one.
Show answer
"The last run" is not defined, because the agent has no memory of earlier runs. "Tell me" assumes someone is there to receive an answer. Rewrite: "Run npm test. For each failing test listed, fix only the source file it covers. If you cannot fix a test within three attempts, leave it unchanged. Write results to report.md and stop."