Skip to main content

Module opencode

Module opencode 

Source
Expand description

OpenCode agent runner.

§CLI invocation

opencode run --format json -m {model} - < "{msg_file}"

§Output format (run --format json)

NDJSON stream:

{"type":"step_start","timestamp":...,"part":{"type":"step-start","snapshot":"..."}}
{"type":"text","timestamp":...,"part":{"type":"text","text":"hello"}}
{"type":"step_finish","timestamp":...,"part":{"type":"step-finish","reason":"stop","cost":0,"tokens":{"total":17512,"input":17509,"output":3}}}

§Token extraction

Tokens are in the step_finish event: part.tokens.{input,output,total}

§Free models

Discoverable via: opencode models | grep free Discovered dynamically at startup with 1-hour cache.

Structs§

OpenCodeRunner
Runner for OpenCode agent.

Functions§

discover_free_opencode_models
Discover free opencode models, with 1-hour cache and background refresh.
discover_opencode_models
Discover all opencode models, with 1-hour cache and background refresh.
find_opencode_result
Extract a structured AgentResult from OpenCode NDJSON output.
prime_free_model_cache
Prime the free-model cache synchronously at startup.