Skip to content

A monitor lets an agent say "wake me when this finishes" and keep that promise. The agent starts a long command (a build, a deploy, a release workflow), registers a monitor on it, and ends its turn. When the command exits, prints the line you were waiting for, or a timer runs out, CompozyOS starts a new turn in the same session with the result. A monitor can also watch a pull request and wake the agent each time its checks or reviews need attention.

Why agents need it

Coding agents such as Claude Code and Codex have their own background tasks and monitors. Inside CompozyOS, those cannot start a new turn. A turn exists only when CompozyOS sends a prompt, so the agent's "I'll report back when it finishes" never came back and the session sat idle.

Monitors are owned by the CompozyOS daemon instead, so the wake always reaches the session:

  • every agent is told to use monitors for any wait on outside work, such as CI, deploys, or builds, whether or not it outlives the turn;
  • for Claude Code sessions, CompozyOS turns off the Monitor, ScheduleWakeup, and Cron tools and refuses background shell commands (Bash and PowerShell), because their results could never reach you. Background subagents keep working: their results return inside the turn that started them.

Shell waits are redirected

An agent that waits inside its own shell keeps the turn busy, so the session looks stuck and CompozyOS can't supervise the wait. When a session can use monitors, CompozyOS refuses these commands and tells the agent the exact call to make instead:

RefusedThe agent is told to
gh pr checks --watchregister a pull request monitor
gh run watch, watch, tail -frun it in a terminal and put a monitor on it
while, until, or for loops that sleep to pollrun the loop in a terminal and put a monitor on it
sleep for 5 seconds or moreset a timer monitor

Shorter sleeps, gh pr checks without --watch, and text that only mentions these commands still run. The check also sees through timeout, env, bash -c, and paths such as /bin/sleep. A gh pr checks --watch that names a pull request or another repository, or that depends on its directory or environment, is sent to a terminal instead.

What each provider gets:

  • Claude Code: a hook refuses the command before it runs.
  • Codex and other ACP providers: there is no hook, so the agent mostly relies on its instructions. CompozyOS can refuse a wait only when the provider asks for permission to run the command or opens a terminal through CompozyOS. Codex runs commands its sandbox allows without doing either, so those waits are not refused.
  • Sessions without the monitor or terminal tools: nothing is refused, because a shell wait is the only wait they have.

If the check itself fails, the command runs.

What a monitor can watch

KindFires whenLimits
terminalthe terminal's process exits (until: exit) or its output matches a pattern (until: match)timeout_seconds defaults to 30 minutes, up to 6 hours. A timeout still wakes the agent.
timerdelay_seconds have passed5 seconds to 24 hours
pull_requestchecks fail or finish, a review or unresolved thread arrives, or the pull request endstimeout_seconds defaults to 6 hours, up to 24 hours, and at most 64 wakes per monitor
sessionany or all of target_session_ids reach states (until: any or until: all)1 to 32 sessions. timeout_seconds defaults to 2 hours, up to 6 hours.

Each session can hold up to 8 active monitors, and each terminal up to 4. Registering the same terminal condition again (same terminal, until, pattern, normalized timeout, and description), the same branch for a pull request monitor, or the same session condition returns the monitor that is already active, so a retried call never adds a second wake.

Waiting for other sessions

A session monitor lets an agent hand work to several sessions, end its turn, and get one wake when they are done. The wake lists each session and its state.

  • Sessions must be in the same project and profile.
  • By default a session counts once it is idle, needs input or approval, needs attention, stopped, or failed. Use states to narrow or widen that list.
  • A stopped, failed, archived, or deleted session always counts, so it can't leave the agent waiting.
  • A session waiting on its own background work, or with queued messages, doesn't count as idle yet.
  • A session that a daemon restart stopped and didn't resume reads interrupted. It ends an all wait, and it ends an any wait only if stopped is in states.
  • The monitor checks each session as it is now. A session that needed input and got an answer before the check doesn't count.
  • If the condition already holds, the monitor fires right away.
  • At the timeout, the monitor checks the sessions one last time, so the wake can arrive up to 8 seconds late.
  • A session monitor survives a daemon restart and is checked again afterward. Restarting the daemon doesn't fire it.

There is no generic polling kind for remote state. For work that is not a pull request, such as a deploy, the agent runs a bounded watch command in a terminal and monitors that terminal, setting timeout_seconds past the expected wait.

Walkthrough: wait for a long command

Ask an agent to run something slow and report back, for example:

Run make release-check and tell me when it's done.

  1. The agent runs the command with compozy__terminal_exec. The command keeps going after the tool returns, so the result says still_running with a terminal_id.

  2. The agent calls compozy__monitor_create:

    json
    {
      "kind": "terminal",
      "terminal_id": "term-3f9a1c2b7d10",
      "until": "exit",
      "description": "make release-check finishes"
    }

    The result returns a monitor_id (for example mon-8c41e0a29b77) and tells the agent to end its turn.

  3. The agent ends its turn. The session goes idle, and you can keep working in other sessions.

  4. When the command exits, the transcript shows a divider: Monitor fired · make release-check finishes · Process exited. Right after it, the agent's new turn reads the exit code and the last lines of output, and reports back.

If you send a message while the agent is busy, the wake waits behind the current turn. If the session's input queue is full, CompozyOS keeps retrying the wake for up to 15 minutes. A pull request wake keeps retrying for as long as the monitor lives, and what changes meanwhile comes in the next wake. Stopping the session on purpose cancels its monitors, so nothing it registered restarts it later.

