anomalyco / anomalyco/opencode

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

Open
#40,544 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the entry point handling opencode run --format json and trace serialization for step_start and step_finish; compare it with the model fields shown by opencode export <sessionID>. Reproduce the two-model session from the issue and verify that live JSON events identify the provider and model for each step.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.