Headless (ka run)
ka run executes exactly one turn with no interface: built for scripts, CI, and piping.
ka run "summarize the build error"echo "what does this repo do?" | ka runka run -c "continue: what else?" # continue the newest strandka run --session 3f9c "next step" # resume a specific sessionOutput formats
Section titled “Output formats”--print |
Output |
|---|---|
text (default) |
The final answer only |
ndjson |
ka’s own event stream: literally the engine’s Event side, one JSON object per line |
stream-json |
Claude-Code-compatible event shapes, for tooling that already speaks that dialect |
--rpc |
RPC event protocol for programmatic hosts driving ka as a subprocess |
ka run --print ndjson "list the failing tests" | jq -c 'select(.type == "turn_finished") | .usage'Run caps
Section titled “Run caps”| Flag | Behavior |
|---|---|
-o FILE |
Write the final answer to a file |
--max-turns N |
Stop after N turns |
--max-budget-usd |
Asks the model to stop once past the ceiling |
--max-cost / --max-time |
Exit with code 3 when the cap is crossed |
--warn-cost |
Warn on stderr when the session cost grows |
Structured output
Section titled “Structured output”Pass a JSON schema and the reply must satisfy it:
ka run --schema issue.schema.json "file the flaky test as JSON" > issue.jsonExit codes
Section titled “Exit codes”| Code | Meaning |
|---|---|
0 |
ok |
1 |
error |
2 |
aborted |
3 |
cap crossed (--max-cost / --max-time) |
42 |
input rejected (e.g. a --schema validation failure) |
Safety in headless mode
Section titled “Safety in headless mode”There is no human to ask, so asks resolve strictly: exec-tier calls that would prompt are denied (not auto-approved), and hardstops are denied outright. Pre-approve what a script needs with [[rules]] or [permissions] allow, or run with --mode allow deliberately. For CI, the explicit stance is --mode dont_ask (never block on a prompt) with [permissions] prompt_policy = "deny"; see automation.