Walkthrough: watch a pull request

Ask an agent to open a pull request and see it through, for example:

Open a pull request for this branch and fix whatever CI or reviewers find.

  1. The agent pushes, opens the pull request, and calls compozy__monitor_create:

    json
    {
      "kind": "pull_request",
      "description": "fix what CI and reviewers find on my pull request"
    }

    The monitor follows the session's branch. Pass branch to watch another one. A default branch, or a session with no branch, is refused. If the pull request does not exist yet, the monitor waits for it. It also waits when the branch only has a pull request that had already merged or closed, as a reused branch does: only a pull request the monitor saw open can end it.

  2. The agent ends its turn, or keeps working on something else. CompozyOS reads the pull request about once a minute through the forge extension, with that extension's own credential. It never runs a command or a URL the agent supplied.

  3. When something needs the agent, a new turn starts with the facts: the pull request, its head, the check counts, the names of failing checks, and who reviewed. The transcript shows a divider such as Monitor fired · fix what CI and reviewers find on my pull request · Pull request changed.

  4. The agent reads the logs and reviews, pushes a fix, and ends its turn again. The monitor stays armed, so the next change wakes it too. Nothing else is needed from you.

  5. When the pull request merges or closes, one last wake says so and the monitor ends. The agent, not CompozyOS, decides when the work is done, so the agent can cancel the monitor sooner.

What wakes the agent:

ChangeWhen the wake arrives
A check failsAt the next read, about a minute. Failures already there wake at once
All checks finishAt the next read, once per head
A new review or unresolved thread on the headAfter 2 minutes of quiet, held at most 5, so a burst is one wake
The pull request merges or closesAt the next read. This is the last wake

What it deliberately does not wake on:

  • Reviews and threads already there when the monitor starts. Only new ones count.
  • A push by itself. A new head resets the checks and drops pending review activity. A review or thread that arrives late on the old head is ignored, though open threads stay in the count each wake reports.
  • A check rerun on the same head that passes. All checks finishing wakes once per head; a rerun wakes the agent only if it fails.
  • Review text. The wake says who reviewed and how, and tells the agent to read the reviews itself, including the review body, because follow-ups can live only there.

If the forge cannot be reached, those failed reads are never treated as check results. After 15 minutes of failures, one wake says the forge is unavailable and the monitor stays armed. If only reviews fail to load, checks keep working and reviews that arrive meanwhile are still reported once they can be read. Rate limits are respected, and sessions watching the same pull request share one read. A forge extension that does not report reviews still supports checks, and each wake says what it could not observe. Pull requests from forks are not visible to the monitor.

A pull request monitor keeps its slot for its whole life, and an always-on agent's session does not rotate while one is active.

Everything a forge reports, such as check names and author names, is treated as untrusted text, the same way terminal output is.

See and cancel monitors in the app

A session whose turn ended but still has an active monitor is not done yet, and the app says so:

  • In the session list, the row shows an amber radar mark instead of the green done check.
  • In the message box, a radar button with the number of active monitors sits next to the attach button. Click it to see what each monitor watches (a timer, a terminal exit, a terminal output pattern, or a pull request) and when it fires or gives up.
  • Click × on a monitor to cancel it. The session is not woken, and the watched command keeps running. A monitor that already fired reads "Waking the session…" and can no longer be canceled.

When the last monitor fires or is canceled, the radar button goes away and the row shows its normal state again.

The same reads are available over HTTP and the local socket:

Terminal
curl http://127.0.0.1:2123/api/workspaces/<workspace>/sessions/<session>/monitors
curl -X POST http://127.0.0.1:2123/api/workspaces/<workspace>/sessions/<session>/monitors/<monitor_id>/cancel

Full native session results (result_view: "full") and HTTP/UDS session payloads carry monitor_summary.active while the session has active monitors.

Managing monitors from the agent

  • compozy__monitor_list shows the session's active monitors first, then the ones from the last hour that fired, are still retrying their wake, were canceled, or could not be delivered.
  • compozy__monitor_cancel stops a monitor from waking the session. It does not stop the command being watched; use compozy__terminal_close for that.

Monitors are stored by the daemon and survive a restart. After the daemon comes back:

  • A timer keeps its original deadline. One that came due while the daemon was down fires right away.
  • A monitor that had already fired but was not yet delivered is delivered once; the terminal output it carried is not kept, and the wake says so.
  • A pull request monitor picks up where it stopped: changes during the downtime still wake the agent, and a wake that was not delivered is delivered once, unchanged.
  • A terminal does not survive a restart, and CompozyOS never reruns its command. A monitor on a terminal that no longer exists fires with the status "terminal is no longer observable".
  • The owning session is resumed only when CompozyOS would resume it after a restart: automatic continuation is on, the session is not archived, and its route, permissions, and tool policy have not changed. Otherwise the monitor is listed as interrupted, with the reason, and nothing wakes the session.
  • A session you stopped on purpose is never resumed by a monitor; its monitors are canceled. While CompozyOS is still checking an owner after a restart, its monitors are listed as active. If the owner cannot be checked for a while, the check is retried for the monitor's own lifetime (at least 15 minutes) before the monitor is listed as interrupted. If you delete a session that is not running during that time, its monitors are canceled by the next check, within about 30 seconds, rather than at the moment of deletion.