Skip to main content

@ccusage/opencode

Analyze OpenCode usage logs with the same reporting experience as ccusage. Track token usage, costs, and sessions for Claude models used in OpenCode.

Quick Start

npx @ccusage/opencode@latest --help

Installation

Since npx @ccusage/opencode@latest is quite long to type repeatedly, set up a shell alias:
alias ccusage-opencode='bunx @ccusage/opencode@latest'
Then simply run:
ccusage-opencode daily
ccusage-opencode monthly --json

Data Source

The CLI looks for OpenCode usage data under:
  • Default: ~/.local/share/opencode/storage/
  • Custom: Set OPENCODE_DATA_DIR environment variable

Storage Structure

OpenCode stores usage data in:
  • Messages: ~/.local/share/opencode/storage/message/{sessionID}/msg_{messageID}.json
  • Sessions: ~/.local/share/opencode/storage/session/{projectHash}/{sessionID}.json
Each message file contains token counts and model information.

Common Commands

Daily Usage Report

View token usage and costs grouped by date:
npx @ccusage/opencode@latest daily

Weekly Usage Report

View usage grouped by ISO week (YYYY-Www):
npx @ccusage/opencode@latest weekly

Monthly Report

View usage aggregated by month (YYYY-MM):
npx @ccusage/opencode@latest monthly

Session Report

Detailed breakdown by conversation sessions:
npx @ccusage/opencode@latest session

JSON Output

Export structured data for scripting:
npx @ccusage/opencode@latest daily --json

Compact Mode

Optimized for screenshots and narrow terminals:
npx @ccusage/opencode@latest daily --compact

Token Fields

OpenCode message files track these token types:
FieldDescriptionUsage
tokens.inputTotal input tokens sent to modelStandard input billing
tokens.outputCompletion tokensOutput billing
tokens.cache.readCached prompt tokensCheaper cached billing
tokens.cache.writeCache creation tokensCache creation cost

Cost Calculation

OpenCode stores cost: 0 in message files by default. This CLI calculates accurate costs from token usage data using the LiteLLM pricing database.
  • All models supported by LiteLLM have accurate pricing
  • Supports cache token pricing (cheaper for cached reads)
  • Automatic model price lookups

Features

Daily Reports

View token usage and costs aggregated by date

Weekly Reports

View usage grouped by ISO week (YYYY-Www)

Monthly Reports

View usage aggregated by month (YYYY-MM)

Session Reports

View usage grouped by conversation sessions

Responsive Tables

Automatic layout adjustment for terminal width

Model Tracking

See which Claude models you’re using (Opus, Sonnet, Haiku, etc.)

Accurate Costs

Uses LiteLLM pricing database for accurate cost calculation

Cache Support

Tracks cache creation and cache read tokens separately

JSON Output

Export data in structured JSON format with —json

Compact Mode

Use —compact flag for narrow terminals, perfect for screenshots

Environment Variables

VariableDescriptionDefault
OPENCODE_DATA_DIROverride OpenCode data directory~/.local/share/opencode
LOG_LEVELControl log verbosity (0 silent … 5 trace)-

Example Output

The CLI provides beautiful terminal tables showing:
  • Date or session information
  • Models used (with bullet points for multiple models)
  • Total tokens (input + output)
  • Cache tokens (read and write)
  • Estimated cost in USD

npm Package

View on npm registry

OpenCode

Official OpenCode repository

ccusage Family

Explore all related tools

Main Documentation

Full ccusage documentation

Build docs developers (and LLMs) love