Skip to main content

Module opencode

Module opencode 

Source
Expand description

OpenCode session reader (SQLite, not JSONL).

Unlike the five file-based providers, OpenCode stores every session in a single SQLite database at ~/.local/share/opencode/opencode.db (WAL mode). This module owns the “SQLite rows -> typed CodeAnalysis” boundary, so both the usage and analysis aggregators consume the same shape the file-based providers produce.

Two entry points keep the work proportional to what each command needs:

  • read_opencode_usage reads assistant messages for per-model tokens and cost, with an older session-table fallback.
  • read_opencode_analysis additionally folds the part table’s tool calls (read, edit, write, bash, todowrite) into per-message file-operation metrics.

Token columns map onto the Claude-style flat usage shape so the existing merge_usage_values / extract_token_counts / LiteLLM cost path works unchanged. Assistant messages carry their own providerID + modelID, so sessions that switch model mid-stream are split before aggregation.

Functions§

read_opencode_analysis
Reads per-session file-operation metrics from the OpenCode database.
read_opencode_usage
Reads per-session token usage from the OpenCode database.