Skip to content

cli(run): --format json omits synthetic background completion notices and completed compactions #64851

Open

Description

@zsicheng0214

Description

opencode run --format json (packages/cli/src/run/noninteractive.ts) emits background_wait when waiting on background subagent or shell jobs, and streams step_start, text, reasoning, tool_use, step_finish, retry, and error events. However, two durable session events delivered during the same run are omitted from both live streaming (renderer.event) and end-of-run projection reconciliation (renderer.reconcile, which skips everything with if (message.type !== "assistant") continue):

  1. Background job completion notices (session.synthetic / message.type === "synthetic"): When a background subagent or shell job finishes and delivers its <subagent> / <shell> report (metadata.source === "subagent" | "shell") to wake the parent session, no JSON event is emitted between background_wait and the woken assistant step_start, leaving downstream JSON consumers without the completion payload or child/shell correlation metadata.
  2. Completed compactions (session.compaction.ended / message.type === "compaction" with status === "completed"): Automatic or manual compactions carry the compaction summary along with cost and tokens (which session-event.ts notes are repeated on session.compaction.ended because session.usage.recorded never reaches clients), but --format json never emits them, causing both compaction visibility and JSON-stream token/cost accounting to miss compaction turns.

Plugins

None

OpenCode version

2.3.0 (dev)

Steps to reproduce

  1. Run opencode run --standalone --auto --format json with a prompt that spawns a background subagent (or background shell command) and waits for its completion report.
  2. Inspect the NDJSON lines written to stdout.
  3. Observe tool_use (status: "running") followed by background_wait and then the woken assistant's step_start, with no JSON event for the delivered synthetic <subagent> / <shell> report (nor for any compaction completed mid-run).

Operating System

Linux (Debian 12)

Terminal

Bash

Activity

  1. opencodejr commented on Nov 19, 2026

    @opencodejr
    Contributor

    Thanks for the detailed write-up and for the PR (#64852).

    You're asking for opencode run --format json to also emit an event when a background subagent or shell job delivers its completion report, and one when a compaction completes, with its summary, cost and tokens. That way, programs reading the JSON output get those payloads and complete usage totals.

    The JSON renderer emits a fixed set of event types, and its end-of-run reconciliation only covers assistant messages. The docs describe the flag only as emitting newline-delimited JSON for scripts. So adding these events means extending the output format, and I've marked this as a feature request for the maintainers to consider.

    Related:

  2. added
    area/cli
    type/feature
    version/v2
    on Nov 19, 2026
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

    area/cliplatform/linuxtype/featureversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions