Skip to main content

Watch a background job while it runs

What it is

A job is a shell command that runs in the background. A watch makes Loomcoding send you the output lines that match a pattern while the job is still running, instead of only at the end.

What it is for

  • Seeing a compile error or a failed test as soon as it appears.
  • Waiting for a server to print that it is ready.
  • Avoiding repeated checks of the output.

How

  1. Ask the agent to start the command as a job, with a pattern to watch.
  2. Read the job: notices in the transcript as they arrive.
  3. Ask the agent to change or remove the watch with job_watch, or to stop the job with job_kill.

Example​

Your prompt:

> Start "cargo watch -x test" as a job and tell me when a test fails.

The agent calls job_start with a watch object, like this:

{ "command": "cargo watch -x test", "label": "tests",
"watch": { "pattern": "FAILED|error\\[", "max_events": 20 } }

Each notice has this shape in the transcript:

job: [Job 2 watch] <matching output line>

Transcript excerpt: a background job prints a line that matches the watch pattern, and the transcript shows it as a job notice with the line FAIL uno, followed by the system line that wakes the agent.

Tools​

ToolParametersWhat it does
job_startcommand, optional label, optional watch (pattern, max_events)Starts a job. A bad pattern fails before the command starts.
job_watchjob_id, optional pattern, optional max_eventsAdds, changes or removes the watch of a running job. An empty pattern removes it. Only lines printed after the call are watched.
job_outputjob idReads the output of a job.
job_listnoneLists the jobs of this session.
job_killjob idStops a job.

Limits​

LimitValue
Length of the pattern256 bytes at most
max_eventsFrom 1 to 100. Default 20.
Length of each notice line512 bytes at most
Notices per jobAt most one every 5 seconds, with up to 10 lines each
ScopeOnly jobs of the current session

Settings and defaults​

NameDefaultRequires restart
watch.max_events (per call)20No
Interval between notices5 seconds, fixedNot configurable

When the agent is idle, a watch notice can wake it up, within the same budget of automatic turns that subagents use. When the budget runs out, the notice waits for your next message.

Result​

You see job: lines while the command runs. When the job ends, the normal end notice arrives and closes the watch.

If it does not work​

SymptomFix
job_start fails with a watch error.The pattern is invalid or too long. Simplify it. The command did not start.
job_watch says the job is finished.Watches apply only to running jobs. Start a new job.
No notices arrive.No line printed after the call matches the pattern, or the output has not reached the next 5-second window.
Notices stop.The max_events limit was reached. A last notice says so. Use job_watch with a new max_events to set a higher limit.

Next steps​