Skip to content

Feature: run_in_background flag for bash + completion notifications #24885

Closed

Description

@abrar360

Problem

The bash tool blocks the assistant turn until the command exits or hits the
2-minute default timeout. For long-running commands the model wants to launch
and revisit later — dev servers, watch processes, builds, log followers — this
forces awkward workarounds (& + redirects, nohup, polling) that the model
handles inconsistently and tends to get wrong.

Claude Code addresses this with a run_in_background: true flag on its bash
tool plus a completion-notification mechanism. Opencode currently has no
equivalent, and it shows up as a routine friction point.

Why it belongs in OpenCode

This is a parity gap with a battle-tested pattern, not a net-new product
surface. Models are already trained to use run_in_background in CC, so
adding it here means existing model behavior just works. It also unblocks
a class of workflows (long-running watchers, soak tests, dev servers) that
are currently painful.

Proposed approach

High-level shape:

  • Add an optional run_in_background: boolean parameter to the bash tool.
    When true, the spawn returns immediately with a task ID + output file
    path; the command runs detached, with output streamed to a file in
    opencode's existing truncation directory.
  • Add a bash_kill (or generic task_stop) tool that takes a task ID and
    terminates the running task. Reading partial/final output uses the
    existing Read tool against the output file path — no new "bash_output"
    tool needed.
  • On natural completion or stall-detection, attach a synthetic part to the
    next user message handed to the LLM, telling the model the task ended
    (status, exit code, output file path). This reuses opencode's existing
    insertReminders / synthetic-text-part convention rather than introducing
    a new attachment vocabulary.
  • A one-shot stall watchdog detects commands blocked on stdin (heuristic on
    the output tail) and emits a notification with a kill+rerun-with-piped-input
    recovery instruction.

Internally: a BackgroundTask service forks workers into the instance scope
(so they survive the bash tool returning), publishes Bus events on lifecycle
transitions, and a notifier subscribes to those events and queues per-session
notifications. Drain happens at the same loop seam as insertReminders.

I have a working branch implementing this; happy to share details or open a
draft PR if the design is approved in principle.

Open questions for maintainers

I'd particularly value direction on these before opening a PR:

  1. Naming / scope. Is this strictly a bash feature (BashTasks service,
    bash_kill tool), or is there appetite for a more generic background-task
    framework now (BackgroundTask service, task_stop tool with bash being
    the first kind)? Affects future extensibility.
  2. Notification envelope. CC wraps the completion notification in a
    <task-notification> XML structure; my current draft uses opencode's
    <system-reminder> envelope for consistency with insertReminders.
    Match CC's format for closer behavioral alignment, or keep the opencode
    convention?
  3. Feature flag. Should this ship behind an experimental flag (e.g.
    OPENCODE_EXPERIMENTAL_BASH_BACKGROUND) until it has real-world soak time?
  4. Kill-after-completion semantics. CC throws "not running" if you try to
    kill a finished task; I made it a no-op returning the existing status.
    Either is defensible — preference?

Not in scope (deferred from CC parity)

Calling these out so it's clear what's not being proposed for v1:

  • Auto-backgrounding of long-blocking commands (CC moves them to background
    after ~15s in assistant mode)
  • Mid-flight backgrounding (CC's Ctrl+B equivalent)
  • Per-agent notification routing (would scope by sessionID for now)
  • TUI-side fold of consecutive completion notifications
  • Notification priority levels

Each could be a follow-up if there's demand.

Status

Working branch is ready locally. Will open a PR referencing this issue once
the design questions above have direction.

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 29, 2026
  2. github-actions commented on Apr 29, 2026

    @github-actions
    Contributor

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    • Feature request titles must start with [FEATURE]: (current title starts with Feature:)
    • The feature request template requires a verification checkbox confirming the feature hasn't been suggested before

    Please edit this issue to address the above within 2 hours, or it will be automatically closed.


    This issue might be a duplicate of existing issues. Please check:

    If you believe this was flagged incorrectly, please let a maintainer know.

  3. abrar360 commented on Apr 29, 2026

    @abrar360
    Author

    Closing as duplicate of #1970, which is the canonical active thread for this feature (8 months of discussion, last activity a few days ago). Apologies — I went straight to filing rather than searching first.

    I've posted the design proposal and a link to a working branch over on #1970 for maintainer review.

    Thanks to the issue-compliance bot for the catch.

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

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)needs:complianceThis means the issue will auto-close after 2 hours.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions