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.
# Ask a question and print the answerhya exec "What ports does docker-compose.yml expose?"
# Pipe file contents or logs in on stdingit 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:
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:
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:
# 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 TUIhya server run --bare --bind 127.0.0.1:8080hya --bareBecause --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/goalto be enabled (default inprofile = "full"). Withouthya/goal(--bare, orbundles.builtin.disable = ["hya/goal"]),hya goaldoes not exist (unrecognized subcommand 'goal'). Roothya -p "<prompt>"always runs a single headless turn likehya 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.
hya goal "Add unit tests for src/billing.rs and make sure cargo test passes" \ --max-iterations 6You can pick a fast or strict model specifically for judging:
hya goal "Clean up all compiler warnings" \ --evaluator-model anthropic/claude-sonnet-4-6 \ --max-iterations 5Writing 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:
hya goal "$(cat <<'EOF'## ObjectiveConvert 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`
## BoundariesDo not change public function names.
## Stop conditionsStop if a third-party dependency lacks type definitions.EOF)" --max-iterations 63. 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 code0(and exits1while work remains).--while '<cmd>'does the opposite—keeps looping while<cmd>exits0, and stops when it exits1.
hya loop \ "Make all workspace clippy lints and unit tests pass" \ --until "cargo clippy --workspace -- -D warnings && cargo test --workspace" \ --max-iterations 8Safety guard: In
--until/--while, exit codes0and1mean “met” or “not met yet.” Any other exit code (like127command 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/loopis enabled automatically andhya loopruns thehya/loop:loopdriver. --bareor disabled: with--bare, or withhya/loopinbundles.builtin.disable, the bundle is not loaded andhya loopis not a command; enablehya/loopinconfig.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.