Skip to content

Headless tasks

A task runs an agent on a prompt in a fresh VM, with no one watching, and brings the work out through the host.

catchpen task run --repo github:acme/api --prompt "fix issue #42"
catchpen task run --repo github:acme/api --prompt-file task.md --agent opencode --out bundle --into ~/src/api
catchpen task run --agent cmd --cmd 'make fix' --prompt "..."   # any command, prompt on stdin
catchpen task run -t go-1.27,codex-api-key --agent codex --repo github:acme/api --prompt "..."
catchpen task run --file tasks.yaml --parallel 2
catchpen task ls
catchpen task show <id>
catchpen task logs <id> [-f] [--raw]
catchpen task cancel <id>
catchpen task rm <id>

What a task does

  1. It waits for the budget in config.yaml (all running catchpen VMs count):
tasks: { max_vms: 2, max_memory: 24G }
  1. It gets a new VM named task-<id>, with the template -t gives (as on catchpen up), from the warm pool when one matches, with read-only deploy keys unless --rw.
  2. The agent works on branch catchpen/<id> without permission prompts: claude -p --output-format stream-json, opencode run --format json --auto, pi -p --mode json, codex exec --json --yolo. omp also runs headless. Codex tasks need -t codex-api-key (the default codex section has no credentials, and codex-chatgpt has no sign-in in a new VM, so both are refused), and Codex reports no cost. --agent cmd runs your command with the prompt on stdin and its path in $CATCHPEN_PROMPT_FILE. --timeout (default 2h, from 1m to 48h) stops it; --max-budget-usd caps Claude's spend (claude only). Prompts are limited to 100 KiB.
  3. Whatever the agent leaves uncommitted is committed.
  4. The work is exported from the host:
--out Result
pr (default with a repo) Pushes catchpen/task-<id>/catchpen/<id> through a remote of --into (default: the current directory) with your credentials, and opens a PR with the prompt and result.
bundle Fetches the branch into refs/catchpen/... of --into.
patch Writes an mbox in the task directory, made on the host from the scanned commits.
none Nothing is exported.
  1. Its transcripts are copied (unless a canary hit paused it), then the VM is destroyed, unless --keep, the export failed, or a canary was hit by the time it stops (while the transcripts were copied included). A VM kept after a failed export holds the commits, and the task's error says how to pull them.

A task moves through queued, starting (it holds a budget slot while its VM is created), running and exporting, and ends done, failed or cancelled. A task whose supervisor died shows as lost; cancel or rm destroys its VM. If a canary hit that VM, both fail instead, keeping it (paused as the hit left it, or else stopped) and the task as it was: look at the VM, destroy it with catchpen destroy, then cancel or remove the task.

Output

Everything is on the host in ~/.local/share/catchpen/tasks/<id>/:

File Contents
task.json Spec, state, turns, tokens and cost.
prompt.md The prompt.
output.jsonl The agent's event stream.
result.md Its final message.
supervisor.log The supervisor's own log.
stderr.log The agent's stderr.
pr-body.md The PR description, with --out pr.
<id>.mbox The patches, with --out patch.

The agents' transcripts are copied to transcripts/task-<id>/ when the task ends. task logs renders the output; --raw prints the event stream. Both drop control characters from the agent's text, one line at a time: the escape character and carriage returns go, so the text can't set the window title or clipboard, move the cursor, or hide the lines after it. The rest of an escape sequence, colour codes included, shows as plain text, and bytes that aren't UTF-8 show as �. task show does the same for the result. task run -f and task logs -f follow the output, and exit 1 if the task didn't end done. task logs skips any line of 16 MiB or more.

Batch files

defaults: { repo: "github:acme/api", timeout: 1h, out: pr, into: ../api }
tasks:
  - prompt: "fix issue #42"
  - prompt_file: tasks/refactor.md
    agent: opencode
    title: Refactor the parser
matrix: { agent: [claude, opencode] }

Each task has prompt or prompt_file, and any of agent, repo, template (a -t spec), timeout, out, into, title, rw, keep, cmd and max_budget_usd. The optional matrix: { agent: [...], repo: [...] } runs each task once per combination, except for the keys a task sets itself: in the example, the second task runs once, with opencode. A batch holds at most 100 tasks. A relative into or prompt_file is relative to the batch file's directory (~ isn't expanded); without into, pr and bundle use the current directory. --parallel limits how many of the batch run at once. --file can't be combined with other task flags except --parallel, and --follow only for a batch of one task.

