Skip to content

[FEATURE]: /schedule — run recurring background tasks (cron-like routines) #41906

Open

Description

@afonsoft

Requested feature

Add a /schedule slash command (inspired by Claude Code's /schedule) to run recurring, background, non-interactive tasks on a timer — e.g. periodic CI/CD sweeps, lint/typecheck runs, or repo reviews.

Why

Today opencode has an internal BackgroundJob service (packages/core/src/background-job.ts, packages/opencode/src/background/job.ts) used for things like session compaction and summary pruning, but there is no user-facing way to schedule a recurring job from the TUI and no cron-like cadence. Automations currently require external orchestrators (n8n, scripts).

Proposed behavior

  • /schedule every 5m <task> or /schedule cron '*/5 * * * *' <task> registers a recurring background routine.
  • Jobs appear in a scheduler list (pause/resume/cancel), run detached from the active session, and surface results via the existing notifications/background job UI.
  • Reuse/extend BackgroundJob.Service (packages/opencode/src/background/job.ts) with a persistence + scheduling layer so jobs survive across sessions.

Benefits

  • In-terminal recurring automation without external tooling.
  • Consistent with the existing background job infrastructure.

Activity

  1. yanxingyu17 commented on Sep 8, 2026

    @yanxingyu17

    We have been prototyping this use case locally and would like to discuss the design before opening a PR.

    Our prototype currently supports:

    • persistent local SQLite-backed automations for once, interval, and five-field cron schedules;
    • timezone-aware scheduling, restart recovery, missed-run policies, retries/backoff, stale-run recovery, and run history;
    • an isolated Agent execution path;
    • a direct, explicitly allowlisted command path for lightweight deterministic jobs, which does not create a Session;
    • CLI management for create/list/show/run/pause/resume/history/remove.

    We validated the prototype with Core automation tests, OpenCode executor/CLI tests, typechecks, migration checks, a Linux x64 build, and a real two-minute command-mode run. The command-mode run produced two Feishu messages 120.683 seconds apart and created no Sessions.

    Before proposing an upstream implementation, we would appreciate guidance on a few architectural questions:

    1. Should this extend the existing BackgroundJob.Service rather than introduce a separate scheduler service?
    2. Should scheduling be owned by serve, web, a separate daemon mode, or an opt-in experimental process?
    3. What ownership/fencing semantics are expected when multiple server processes share the local database?
    4. Would a local persistent scheduler belong in core, or should the first implementation live as an official plugin/companion service?

    We have also reviewed the related scheduling discussions and PRs (#41907, #18001, and #44191). We are happy to adapt the prototype to the preferred direction rather than submit a large, pre-decided PR.

  2. danibauti94 commented on Oct 7, 2026

    @danibauti94

    Thanks for proposing this. I would like to add a Web UI / Tasks experience to the scope, similar to Codex Tasks or Claude Code scheduled tasks, so schedules are manageable without relying on the TUI.

    For a self-hosted setup, it would be especially useful if tasks could be created and managed in the Web UI (prompt, agent, workspace, and schedule), then executed server-side by an existing OpenCode Serve instance. The browser could be closed and the task would continue to run as long as that server is available; schedules and run history should survive restarts.

    A useful first-class task lifecycle would include one-shot, interval, and cron schedules; Run now, pause, resume, and delete actions; per-run status, timestamps, output/logs, and failure details; and notifications when a run completes or fails. Each run should reuse the selected workspace's existing OpenCode configuration, agents, MCP servers, skills, and plugins, rather than requiring a separate integration or external orchestrator.

    This would make the existing scheduling/background-job proposal useful for ongoing homelab maintenance, such as periodically checking and updating self-hosted documentation. The TUI can remain a management surface too, but a Web UI is important for users primarily running OpenCode through Serve.

  3. opencodejr commented on Oct 28, 2026

    @opencodejr

    Thanks for the detailed request, @afonsoft! You're asking for a /schedule command that runs prompts again and again in the background, on an interval or a cron expression, with schedules that persist and can be paused, resumed or cancelled.

    Maintainers will consider it. Some related work is already in progress:

    You can follow those PRs to see how this develops.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions