Monitor Tool: Event Streaming from Background Scripts¶
Stream stdout from a background process directly to Claude — each output line arrives as a notification, no polling required.
The Monitor tool, added in Claude Code v2.1.98 (April 9, 2026), lets Claude watch a long-running process and react to its output mid-conversation. Claude writes a small watch script, runs it in the background, and receives each stdout line as it arrives. The conversation continues normally; Claude interjects only when an event lands.
Push vs poll¶
Before Monitor, watching a background process meant using Bash with run_in_background: true and polling for results. Background tasks write output to a file; the agent calls Read to check progress. [Source: Claude Code Tools Reference]
Bash (run_in_background: true) → agent calls Read on output file to check progress
Monitor inverts this. It pushes each stdout line to Claude as a notification:
Monitor → each line arrives as a notification → Claude reacts immediately
The polling loop disappears. The agent handles other work and responds to events as they arrive.
Use cases¶
| Scenario | What to watch |
|---|---|
| Deploy monitoring | Tail deploy logs, flag errors or completion |
| CI status | Watch a gh run list poller until a run finishes |
| File watching | Watch a directory for build artifacts |
| Test suite streaming | Stream test runner output, surface failures as they occur |
| Long-running scripts | Any process that emits progress lines over time |
Starting and stopping a monitor¶
Ask Claude in natural language — no special syntax required:
Watch the deploy log at /var/log/deploy.log and tell me if any errors appear.
Poll the GitHub Actions run for this branch every 30 seconds and report when it finishes.
Claude writes the watch script internally and starts it. To stop, ask Claude to cancel the monitor, or end the session. All monitors are session-scoped: they stop when the session exits.
Permissions and availability¶
Monitor uses the same allow and deny permission rules as Bash. Any pattern you set for Bash applies to Monitor automatically.
On Bedrock, Vertex AI, Foundry, or with DISABLE_TELEMETRY or CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC set, Monitor requires Claude Code v2.1.310 or later. [Source: Claude Code Tools Reference]
Monitor vs scheduled polling¶
Both Monitor and session scheduling handle recurring background activity, but they differ in mechanism:
| Monitor | CronCreate / /loop | |
|---|---|---|
| Trigger | Each stdout line from a process | Timer interval |
| Cadence | Continuous stream | Minimum 1 minute |
| Script lifecycle | Managed by Monitor | Re-runs Claude each fire |
| Best for | Streaming logs, file watchers | Periodic status checks |
Use Monitor when the process already emits events and you want zero-latency reactions. Use scheduling when you want Claude to run a fresh check on a timer.
When this backfires¶
Push beats poll when events are rare and meaningful. It loses when any of the following hold:
- Chatty processes flood context, and Monitor will stop them. Every stdout line becomes a notification. Watching a verbose test runner, webpack rebuild, or
pytest -vvpipes thousands of events into the conversation, and Monitor automatically stops any monitor that produces too many events. Restart it with a tighter filter if that happens. [Source: Monitor tool description] Pipe throughgrepbefore monitoring, or capture to a file andReadon demand. - Pipe buffering silently delays events. When piping to
grepor similar filters, usegrep --line-buffered. Without it, standard block buffering holds output until a ~4 KB chunk fills, which can delay events by minutes on low-traffic streams. [Source: Monitor tool description] - Stderr and exit codes are invisible. Monitor forwards stdout only. A script that logs errors to stderr, crashes silently, or communicates via a non-zero exit status will look healthy to Monitor. Use
Bashwith captured output for anything where failure is silent. - Outcome filters must match every terminal state. When you watch a job for a result, the filter has to match both success and failure signals. Otherwise a failed run produces silence, which Claude reads as "still running". [Source: Monitor tool description]
- Low-cadence checks do not need streaming. If the thing you watch changes every few minutes (a slow CI run, a nightly build), scheduled polling with
CronCreateor/loopis just as responsive, does not hold a background process open, and survives across idle windows. - Session-scoped lifetime. Monitors die when the Claude session exits. For batch jobs that need to outlive a conversation, or monitoring across reboots, use an external supervisor (systemd, cron, CI) instead.
- Builds before v2.1.310 lack Monitor on Bedrock, Vertex AI, Foundry, and with telemetry or nonessential traffic off. [Source: Claude Code Tools Reference]
Example¶
Monitor a Docker Compose deployment and surface errors the moment they appear:
Run `docker compose up --build` in the background and monitor its output.
Flag any lines containing "error" or "failed" immediately, and tell me when
all services report "healthy".
Claude starts docker compose up --build, monitors its stdout, and interjects on error lines or when the health check passes — without blocking the conversation or requiring manual polling.
Key Takeaways¶
- Monitor pushes each stdout line to Claude as a notification;
Bash run_in_backgroundrequires the agent to poll manually - Session-scoped: monitors stop when the session exits
- Uses the same permission rules as Bash — no separate configuration required. Hook
ifconditions are the exception: they name one tool each, so Monitor needs its own rule - On Bedrock, Vertex AI, Foundry, or with telemetry or nonessential traffic disabled, Monitor needs v2.1.310 or later
Related¶
- Plugin Background Monitors
- Wait Primitive Plus Shell-Sleep Deny — why the 2.1.310 release paired Monitor with a sleep block
- Session Scheduling
- Hooks & Lifecycle
- /batch & Worktrees
- Observability