Skip to content

Headless & Automation

You don’t need to open an interactive screen to use Hya. From shell scripts, Makefiles, cron jobs, or CI pipelines (like GitHub Actions), Hya has three non-interactive modes depending on how much supervision the job needs:

Mode Command When it stops
Single run hya exec "<prompt>" (or hya -p "<prompt>") After finishing one turn (including any tool calls it makes)
Goal mode hya goal "<goal>" When a separate judge model agrees the goal is met (or --max-iterations runs out)
Loop mode hya loop "<target>" --until "<cmd>" When your shell command exits 0 and the verifier agrees (or --max-iterations runs out)

1. One-shot runs (hya exec)

hya exec sends one prompt, lets Hya read files or run tools until it has an answer, prints the final reply to stdout, and exits.

Terminal window
# Ask a question and print the answer
hya exec "What ports does docker-compose.yml expose?"
# Pipe file contents or logs in on stdin
git diff HEAD~1 | hya exec "Review this diff for obvious bugs"

Saving history vs running in memory

By default, hya exec persists to ~/.local/state/hya/sessions.db (or --db <PATH>), so you can follow up with hya exec -c "..." or hya exec -s <ID> "...". Pass --ephemeral to run on a transient in-memory store so parallel scripts never touch disk or wait on a database lock:

Terminal window
hya --db ./ci-run.db exec "Fix formatting issues in src/"
hya exec --ephemeral "Quick one-off check without saving to disk"

JSON output for scripts (--json)

Pass --json to stream one JSON event per line (JSONL) instead of plain text—handy if your script wants to watch tool calls, token counts, or errors as they happen:

Terminal window
hya exec --json "List all public endpoints" | jq -r 'select(.event.type == "message_finished")'

Bare mode (hya --bare)

Want a lean runtime that skips installed and project bundles and uses only the minimal hya-bare agent, the 8 standard bare tools (read, write, edit, bash, grep, todo, rewrite, skill), and optional native Code Mode? Pass the global --bare flag on hya exec, hya server run, or interactive hya:

Terminal window
# Headless bare run (keeps AGENTS.md, disk skills, MCP, and user/project plugins)
hya exec --bare "Fix the failing assertion in tests/math.test.ts"
# Pure kernel benchmark (also skips AGENTS.md, disk skills, MCP, and user/project plugins)
hya exec --bare --pure "Benchmark prompt"
# Bare server or interactive TUI
hya server run --bare --bind 127.0.0.1:8080
hya --bare

Because --bare uses the unified SessionEngine, it still enforces your configured permission rules (pass --yolo in disposable containers/sandboxes when unattended execution is desired).


2. Autopilot with a judge (hya goal Goal Mode)

In regular chat tools, an AI sometimes stops early and says “All done!” when two files are still broken.

Goal mode (hya goal) fixes that by separating the worker from the judge. Goal mode is provided by the built-in hya/goal native ABI v2 bundle (the hya/goal:goal driver + goal-contract, guided-goal, and evaluator-prompt skills + hya-goal-guide and hya-goal-verifier agents). After Hya finishes a round of work, an independent evaluator (a registered hya/goal:evaluate hook or the tool-free model verifier) checks the transcript before letting Hya stop. If anything is missing, Hya gets sent back to finish the job.

Bundle availability: Goal mode requires hya/goal to be enabled (default in profile = "full"). Without hya/goal (--bare, or bundles.builtin.disable = ["hya/goal"]), hya goal does not exist (unrecognized subcommand 'goal'). Root hya -p "<prompt>" always runs a single headless turn like hya exec. Configure the default judge model per bundle under [bundles."hya/goal"] in ~/.config/hya/config.toml (or ~/.config/hya/bundles/hya/goal.toml, goal.evaluator_model), or override it per run with --evaluator-model.

Terminal window
hya goal "Add unit tests for src/billing.rs and make sure cargo test passes" \
--max-iterations 6

You can pick a fast or strict model specifically for judging:

Terminal window
hya goal "Clean up all compiler warnings" \
--evaluator-model anthropic/claude-sonnet-4-6 \
--max-iterations 5

Writing rock-solid goals

Plain sentences work fine, or you can write a structured goal file with five clear headings (## Objective, ## Success criteria, ## Verification, ## Boundaries, ## Stop conditions) so the judge knows the exact command Hya must run to prove success:

Terminal window
hya goal "$(cat <<'EOF'
## Objective
Convert src/config.js to TypeScript.
## Success criteria
- src/config.ts exists with strict types and src/config.js is removed.
## Verification
`npm run typecheck && npm test`
## Boundaries
Do not change public function names.
## Stop conditions
Stop if a third-party dependency lacks type definitions.
EOF
)" --max-iterations 6

3. Autopilot gated by a shell check (hya loop)

When you already have a test suite, typechecker, or linter that tells you pass/fail via exit code, hya loop is the most reliable way to run unattended work.

  • --until '<cmd>' keeps looping until <cmd> exits with code 0 (and exits 1 while work remains).
  • --while '<cmd>' does the opposite—keeps looping while <cmd> exits 0, and stops when it exits 1.
Terminal window
hya loop \
"Make all workspace clippy lints and unit tests pass" \
--until "cargo clippy --workspace -- -D warnings && cargo test --workspace" \
--max-iterations 8

Safety guard: In --until / --while, exit codes 0 and 1 mean “met” or “not met yet.” Any other exit code (like 127 command not found or a syntax error in your check command) stops the loop immediately with an error instead of burning through your token budget on a broken check!

Modular hya/loop bundle (hya/loop:loop driver)

Loop mode is supplied by the official native ABI v2 bundle hya/loop, which registers its hya/loop:loop driver, lifecycle LoopService, and verifier/planner prompt skills (loop-verifier-prompt, loop-planner-prompt) through HostRuntime.

  • Full mode (default): hya/loop is enabled automatically and hya loop runs the hya/loop:loop driver.
  • --bare or disabled: with --bare, or with hya/loop in bundles.builtin.disable, the bundle is not loaded and hya loop is not a command; enable hya/loop in config.toml:
schema_version = 3
[bundles.builtin]
profile = "bare"
enable = ["hya/loop"]

Permissions in headless runs

Headless commands, including --bare, use the active permission policy. Configure explicit allow rules in permissions.toml for unattended builds and tests. In a disposable CI container or VM, --yolo selects bypass and skips prompts while honoring denials by default. See Projects, permissions, and trust.