Skip to content

Feature request: native file/path watch primitive (Claude Code Monitor() equivalent) #737

Open

Description

@rameshbaskaran

Summary

jcode has no first-class primitive equivalent to Claude Code's Monitor() tool: watch a filesystem path (or process/log) and automatically inject change events into the conversation as they happen, without the agent having to poll.

What exists today (and why it's not equivalent)

  • bg (watch/subscribe/delivery) monitors background tasks the agent itself started — it wakes/notifies on task completion or checkpoints, not on arbitrary file mtime/content changes.
  • ScheduleWakeup lets an agent schedule itself to wake up after a delay and re-run a prompt. This can approximate a watcher (wake every N seconds, stat/diff a file, react if changed), but it's the agent hand-rolling a poll loop every time, not a reusable primitive — no debouncing, no diff-on-change payload, no clean "stop watching" lifecycle, and it burns a scheduled wakeup slot per file per session.

Requested capability

A watch_file (or similar) tool/primitive that:

  • Takes a path (file or directory, optionally recursive) to watch, likely backed by FSEvents/kqueue on macOS and inotify on Linux, rather than polling
  • Delivers change events (created/modified/deleted, ideally with a diff or new-content snippet) as part of the agent's next turn — analogous to how bg's wake/notify delivery already works for background tasks
  • Supports start/stop/list, similar to the existing bg lifecycle actions
  • Optional debounce interval to avoid flooding turns on rapid successive writes (e.g. log files, build output)

Use case that surfaced this

Coordinating on a task where the natural pattern was "watch this file/log and tell me when it changes" (mirroring a Claude Code workflow the user already relies on) — currently the only way to do this in jcode is to hand-build a poll loop with bg/ScheduleWakeup, which works but isn't a real primitive and doesn't compose well across sessions/swarm workers.

Non-goals / scope note

This is a feature request, not a bug report — happy to help scope further (e.g. should this live in the bg tool as a new watch-source type, or be its own tool) if useful.

Activity

  1. rameshbaskaran commented on Aug 3, 2026

    @rameshbaskaran
    Author

    Broader context: this is a cross-cutting requirement, not a one-off ask

    Filing this with the concrete use cases that motivate it, since a generic "watch a file" API undersells how foundational this is for real agent workflows:

    Use case 1 — Trade/position monitoring

    Watching live state files (position snapshots, P&L JSON, order-status logs) written by a trading system and reacting the moment they change — fills, stop-loss triggers, margin alerts, daily P&L thresholds. Today this means either a hand-rolled poll loop (wastes a scheduled-wakeup slot per file, adds latency proportional to poll interval) or a bespoke daemon outside the agent entirely that has to re-implement delivery-into-conversation from scratch.

    Use case 2 — Telegram / external messaging monitoring

    Watching for new messages/webhooks landing in a local queue/log file (or a socket/pipe) and reacting live — this is currently done via a separate long-running daemon process that polls and pushes into the agent's queue manually. A native watch primitive would let the agent own this loop directly instead of depending on external daemon infrastructure per integration.

    Use case 3 — Inter-session / inter-agent communication

    Multiple jcode sessions (or swarm workers) coordinating via shared files (queue.jsonl-style outboxes, handoff docs, status files) — right now this is polling-based (queue_reader.py-style scripts) with all the same downsides: per-file poll loops, no debounce, no clean lifecycle, and it doesn't compose with jcode's own swarm/bg primitives even though the pattern (something external changes, tell me about it) is identical to what bg's watch/wake/notify already does for background tasks.

    Why this generalizes beyond me

    Any agent user running jcode against live external state — logs, trading systems, chat platforms, other processes, other agent sessions — hits the same gap: there's no way to say "watch X, tell me when it changes" without building custom polling infrastructure per integration. A first-class primitive here would collapse three-plus bespoke patterns (poll-loop-via-ScheduleWakeup, external daemon + manual injection, queue-file polling scripts) into one reusable mechanism, and it composes naturally with bg's existing wake/notify/subscribe delivery model rather than requiring a fourth parallel mechanism.

    Suggested priority framing

    Given it underpins several concrete, already-in-use workflows (not just a nice-to-have), worth treating as a core-infra requirement for anyone building monitoring/automation on jcode, not a niche feature request.

  2. rameshbaskaran commented on Aug 3, 2026

    @rameshbaskaran
    Author

    One more requirement from Claude Code's Monitor(): multiple concurrent monitors per session. A single session commonly needs several independent watches active at once (e.g. a trade-state file + a Telegram inbox log + an inter-session outbox, all in the same session simultaneously), each delivering its own change events without interfering with the others.

    Implications for the API shape:

    • Each watch_file-style call should return its own handle/id, not be a singleton per session
    • A list/status action to see all active watches in the current session (mirroring bg action=list)
    • Independent debounce/lifecycle per watch — stopping one shouldn't affect the others
    • Delivery needs to disambiguate which watch fired when multiple are active (include the watch id/path in the injected event)

    This maps well onto extending bg's existing multi-task model (which already handles N concurrent background tasks per session with independent status/wake/notify) rather than inventing a separate single-watch-only mechanism.

  3. added
    enhancement
    priority: medium
    triage: needs-decision
    autonomous: no
    on Aug 3, 2026
  4. 1jehuang commented on Aug 3, 2026

    @1jehuang
    Owner

    Thanks for the concrete requirements. This needs an architecture decision between extending bg with durable watch sources and introducing a separate watcher registry, especially for lifecycle cleanup and remote-session delivery.

    --- — Jcode agent (automated triage), on behalf of @1jehuang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    autonomous: noenhancementpriority: mediumtriage: needs-decision

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions