Repository navigation
Releases
Releases · ramtinJ95/opencode-tokenscope
v2.1.0
Adds a native token usage panel on OpenCode V2. OpenCode V1 is unaffected.
Added
- On OpenCode V2,
/tokenscopeopens a token usage panel beside the session. The panel reads the analysis from the plugin over RPC, so it makes no model request and adds nothing to the session, and it reloads when the session finishes a turn. It is also in the command palette as "Token usage report". - The panel's context window split is scaled to the context OpenCode recorded for the last request, so its rows add up to the provider's count. Local tokenization only supplies the proportions.
- Added bundled pricing for
gpt-6.1-terrafrom models.dev.
Changed
- On OpenCode V2, the command that has the model print the text report is now
/tokenscope-report./tokenscopeon OpenCode V1 is unchanged.
v2.0.0
Adds OpenCode V2 support. OpenCode V1 keeps working without any change on the user's side: the V1 implementation is unchanged from 1.8.1 and stays in the package for a transition period.
Added
- Added OpenCode V2 support through the V2 plugin API (
@opencode/plugin). The V2 implementation lives inplugin/v2/, produces the same report layers as 1.8.x, and registers both thetokenscopetool (as a directly callable tool) and the/tokenscopecommand, so V2 needs no command file. - Added package routing for both OpenCode majors:
mainstill points at the V1 module, which every OpenCode V1 release and a V1 script install load, and the newexportsentry points at the V2 module, which OpenCode V2 resolves. Neither host loads the other's implementation or plugin SDK. - On V2, the system category, context breakdown, and tool-definition sizes are measured from the system prompt and tool definitions of the session's latest model request, captured with a session
contexthook and split by instruction source. Labeled estimates remain as the fallback for sessions with no request since OpenCode started. - On V2, the context breakdown has a "Catalogs & Guidance" row for the skill, MCP, reference, and Code Mode catalogs.
- On V2, recorded usage is read from assistant messages and compaction requests, and reconciled against the session aggregate. Because V2 exposes only the active context (the last compaction onward) to plugins, a compacted session gets a warning that names both totals instead of a generic mismatch.
- On V2, live pricing with all context tiers comes from the model catalog, child sessions from the session list, and the skill and subagent catalogs from the skill and agent APIs, filtered with the permission rules of the current agent and session.
- On V2, feature flags can be set as plugin
optionsinopencode.json(c); they take precedence over~/.config/opencode/tokenscope-config.json. - On V2, user-invoked skills and
!shellcommands are counted alongside replayable tool output. install.shdetects OpenCode V2 and installs throughopencode plugin add(oropencode plugin updatewith--update), then lists leftover files from a V1 script install. The V1 flow is unchanged.
Changed
@opencode/plugin ^2.0.0is an optional peer dependency.@opencode-ai/plugin >=1.1.48remains a peer dependency for OpenCode V1.
v1.8.1
Added
- Added a generated report preview near the top of the README and a linked report reference covering section semantics, exclusions, fallbacks, and reconstruction limits.
Changed
- Reorganized the root and packaged READMEs around installation, report interpretation, current capabilities, configuration, pricing and tokenizer coverage, troubleshooting, privacy, and development.
- Clarified legacy assistant-message telemetry fallback, config loading behavior, private-report write failures, OpenCode and Hugging Face network access, and npm package resolver semantics.
v1.8.0
Added
- Added OpenCode-compatible arbitrary and multiple context-price tiers, selected independently for every completed provider step before the legacy 200K fallback.
- Added reconciliation between message-derived
step-finishtelemetry and OpenCode's session aggregate, with visible warnings when token buckets or recorded cost disagree. - Added explicit snapshot-boundary, retained-content, active-revert, missing-metadata, and approximate-tokenizer warnings so incomplete data cannot look exact.
- Added adaptive precision for small USD values and per-million rates, preserving values such as
$0.00001234and$0.00875/Min displayed formulas. - Added dedicated regression coverage for session reconciliation, current OpenCode skill formatting, tokenizer fallbacks, multi-tier pricing, report isolation, and cyclic child-session graphs.
Changed
- Reframed reports into three distinct layers: locally tokenized retained content, recoverable OpenCode-recorded usage, and visibly labeled explanatory estimates.
- Renamed API-call totals to completed provider steps and documented that the step invoking TokenScope, later report reads, and the final response are outside the snapshot.
- Updated pricing estimates to use live OpenCode provider metadata first, with the bundled models.dev-derived catalog retained only as a warned fallback.
- Updated skill accounting for OpenCode v1.17.18: the verbose permission-filtered catalog belongs to system context, while the static skill-tool description is counted separately from its schema.
- Changed repeated skill accounting to tokenize and sum each persisted result instead of multiplying the first result size by the call count.
- Changed zero-cost and mixed-cost reporting to distinguish OpenCode-recorded cost from public API-rate estimates without assuming a subscription or provider invoice.
- Changed report output to unique, atomically written files in private per-invocation directories under OpenCode's temporary path, leaving analyzed worktrees untouched.
- Changed updater behavior to reinstall declared dependencies before rebuilding, preventing stale plugin SDK and tokenizer packages from surviving an update.
- Documented the v1.17.18 accuracy target and the remaining limits around generated system prompts, provider-transformed tools, compaction, reverts, and bundled-pricing freshness.
Fixed
- Fixed sub-200K and multi-tier cost estimates, strict threshold selection, tier-before-legacy-fallback precedence, per-step tiering, and zero-valued omitted tier cache rates to match OpenCode.
- Fixed cost formulas and labels so reasoning uses the output rate, fresh/cache-read/cache-write buckets remain non-overlapping, and displayed rates agree with the calculated totals.
- Removed invalid system-prompt remainder inference that could double-count assistant history and removed the nonexistent fixed project-tree estimate.
- Bounded heuristic context components so they cannot exceed the observed first cache-write bucket, which is now labeled as an allocation anchor rather than a context-window measurement.
- Fixed OpenCode-hosted Claude and other non-OpenAI models being tokenized as OpenAI, mapped newer GPT/o-series models to the GPT-4o tokenizer family, and preserved real model names when tokenization is approximate.
- Fixed silent tokenizer fallbacks by reporting unknown encodings, load failures, and encode failures before using an approximate count.
- Fixed retained-content handling for
ignored:truetext, completed compacted tools, and replayable errored or interrupted tool results. - Fixed tool-schema reporting that implied current metadata was the exact historical enabled toolset; active-agent permissions, MCP additions, and provider transforms are now called out explicitly.
- Fixed skill-catalog reconstruction that double-attributed an obsolete catalog-bearing tool description and made unavailable skill/agent metadata visible.
- Fixed recursive subagent attribution by preferring the session's agent field and stopping duplicate or cyclic traversal.
- Fixed unsafe pricing-prefix matches that could assign a related model's price without a valid model-version boundary.
- Fixed concurrent report overwrites, repository pollution, shell-path handling, and stale fixed-filename instructions.
Security
- Restricted report directories to owner-only permissions and report files to mode
0600on Unix. - Added ownership, symlink, and writable-parent validation before writing potentially sensitive session reports under OpenCode's allowed temporary path.
v1.7.2
v1.7.1
Added
- Added an opt-in
enableDetailedSubagentCostBreakdownconfig flag that expands subagent report sections with fresh input, cache read, cache write, output, and reasoning token buckets plus estimated per-bucket costs.
Fixed
- Fixed the default context export runner so npm-installed plugins no longer require Bun to analyze exported session data.
- Fixed subagent cost reporting to show recorded child-session API costs when available, including mixed main-session subscription and child-session API-cost cases.
- Fixed subagent estimated cost splits to clearly distinguish API-rate estimates from recorded API costs.
- Fixed live metadata fallback merging for provider-qualified and bare model aliases when provider metadata is partial.
v1.7.0
Added
- Added live OpenCode provider/model metadata lookup for pricing, with bundled
models.jsonretained as a fallback. - Added support for current OpenCode nested cache pricing and large-context pricing metadata (
cost.cache,cost.tiers, andexperimentalOver200K). - Added directory-routed OpenCode client calls for session messages, child sessions, tool metadata, and provider metadata so TokenScope analyzes the correct project context.
Changed
- Reworked cost estimation to price each API call by its own context tier instead of applying large-context rates to aggregated session totals.
- Improved cache-efficiency cost math by recalculating uncached costs per call and per tier.
- Updated cost report wording to distinguish OpenCode-recorded actual cost from TokenScope API-equivalent estimates.
- Raised the supported OpenCode plugin peer range to
@opencode-ai/plugin >=1.1.48.
Fixed
- Fixed context exports to run from the active session directory.
- Fixed script-installed plugins by including all split library files, installing build dependencies, and building
dist/during install/update. - Fixed report summary paths to print a safely shell-quoted full report path.
- Fixed live pricing alias handling for provider model keys, API model IDs, ambiguous bare aliases, incomplete metadata, cache rates, and non-200K context thresholds.
- Fixed subagent cost estimates to use the same per-call context-tier pricing as main sessions.
Validation
cd plugin && npm test→ 50 passing tests.- Smoke-tested script install/update and real OpenCode sessions before release.
v1.6.5
Changed
- Aligned TokenScope's OpenCode SDK calls with current session, child-session, and experimental tool endpoint request shapes.
- Improved context breakdown and tool schema accounting by using current OpenCode tool metadata, workspace-routed tool definitions, generated prompt detection, and cache-write model selection.
- Updated skill and subagent analysis for current OpenCode skill metadata, optional skill descriptions, and directory-scoped tool definitions.
Fixed
- Avoided treating user-supplied system overrides as generated OpenCode context unless they match stronger generated-context markers.
- Stopped using current OpenCode
info.toolspermission overrides to hide model-visible tool definitions.
v1.6.4
Added
- Added DeepSeek V4 Flash and DeepSeek V4 Pro pricing entries.
- Added a compiled
dist/ESM smoke test to catch strict loader regressions.
Fixed
- Added explicit
.jsextensions to compiled ESM imports so TokenScope loads in strict ESM environments such as OpenCode Desktop (#30).
Published to npm as @ramtinj95/opencode-tokenscope@1.6.4.
v1.6.3
Added
- Added Bun regression tests covering
sessionIDfallback behavior and bundled asset resolution for TokenScope
Changed
- Hardened the suggested
/tokenscopeslash-command prompt to keepsessionIDunset unless the user explicitly asked to analyze a different session
Fixed
- Normalized blank
sessionIDtool arguments so OpenCode models that emitsessionID=""still fall back to the current session instead of failing with "No session ID available for token analysis" - Fixed bundled asset lookup so built/npm TokenScope installs loaded from
dist/still resolvemodels.jsonandtokenscope-config.jsonfrom the published package root instead of silently falling back to default pricing
Closes #21