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-tokenwise

v1.0.0

Published

Token analytics plugin for OpenCode

Readme

opencode-tokenwise

Plugin de analytics de tokens para OpenCode. Captura uso de tokens em tempo real, exibe dashboard web local e oferece CLI para consultas rápidas.

Funcionalidades

  • 📊 Captura automática — Hooks no chat.params, session.created, message.updated, session.idle
  • 💾 Storage local — SQLite em ~/.config/opencode/tokenwise.db (zero dependências externas)
  • 🌐 Dashboard web — SPA em http://localhost:7842/dashboard com gráficos (Chart.js)
  • 🖥️ CLI standaloneopencode-analytics stats|today|models|dashboard|export
  • 🤖 Custom tools — Agente pode consultar token_stats e token_today
  • ⚠️ Alertas de custo — Configurável via TOKENWISE_ALERT_USD
  • 💰 Pricing embutido — Tabela de preços por modelo com override via arquivo JSON

Instalação

npm install -g opencode-tokenwise

Adicione ao ~/.config/opencode/opencode.json:

{
  "plugin": ["opencode-tokenwise"]
}

Reinicie o OpenCode.

Configuração (variáveis de ambiente)

| Variável | Padrão | Descrição | |----------|--------|-----------| | TOKENWISE_PORT | 7842 | Porta do dashboard | | TOKENWISE_HOST | 127.0.0.1 | Host do servidor (nunca 0.0.0.0 por segurança) | | TOKENWISE_DB_PATH | ~/.config/opencode/tokenwise.db | Caminho do SQLite | | TOKENWISE_ALERT_USD | 0 | Limite de alerta de custo por mensagem (0 = desabilitado) | | TOKENWISE_PRICING_PATH | — | Caminho para JSON customizado de pricing |

Uso

Dashboard

opencode-analytics dashboard
# ou acesse http://localhost:7842/dashboard

CLI

# Resumo últimos 7 dias
opencode-analytics stats

# Resumo últimos 30 dias
opencode-analytics stats -d 30

# Consumo de hoje
opencode-analytics today

# Breakdown por modelo
opencode-analytics models

# Exportar JSON
opencode-analytics export -f json -o analytics.json

# Exportar CSV
opencode-analytics export -f csv -o analytics.csv

Custom Tools (agente)

O agente do OpenCode pode usar:

"Quanto gastei hoje?" → usa token_today
"Stats dos últimos 30 dias" → usa token_stats com days: 30

Estrutura do Banco

sessions (
  id, project, model, input_tokens, output_tokens,
  cache_read_tokens, cache_write_tokens, estimated_cost_usd,
  created_at, updated_at, tags
)

daily_summary (
  date, total_input, total_output, total_cost_usd, session_count
)

Migrações automáticas via tabela _meta.

Pricing Override

Crie pricing.json:

{
  "meu-modelo-custom": { "input": 2.50, "output": 10.00 }
}
export TOKENWISE_PRICING_PATH=/caminho/pricing.json

Desenvolvimento

# Instalar deps
bun install

# Testes
bun test

# Build plugin
bun run build

# Build CLI
bun run build:cli

# Dev mode (watch)
bun run dev

Segurança

  • Dashboard bind apenas em 127.0.0.1 (localhost)
  • Para acesso remoto, use SSH tunneling:
    ssh -L 7842:localhost:7842 user@servidor

Licença

MIT