npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

opencode-token-cost-tracker

v0.3.0

Published

OpenCode TUI plugin: live tokens/sec, session token totals, and per-model cost breakdown with DeepSeek peak/off-peak pricing.

Readme

opencode-token-cost-tracker

npm version npm downloads license opencode

Live tokens/sec, full-session token totals, and a per-model cost breakdown for the opencode terminal UI — including DeepSeek peak/off-peak pricing.

Zero config: add it to tui.json, restart opencode, done.

Contents

Preview

Status line (bottom of the chat pane, centered, never overlapping the sidebar):

cache 12.34k  ·  in 45.67k  ·  out 8.90k  ·  reason 1.20k  ·  avg 42.3 t/s  ● off-peak

Cost panel (right sidebar, collapsible):

▾ Cost                        $0.0154
  ▸ deepseek-flash             $0.0070
    In $0.15 · Out $0.60 · C $0.003
    cache         12.3k    $0.0000
    input         45.7k    $0.0069
    output         0.9k    $0.0011

  ▸ deepseek-flash (peak)      $0.0210
    In $0.30 · Out $1.20 · C $0.006
    cache          4.1k    $0.0000
    input         30.0k    $0.0090
    output         6.0k    $0.0144

  ▸ Subagents                  $0.0031
    in 9.4k · out 3.1k · c 6.2k

Expanding Subagents lists each child session with its own in/out/c (reasoning folded into out):

  ▾ Subagents                  $0.0031
    in 9.4k · out 3.1k · c 6.2k
    explore: find the…         $0.0022
      in 5.0k · out 2.0k · c 4.0k
    general: run tests…        $0.0009
      in 4.4k · out 1.1k · c 2.2k

  Total                        $0.0185

Features

  • Status line — session-wide token totals (cache reads, input, output, reasoning), token-weighted average speed (t/s), and a blinking DeepSeek peak/off-peak indicator.
  • Cost panel — per-model totals, the catalog rates (In / Out / C), and per-category tokens with estimated cost. Click a model name to expand output and reason separately; collapsed, they are combined.
  • Full-session accuracy — totals are read from the whole session through the SDK, not just the recent window the TUI keeps in memory, so counts do not shrink when you reopen a session.
  • DeepSeek peak/off-peak pricing — peak usage is shown as its own ‹model› (peak) entry priced at 2× the listed off-peak rates (peak = 01:00–04:00 and 06:00–10:00 UTC, Mon–Fri).
  • Subagents — a collapsible Subagents section shows the cumulative in/out/c token usage and cost of every subagent (child) session, and expands to a per-subagent breakdown (subagent_type: description), each with its own in/out/c. Reasoning is folded into out.
  • Session total — a Total line adds the active session's models plus all subagents, so you can see the real session spend at a glance.
  • Zero config, no build step — opencode's runtime transpiles the TSX and provides solid-js / @opentui.

Requirements

  • opencode >= 1.15.0
  • Terminal wider than 120 columns (or a manually toggled sidebar) to see the Cost panel.

Install

From npm (recommended)

Add the package to your global tui.json (~/.config/opencode/tui.json):

{
  "$schema": "https://opencode.ai/tui.json",
  "plugin": ["opencode-token-cost-tracker"]
}

Restart opencode. The package is installed automatically on first run.

From a local file

Copy tps-monitor.tsx into ~/.config/opencode/tui/ and reference it by path:

{
  "$schema": "https://opencode.ai/tui.json",
  "plugin": ["./tui/tps-monitor.tsx"]
}

Usage

  • The status line is centered within the chat column so it never runs under the sidebar.
  • The Cost panel renders in the right sidebar. Click the Cost header to collapse or expand the whole panel.
  • Click a model name to toggle its output/reason breakdown.
  • The Subagents section appears when a session has spawned subagents — it shows their cumulative cost and expands to a per-subagent breakdown.
  • Prices come from models.dev — the same catalog opencode uses.

State is kept in opencode's KV store:

| Key | Default | Meaning | | --- | --- | --- | | token-cost-tracker.cost_expanded | true | Cost panel expanded | | token-cost-tracker.model.<provider>/<model> | false | Per-model expanded (add #peak for peak entries) | | token-cost-tracker.subagents_expanded | false | Subagents section expanded |

How it works

  • Totals are computed from session.messages (no limit) via the SDK and cached per session. The live TUI store is merged on top so streaming stays real-time.
  • Average t/s = Σ(output + reasoning) ÷ Σ(turn span), where a turn's span runs from its first streamed text/reasoning token to completion (the in-progress turn uses "now").
  • Cost = tokens × catalog rate ÷ 1,000,000. Reasoning is billed at the output rate when no dedicated rate exists. DeepSeek peak turns are priced at 2×.
  • Subagent (child) sessions are discovered from the parent's task tool parts, so their tokens and cost are attributed to the subagent that produced them, recursively.
  • No build step: opencode's Bun runtime transpiles the TSX and injects solid-js / @opentui.

Limitations

  • Costs are estimates and can differ from your provider invoice (tiered >200k context pricing, cache-write pricing, promos, rounding).
  • Peak/off-peak is decided from each turn's start time, so a turn that crosses a boundary is classified by its start.
  • Cache write tokens are not included; most providers bill those separately.
  • Subagent usage refreshes with the history poll (every 30 s), so it can lag the live parent numbers.

Troubleshooting

  • Cost panel is missing — widen the terminal past 120 columns or toggle the sidebar; the panel renders in the sidebar slot.
  • Plugin does not load — make sure tui.json is valid JSON and the name matches the npm package, then restart opencode.
  • Numbers look stale — history refreshes every 30 seconds; the live window updates immediately.

Development

git clone https://github.com/sulaimanh7877/opencode-token-cost-tracker

The plugin entry point is tps-monitor.tsx (exported as ./tui). There is no build step.

License

MIT © Sulaiman