Skip to content

run --format json events don't say which model produced them #40544

Description

@macurandb

Description

opencode run --format json emits step_start / step_finish events with tokens and cost, but no model. Nothing in the stream says which model produced a step, so a headless consumer can't attribute usage or cost to a model.

The data isn't missing from opencode — only from the stream. opencode export <sessionID> has providerID / modelID on every assistant message, and the default (human) format already prints the model header. It just never reaches the JSON path.

This matters for multi-model sessions: switching models mid-session, or subagents running a different model than the parent, are unattributable today. Recovering it needs a second opencode export call after the run, which doesn't work for a live consumer.

Event keys, same across three runs: cost, id, messageID, reason, sessionID, tokens, type.

OpenCode version

1.14.28

Steps to reproduce

  1. opencode run --format json -m opencode/ling-3.0-flash-free "Reply with exactly: OK"
  2. Continue that session with a different model: opencode run --format json --session <sessionID> -m opencode/mimo-v2.5-free "Reply with exactly: SECOND"
  3. The step_finish events from both turns are indistinguishable:
{"id":"prt_…","reason":"stop","messageID":"msg_fcdd0d049001VruQNZZOX4Z9LQ","sessionID":"ses_032300dcdffeods08f6tn9QMAy","type":"step-finish","tokens":{"total":21335,"input":20277,"output":4,"reasoning":30,"cache":{"write":0,"read":1024}},"cost":0}
  1. opencode export <sessionID> on that same session does distinguish them:
msg_fcdcff80c001Cp | opencode / ling-3.0-flash-free
msg_fcdd0386f001gQ | opencode / ling-3.0-flash-free
msg_fcdd0d049001Vr | opencode / mimo-v2.5-free

Operating System

macOS 26.5

Terminal

VS Code integrated terminal

Metadata

Metadata

Assignees

No one assigned

    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