Run hagent non-interactively with -p and JSON output
hagent -p "message" sends one message, waits for that turn to finish, prints the result and exits. It's made for scripts, batch jobs and CI. Add --output json or stream-json for structured output.
Send one message
hagent -p "check /obj for errors"
The reply and its progress are printed to the terminal, and the program exits when the turn ends.
- Read the message from standard input:
-p -reads the message text from stdin, which is handy for long prompts:
Get-Content prompt.txt -Raw | hagent -p -
- Choose mode, model and effort:
--mode Ask|Agent|Plan,--provider,--model,--effort. These apply to this run only and don't change the desktop app's defaults. - Attach images:
--image path, which can be repeated. - Continue a session:
-ccontinues the most recent session, and-r <session ID>continues a specific one; without either, a new session is started. - Slash commands: the
-ptext can also be a slash command or skill that sends a message, for examplehagent -p "/init"orhagent -p "/vellum make a flag blowing in the wind".
How confirmations and questions are handled
Nobody is at the terminal to answer, so -p handles these in a fixed way:
| Situation | Without -y |
With -y (--yes) |
|---|---|---|
| Confirmation before an action | Always denied, with a hint to add --yes |
Approved automatically |
| A plan produced in Plan mode | The plan is printed and the run ends without executing it | Approved and executed automatically |
| The agent asks you a question | The agent is told no one can answer and to continue with the safest option | Same |
-y lets the agent change the scene, run code and write files with no one confirming. Only use it when you trust the prompt and the scene has been saved.Wait for Houdini to connect
By default, if Houdini is running, hagent waits up to 15 seconds for it to connect before sending; if Houdini isn't open, it sends right away. Change the wait with --wait-houdini seconds, for example right after a script has launched Houdini:
hagent -p "count the polygons in the scene" --wait-houdini 90
Output formats
Choose the format with --output:
| Format | What it prints |
|---|---|
text (default) |
The same readable text as interactive mode |
json |
One JSON object at the end |
stream-json |
One JSON line each time a conversation row appears or updates, then a final result line |
json
At the end, one line of JSON is printed:
{"result": "reply text", "session_id": "3f9c2a…", "is_error": false,
"usage": {"…": "token usage for this session"}, "model": "model name", "provider": "provider"}
result: the text of the last reply (Markdown).session_id: the session used; pass it to-rnext time to continue.is_error: whether the turn ended with an error.usage: token usage for this session.
stream-json
One JSON object per line:
{"type": "row", "row": {…}}: printed when a conversation row (your message, an agent reply, a tool call and so on) appears or updates; the same row may be printed several times.{"type": "result", "result": "…", "is_error": false}: the last line, marking the end of the turn.
Exit codes
| Exit code | Meaning |
|---|---|
0 |
Finished normally |
1 |
The message couldn't be sent, or the turn ended with an error |
2 |
Bad arguments, for example an empty message or a --model that doesn't exist |
Script examples
# Read-only check, result written to a file
hagent -p "List every node with errors or warnings" --mode Ask --output json > report.json
# Allow changes, then continue in the same session for a second step
$r = hagent -p "Set the scatter count on /obj/geo1 to 2000" -y --output json | ConvertFrom-Json
hagent -r $r.session_id -p "Render a preview image" -y
To run many messages in one go, put them one per line in a file and pipe it into interactive mode; see Use hagent in interactive mode.