Skip to content

(schedules): run a scheduled task as a background session so it can be joined while it runs #611

Open

Description

@devsuitup

Problem

A scheduled run cannot be joined while it runs. schedule-runner.js (~408) launches claude -p 'Run the scheduled task' … as a detached child process with no PTY. Stdout is dropped, so there is no live view and nothing to attach to. A "Resume anyway" on a running scheduled session would start a second claude on the same conversation, so two processes would write one transcript. Today it is refused (.ai/contexts/schedule-runner.md, live-elsewhere).

The maintainer (13/10) wants to step into a scheduled task while it runs.

Proposal

Launch scheduled runs as Claude Code background jobs (--bg, the daemon) instead of claude -p. Each run then becomes an attachable job:

This can be a per-schedule setting, chosen when configuring the schedule (e.g. "Run as a background session (can be joined while it runs)"), so headless -p stays available. The default is to be decided once the measurements below are in.

Measure first (CLI 2.1.296+, Windows and Linux)

  1. Does claude --bg accept an initial prompt and run it without a terminal? Does it end by itself when the task is done, or stay idle until stopped? If it stays idle, who stops it, and when?
  2. Do the flags the runner passes today work with --bg? These are the permission mode, --add-dir, model, worktree, the sandbox wrapper (scripts/claude-sandbox.sh) and the pre-seeded session id / resume used for provenance (scheduleSlug).
  3. How does the job's descriptor (kind:"bg", jobId) map to the run's session, so the sidebar row and the schedule's run history stay linked?
  4. What happens to concurrency guards, catch-up (skipMissedRuns) and the in-flight key when the run is a daemon job rather than a child process? Is completion still observable for the next tick?
  5. Remote hosts: are scheduled runs on a remote host in scope?

Out of scope

Changing the cron, the schedule file format beyond the new setting, or the headless -p path itself.

Related: #546 (attach conversion), #567 (live-elsewhere rule), #565 (Stop/Detach).

Activity

  1. jbr-sekoia commented on Oct 27, 2026

    @jbr-sekoia
    Collaborator

    Related: #814 makes a running scheduled task count as running (Running filter, never in "+ N older") and makes the transcript view refresh while the run writes. It holds for today's headless -p runs, independently of this issue.

  2. devsuitup commented on Oct 28, 2026

    @devsuitup
    OwnerAuthor

    After #820: the schedule command builder goes through the harness headless args.

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions