Skip to content
qqthe agent runtime
DocsHeadless: qq ask, qq run, qq serve

Headless: qq ask, qq run, qq serve

Run agents from scripts and CI with qq ask, qq run, and qq serve; exit codes and JSONL output.

Three ways to use QQ without the TUI. All three share the runtime, tools, approval policy, and session store with it.

Terminal window
qq ask "Explain what src/parser.rs does in three sentences"
qq ask --model openai/gpt-5.4-mini "Reply with pong"

Streams an answer to stdout using workspace read tools and the MCP tools a server’s allow lists. It cannot ask approval questions: built-in edits, commands, questions, fetch and other MCP tools are omitted. No session is persisted. Use it to check a credential or for quick questions from a script. Exit 0 on success, 1 otherwise.

Terminal window
qq run --approval auto "Add a --dry-run flag to the CLI and cover it with a test"

Runs one task to completion in the current directory (or --workspace PATH) through a durable session. Progress goes to stderr, the final answer to stdout.

--approvalMeaning
read-onlyreads only; every edit, shell, MCP, and network call is denied and reported to the model
askreads run; every other call needs human approval, so with no human present it is denied immediately
auto (default)edits, shell, MCP, and public fetch run without asking, in the checkout; fixed stops are denied and reported to the model
fulleverything runs without asking, fixed stops included; managed denies and protected files still apply

No mode waits for a human: qq run never stops on an approval prompt.

Under read-only, when at least one held call was denied, a text-mode run ends with held calls were denied under --approval read-only; rerun with --approval auto to allow workspace edits on stderr (after the answer, before the resume hint). The exit status is unchanged; JSONL output carries no hint because each denied call is already in its tool_call_finished record.

FlagEffectExit
--timeout-seconds Ncancel after N seconds of wall clock3
--max-turns Ncancel when model turn N+1 would start3
--max-cost-usd Vcancel when the estimated cost passes V; refused up front if the model has no pricing3
CodeStatusMeaning
0completedfinal answer produced (and satisfied --output-schema if given)
1task_failedthe agent reported failure, the run failed, or the answer never satisfied the schema
2invalid_configurationQQ refused to start: config, model, credential, pricing, or flag error
3timed_out / budget_exhausteda limit was reached
4harness_failureQQ itself failed (store, provider protocol, internal), or another qq process owns the session store
5needs_inputthe agent asked a question and nobody was there; the question is in the event stream
130interruptedCtrl-C
Terminal window
qq run --format jsonl --approval auto "…" > run.jsonl
qq run --trace run.jsonl "…" # text on the terminal, JSONL to the file too

Each line is one JSON object with a type:

typeWhenContents
trialonce, firstQQ version and revision, protocol_version, workspace/session/run ids, model, profile, approval, limits, correlation labels
eventevery protocol eventthe same envelope the TUI consumes: prompts, model text, tool calls and results, approvals, usage
outcomeonce, laststatus, exit_code, token usage, estimated_cost_usd_nanos, final_output when a schema was given; recovered_answer after a delivery gap

Slow consumers can outlive the replay window. QQ recovers from durable state without restarting the task. If an outcome includes recovered_answer, use that complete reply instead of text accumulated from the partial event stream.

The shapes are versioned with PROTOCOL_VERSION and pinned by golden fixtures under crates/qq-protocol/tests/fixtures/headless/; a consumer should read trial.protocol_version first. Full contract: ../design/headless-contract.md.

Terminal window
qq run --output-schema answer.schema.json --output-repair-turns 2 "…"

The final answer must be one JSON document valid against the schema (a bounded subset: ≤ 64 KiB, no $ref). QQ gives the model up to N extra turns to repair an invalid answer; the outcome’s final_output carries either the parsed value or the validation errors. Valid JSON is not a correct answer; verify it.

Terminal window
qq run --session 1f0c9a2e4b7d4c1e9a3f5b6d7e8f9012 "Now add the same flag to the docs"

Submits into an existing idle root session of this workspace, keeping its history. The model and profile come from this invocation. The stored approval mode is preserved unless you explicitly pass --approval. New sessions default to Auto. Every exit prints the id you need.

A command does not survive the process that started it. After a crash or a restart, the unfinished run and its commands are reported as interrupted, and the session accepts the new prompt.

--steer-stdin reads one line per steering message and injects each at the run’s next model/tool boundary; without it stdin is untouched.

--correlation job=nightly --correlation pr=123 (≤ 8, opaque to QQ) appear on the trial record and every session snapshot.

--profile NAME selects a profile from configuration; it sets the model, approval mode, and reasoning effort for the run and fails before starting when the name is unknown.

Terminal window
qq serve # 127.0.0.1, random port
qq serve --bind 127.0.0.1:4711
qq serve --allow-origin https://app.example.com

Runs the user-scoped server in the foreground until Ctrl-C, SIGTERM or qq daemon stop. Without it, each qq starts a server inside itself when none is running, and quitting that qq cancels its runs (Exiting). qq serve is for keeping runs going after the TUI quits and for several TUIs on one machine. It prints qq server listening at ADDR; a second qq serve reports the existing one. Stopping it cancels every queued and running run, as quitting an owning TUI does.

Terminal window
qq daemon run --detach # start in the background; returns once it serves
qq daemon status # address, pid, version, log path; exit 1 if none
qq daemon stop # stop and wait until the store is closed
qq daemon restart # stop, then start this binary in the background

qq daemon run is qq serve under the name the other daemon commands use; add --detach to start it as a background process. A detached daemon does not depend on the terminal or directory it was started from, and writes to daemon.log in the server state directory (qq daemon status prints the path). Starting a second daemon reports the running one. Stopping settles every queued and running run as cancelled, as Ctrl-C on qq serve does. stop does not stop the server inside an interactive qq; quit that qq. After an upgrade, qq daemon restart stops the daemon the previous version started and starts the new binary, even across a protocol change.

The daemon’s approval wait (approval_timeout_seconds) comes from global and managed configuration only, never from the directory it was started in. The same holds for qq serve.

qq run and qq ask never use a server. qq run opens the session store itself, so it cannot run while another process holds that store — a TUI, qq serve, or another qq run — and exits 4 with session store is owned by another running qq process. Queue the work from the TUI, run jobs one after another, or give concurrent CI jobs separate data directories (XDG_DATA_HOME on Linux).

The wire protocol is HTTP + SSE with resumable event cursors; see ../design/protocol.md. The server binds only to loopback; there is no remote client or remote authentication yet.

- run: printenv ANTHROPIC_API_KEY | qq auth login anthropic --allow-file
env: { ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} }
- run: >
qq run --model anthropic/claude-sonnet-5 --approval auto
--timeout-seconds 900 --max-cost-usd 2
--format jsonl "Fix the failing tests" > run.jsonl

Commands run as the runner’s user with the job’s environment, so pass the job only the secrets the task needs.

Or skip the store entirely: QQ reads ANTHROPIC_API_KEY from the environment when nothing is stored. QQ_CONFIG_CONTENT='(version: 1, model: "…")' supplies configuration without a file. If the repository ships .qq/config.ron with sensitive sections, run qq trust first.