GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Token usage: no stable machine-readable export and no turn boundaries for external consumers · Issue #60278 · anomalyco/opencode

Token usage: no stable machine-readable export and no turn boundaries for external consumers #60278

New issue
Copy link
New issue
Copy link
Open
Open
Token usage: no stable machine-readable export and no turn boundaries for external consumers#60278
Copy link

Description

@suale-dev
suale-dev
opened on Oct 29, 2026
Issue body actions

Summary

OpenCode tracks token usage per assistant message and per session, but exposes
no stable, documented way to consume that data outside the TUI. External
consumers (scripts, CI, cost dashboards, agent tooling) are forced to
reverse-engineer the internal SQLite store, including WAL side files.

Current gaps

  1. No machine-readable export. Usage lives in session_v2.tokens_* and
    session_message.data (JSON-in-TEXT) inside ~/.local/share/opencode/opencode.db.
    There is no CLI command or documented API to export per-session /
    per-message usage as JSON/Markdown.

  2. No turn or invocation boundary. Sessions have no turn_id or
    task-boundary event. A long-lived or reused session cannot be split into
    separate invocations, so usage from earlier work bleeds into later reports.

  3. No per-response identity beyond message.id. There is no response-level
    id comparable to other hosts, which limits dedup and cross-checking.

  4. Effort is a model variant, not reasoning effort. model.variant
    (default/low/high) is the only signal; there is no reasoning-effort
    field, so consumers cannot distinguish effort levels reliably.

  5. Schema is internal and versioned. session vs session_v2,
    message vs session_message, JSON-in-TEXT columns. Any rename breaks
    parsers, and the DB is live with WAL files, requiring snapshot copying.

Requested improvement

Please consider adding a stable, documented way to obtain per-session and
per-message token usage:

  • a CLI command such as opencode usage export --session <id> --format json
    (or extending opencode stats) emitting per-message records with
    session_id, parent_session_id, agent, model, provider, variant,
    tokens { input, output, reasoning, cache { read, write } },
    time { created, completed };
  • optional per-turn boundaries (a turn id or task-boundary event) so a reused
    session's usage can be attributed to the correct invocation;
  • alternatively, document the SQLite schema as a supported read-only interface.

Why this matters

Token accounting is increasingly performed by external tooling, not only by the
TUI. A stable export would let consumers avoid coupling to OpenCode internals.
(Related but different in scope: #41915 requests an in-TUI /usage report.)

Environment

  • OpenCode v2.0.27
  • macOS, data dir ~/.local/share/opencode/

Activity

  1. opencodejr commented on Oct 29, 2026

    @opencodejr
    opencodejrBot
    on Oct 29, 2026
    Contributor
    More actions

    Thanks for the detailed write-up, @suale-dev! As I understand it, you'd like a stable, documented way to get token usage out of OpenCode for each session and each message. That could be something like opencode usage export --session <id> --format json or an extension of opencode stats. You'd also like turn or invocation boundaries, so that usage in a reused session can be attributed to the right run, instead of external tools having to parse the internal SQLite database.

    For reference, v2 currently has opencode stats --json, which outputs aggregate totals only, and opencode session export, which dumps the session as JSON through an experimental endpoint. Neither offers a documented per-message usage schema or turn ids, so this is a fair gap to raise.

    Related issues:

    • [FEATURE]: Structured usage export for task-level evaluations #48821: requests a structured (JSON/CSV) usage export split per provider step. It overlaps heavily with your first point, but does not cover turn boundaries or schema documentation.
    • [FEATURE]: /usage — dedicated session token & cost report (alias /cost) #41915: an in-TUI /usage report, as you noted.
    • cli: stats totals differ from stored session usage #57878: opencode stats totals differ from stored session usage, which matters if you rely on stats --json in the meantime.
    • cli: stats --days N omits cost/token/cache breakdown that v1 showed by default #47481: stats --days N omits the cost/token/cache breakdown.

    The maintainers will consider this request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.