Guide · vanth 1.14.0
Run long jobs
and wake your agent
Start a detached command, inspect its output, and wake an OpenCode or Codex session when the job finishes or reaches a checkpoint. The first job is short. The wake example uses a loop with checkpoints.
Before you start
The short example needs only Python and uv. The wake example also needs a live OpenCode or Codex session.
- Python 3.11 or later, and
uv. - OpenCode or Codex CLI for the wake steps. The job and inspection steps work without an agent.
- A project folder with a command that can run unattended.
- Network access for the first install.
1. Install and connect
Install with uv. The wheel includes the CLI, the MCP server, the daemon, and vanth-monitor.
vanth setup detects OpenCode, Codex, and Claude-style MCP clients. For Codex, run vanth setup codex. Restart the client after setup so it loads the new server.
vanth status is read-only. It reports the daemon as down without starting it. A normal MCP call or an operational command such as vanth list starts the daemon on demand.
uv tool install vanth
vanth setup opencode
vanth status
vanth doctor
opencode mcp list2. Run one complete job
This command starts a detached job and returns a job ID. The command uses uv run, so it runs in the project environment.
--timeout sets a runtime limit in seconds. The runner enforces it across daemon restarts. A hung command ends as timeout, not as a job that runs forever.
Pass a command with shell operators as one quoted string. A bare &&, |, or > argument is refused.
vanth start --name demo --timeout 60 -- uv run python -c "print('hello from a vanth job')"
started job_543a9ad15be2 (running)
watch: vanth logs job_543a9ad15be23. Wait and inspect the result
vanth wait blocks until a terminal event by default and exits 0 on an event, 3 on timeout. It defaults to completed, failed, timeout, cancelled, and orphaned.
vanth logs reads captured output without attaching to the runner. vanth status shows the command, exit code, runtime, and last event.
vanth wait job_543a9ad15be2
vanth logs job_543a9ad15be2
vanth status job_543a9ad15be2
vanth wait: completed (job job_543a9ad15be2, seq 2): Job completed
hello from a vanth job
job: job_543a9ad15be2
name: demo
status: completed (exit 0)
runtime: 0s
command: uv run python -c "print('hello from a vanth job')"
cwd: C:\work\demo
last: completed seq 24. Wake an agent when the job needs attention
Add --wake-me to register a wake target for the current agent session. It defaults to the terminal outcomes: completed, failed, timeout, cancelled, and orphaned.
Add checkpoint when you want a wake before the job ends. A checkpoint wake only fires if the job emits checkpoint events.
For OpenCode, run vanth setup opencode and restart OpenCode. A plain TUI uses the plugin relay. Without a live relay, an opencode_thread target is rejected at creation. Run vanth doctor to inspect the relay.
Create job.py with the loop below, then start it. When the job reaches a checkpoint or finishes, vanth resumes the registered OpenCode or Codex session.
import time
from vanth.agent_events import agent_event, progress
for epoch in range(1, 4):
progress(epoch, 3, unit="epoch", stage="train", message=f"{epoch}/3 epochs")
agent_event("checkpoint", f"epoch {epoch} done", epoch=epoch, val_loss=0.4 / epoch)
time.sleep(2)
print("training complete")
vanth start --wake-me=completed,failed,checkpoint --timeout 3600 -- uv run --with vanth python job.pystarted job_543a9ad15be2 (running)
watch: vanth logs job_543a9ad15be25. Emit progress, metrics, and checkpoints
The wire format is one line on stdout or stderr. vanth emit prints one line and works from any language.
Numeric metric fields become line plots. _step is the x-axis when present. Other fields stay with the event.
vanth emit checkpoint "epoch done" --data epoch=10 --data val_loss=0.42
vanth emit progress --data current=10 --data total=100 --data unit=epoch --data stage=train
vanth emit metric --data _step=10 --data loss=0.42 --data acc=0.88
AGENT_EVENT {"type":"checkpoint","data":{"epoch":10,"val_loss":0.42},"message":"epoch done"}
AGENT_EVENT {"type":"progress","data":{"current":10,"total":100,"unit":"epoch","stage":"train","percent":10.0}}6. Watch the work
vanth-monitor shows live jobs, progress, metrics, and plots. The log command filters captured output without attaching to the runner.
vanth list --json gives scripts the same job state.
vanth list --status running --json
vanth status job_abc123
vanth logs job_abc123 --stream stderr --max-bytes 65536
vanth wait job_abc123
vanth-monitor7. Use MCP from an agent
MCP clients get the same operations as tools. For long work, start with a wake target and let the session go idle.
Use job_wait instead of polling job_status. Pass since_event_id after you handle an event so the next wait does not return the same one.
job_start(
command="uv run python train.py",
name="train resnet",
wake_me=True,
)
job_wait(job_id="job_abc123", filters=["checkpoint"], timeout_seconds=120)
job_wait(
job_id="job_abc123",
filters=["completed", "failed", "timeout", "cancelled", "orphaned"],
timeout_seconds=300,
)
job_run_summary(job_id="job_abc123")
job_tail(job_id="job_abc123", stream="stderr", max_bytes=8192)Know the wake limits
- Delivery is at-least-once. Each payload carries a
delivery_idfor deduplication. - An OpenCode TUI is woken by the plugin relay. Run
vanth setup opencodeand restart OpenCode. Without a live relay, the target is rejected at creation. - The default OpenCode turn timeout is 30 seconds. Raise it for long turns.
- A Codex thread must already have a turn. Waking a new, zero-turn thread fails with
no rollout found for thread id. - Codex Desktop wake is experimental. It covers one provisioned task per Desktop lifetime and needs a running Desktop session.
- Jobs survive a daemon restart. The runner is detached. The daemon marks a job
orphanedif the runner dies.
Sources and related
Commands checked against vanth 1.14.0 on Windows: vanth emit printed the event lines shown; vanth start, vanth wait, vanth logs, and vanth status ran one short job. The full wake loop needs a live OpenCode or Codex session and was not tested for this guide.