anomalyco / anomalyco/opencode

bug: headless "opencode run" provides no agent identity on the event bus

Open
#46,652 1 comment 0 reactions 1 assignee View on GitHub

@jlongster is already working on this.

Since Sep 1, 2026.

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

Description

Version

opencode 1.18.25 (npm package opencode-ai)

Description

Headless sessions started via opencode run carry no agent identity on the event bus. Downstream consumers (plugins subscribing to bus events) receive only part-level events and never learn which agent ran the session, even when --agent <name> is passed explicitly.

Reproduction
opencode run --format json --agent general "Reply with the single word OK" > out.json
grep -c '"agent"' out.json   # → 0

The JSON stream contains only step_start / text / step_finish part events:

{"type":"step_start","timestamp":...,"sessionID":"ses_...","part":{...}}
{"type":"text","timestamp":...,"sessionID":"ses_...","part":{...,"text":"OK",...}}
{"type":"step_finish","timestamp":...,"sessionID":"ses_...","part":{...,"reason":"stop",...}}

There is no session-level event with the resolved agent name.

Corroborating evidence from a telemetry plugin that subscribes to the bus and enriches session.created (capturing info?.agent, info?.directory, info?.parentID): in the spooled event for this exact headless run, sessionAgent is null while sessionWorktree (from info.directory) is delivered:

"sessionAgent":null
"sessionWorktree":"/tmp/opencode"

So the bus delivers the session's directory but not its agent in headless mode. TUI sessions and sessions created with an agent via the SDK do populate the agent name in our telemetry, which suggests the data exists at session level and is only missing from the headless run path.

Expected behavior

opencode run --agent <name> (and headless sessions generally) should expose the resolved agent name on the event bus (e.g., in session.created info), the same way TUI/SDK sessions do.

Impact

Downstream observability cannot attribute headless sessions to the agent that ran them. We currently fall back to a parent-child correlation (sessions.parent_id → parent session's agent) for subagents spawned via task(), but top-level headless sessions remain unattributed in any per-agent cost/quality breakdown.

Workaround

Resolve the agent by joining the child session to its parent session (which does carry identity); not possible for top-level headless sessions.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.