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

@lmoesle/token-usage-cli

v0.7.0

Published

CLI for tracking AI agent token usage

Readme

token-usage

token-usage is a TypeScript CLI for tracking and visualizing AI agent token usage.

This setup provides:

  • A Commander-based CLI entrypoint (token-usage).
  • Token usage aggregation by date, agent, and model.
  • Cost calculation from configured model token prices.
  • Opencode usage extraction from the local SQLite database.
  • Vibe usage extraction from local session metadata.
  • Codex usage extraction from local session transcripts and archived sessions.
  • Junie usage extraction from local session event streams.
  • Table output and raw JSON output.
  • TypeScript build with webpack.
  • npm scripts for build/lint/test.
  • GitHub Actions workflow for CI.

The CLI reads Opencode usage from ~/.local/share/opencode/opencode.db, Vibe usage from ~/.vibe/logs/session, Codex usage from ~/.codex/sessions plus ~/.codex/archived_sessions, and Junie usage from ~/.junie/sessions by default. An agent adapter is activated only when its usage location exists.

npx @lmoesle/token-usage-cli today
npx @lmoesle/token-usage-cli daily
npx @lmoesle/token-usage-cli weekly
npx @lmoesle/token-usage-cli monthly
npx @lmoesle/token-usage-cli yearly

today shows only today's usage. daily, weekly, monthly, and yearly load the complete usage history and group it by the selected period.

The table groups usage by Period, Agent, and Model. Daily periods use YYYY-MM-DD, weekly periods use ISO calendar weeks (YYYY-Www), monthly periods use YYYY-MM, and yearly periods use YYYY. Each row shows input, output, cached, total tokens, and cost.

The CLI calculates costs from the model token prices in src/adapter/out/tokenPrices.json. Prices are configured in USD per 1 million tokens and split into input, cached, and output prices. The config covers OpenCode Zen plus common OpenCode providers like OpenAI, Anthropic, Google, and Mistral. Models without a configured price use 0 cost.

Use --raw to print the token usage report as JSON:

npx @lmoesle/token-usage-cli monthly --raw

Custom Opencode Database

Use --opencode-db to read another SQLite database, for example the sample database in this repository:

npx @lmoesle/token-usage-cli daily --opencode-db sample-data/opencode.db

Custom Vibe Sessions Directory

Use --vibe-session-dir to read Vibe session metadata from another directory:

npx @lmoesle/token-usage-cli daily --vibe-session-dir ~/.vibe/logs/session

Custom Codex Home Directory

Use --codex-home to read Codex transcripts from another Codex home directory:

npx @lmoesle/token-usage-cli daily --codex-home ~/.codex

Custom Junie Sessions Directory

Use --junie-sessions-dir to read Junie usage from another sessions directory. Junie records token usage (including cost) in each session's events.jsonl, so Junie costs come directly from Junie instead of src/adapter/out/tokenPrices.json:

npx @lmoesle/token-usage-cli daily --junie-sessions-dir ~/.junie/sessions

Setup

Use a Node.js runtime with node:sqlite support.

npm install

Build

npm run build

The bundled CLI is emitted to dist/index.js.

Run

npm start -- today

Development

  • npm run lint – lint source and test files.
  • npm test – run unit tests.