Notes

  • Task VMs ignore the agents' own notification hooks; the task's result is notified instead (task.done, task.failed).
  • A task whose VM a canary hit paused fails at once, and its VM is kept for inspection. It holds its share of the budget until you destroy it.
  • Restore, reset and rebase refuse while a VM runs a task.
  • task cancel and task rm are recorded in the audit log (task.cancel, task.rm).
  • task rm refuses a task, ended or lost, whose VM a canary hit while that VM exists: the task's directory (its prompt, output and supervisor.log) goes with the evidence. Destroy the VM first (catchpen destroy task-<id>).
  • task cancel sends the task's supervisor SIGTERM; it ends the task and tears its VM down. The supervisor drops every SIGINT, SIGTERM or SIGHUP after the first for the rest of its life, so another cancel doesn't cut that short; but a first cancel while it waits on something that doesn't watch for it (another process building the template's base image or downloading its cloud image) ends the task only once that wait is over. To stop a supervisor at once, send it SIGKILL or SIGQUIT (its pid is pid in task.json): the task then shows as lost, and task cancel or task rm destroys its VM, unless a canary hit it.

Over the API

With the daemon's API on (server: in configuration.md):

Call As Takes
POST /v1/tasks task run, one task template, repo, agent (default claude), cmd, prompt, timeout_s (60 to 172800; default 7200), max_budget_usd, out (default pr with a repo, else none), into, title, rw, keep
POST /v1/tasks/<id>/cancel task cancel, as a job nothing
POST /v1/tasks/<id>/delete task rm, as a job nothing
GET /v1/tasks/<id>/output task logs after (a line's N), limit (default 1000, 0 for all, at most 10000), follow=true to keep reading until the task ends

Submitting needs a client enrolled with --scope config:write (403 otherwise; over the unix socket, every call is allowed): a task runs whatever its prompt or cmd says in a guest that holds the template's secrets, and can write them to its error (which the API returns only to config:write clients: others read it as withheld), its result or its commits. A submit answers with the task, queued; its supervisor is a process of the daemon's, so the task runs on with the daemon's environment (--out pr pushes with the daemon's git credentials) and outlives a restart. The prompt is sent as text: there is no --prompt-file, --file or --follow. into is the absolute path of a git repository on the daemon's host, written clean, and --out pr and bundle need it (there is no working directory to default to). A repo with any of @ ? # % is refused, as for a VM, and so is a template whose ssh.agent isn't off (409): the task's VM would load or forward the host's SSH keys. A cancel of a task that ended, and a delete of one whose supervisor runs, are refused (409); so are both on a lost task (its supervisor gone) whose VM a canary hit paused or whose decoys were used, which they would destroy, and a delete of an ended task whose VM a canary hit, while that VM exists: destroy that VM first with its own call, which confirms the hit and needs config:write, as the 409 says. A hit after that check fails their job instead with the same message, keeping a lost task's VM and its record (as task cancel and task rm do). Neither asks for confirm, as the CLI doesn't, and a cancel destroys commits the task hasn't exported. Their audit events carry client. The output (GET /v1/tasks/<id>/output) needs --scope config:write too (403 otherwise, before the task is looked up): it is the agent's transcript and can quote the template's secrets. A line carrying one of the task VM's decoys is withheld from there on ((withheld: it contained the VM's decoy credentials)), the hit is acted on and audited with the client, and decoys that can't be read withhold every line. The lines are the printable ones catchpen task logs shows, not the raw agent events. A line is held until the next arrives (a decoy may straddle two), so a follow shows a line when the next is written or the task ends. The stream ends at limit or, with follow, when the task ends; to go on, ask again with after set to the last N plus one. pkg/apiclient's TaskOutput drives it. On a task's VM (any VM named task-…), changing its egress or opening a forward (see egress.md and forges.md), starting, stopping (with force or not), resuming or destroying it (see the server row in configuration.md), resetting, rebasing or pushing credentials to it, saving, restoring or deleting a snapshot (see snapshots.md), and pulling a branch from it or opening a pull request (see forges.md) need config:write too (403 otherwise; a client on the unix socket has every scope): with them a client could wipe what a canary hit left in its VM, add snapshots that its destroy must confirm, bring its commits onto the host, or let the unattended agent a config:write client submitted reach further, run on or stop. Reading the VM, its egress, forwards and snapshots, stopping its forwards, and GET /v1/vms/<name>/destroy, /reset and /rebase need no scope. The API creates no VM whose name starts with task-, for any client (400, on the unix socket too), so none can take a queued task's VM name; the CLI still can.