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

@alexanderfortin/pi-token-usage

v0.1.1

Published

Pi coding agent extension for analyzing token usage and cost across session files

Readme

pi-token-usage

A Pi coding agent extension that analyzes token usage and cost across your session files.

Installation

# NPM (recommended)
pi install npm:@alexanderfortin/pi-token-usage

# Git
pi install git:github.com/shaftoe/pi-token-usage

# Or quick-test without installing
pi -e ./pi-token-usage/src/index.ts

Usage

/token-report                                  Report all sessions (table in TUI)
/token-report 7                                Last 7 days
/token-report /path/to/dir                     Specific directory or file
/token-report --format csv                     CSV to stdout
/token-report --format csv --save report.csv   Save CSV to file
/token-report 7 --format json                  JSON to stdout
/token-report --format md                      Markdown to stdout
/token-report --format markdown --save out.md  Save Markdown to file
/token-report --format=csv --save=out.csv      Equals-sign syntax also works

Arguments

| Argument | Description | |----------|-------------| | [days] | Number — show sessions from the last N days | | [path] | Path to a .jsonl file or directory (default: ~/.pi/agent/sessions) | | --format, -f | Output format: table (default), csv, json, markdown (alias: md) | | --save, -s | Write output to file instead of stdout/TUI |

Output Formats

Table (default) — interactive TUI overlay with styled columns.

CSV — machine-readable spreadsheet format. Includes metadata as # comment lines.

Model,Provider,Turns,Input Tokens,Output Tokens,...
claude-sonnet-4-20250514,anthropic,10,50000,12000,...
TOTAL,,15,70000,20000,...

JSON — structured output with meta, models, and totals sections. Pipe to jq for queries.

Markdown — pipe-delimited table for notes, PRs, or documentation.

Development

cd pi-token-usage
bun install           # Install dependencies
bun run check         # Type-check with tsc
bun run lint          # Lint with eslint
bun run format:check  # Verify formatting
bun run format        # Auto-format with Prettier
bun test              # Run tests
bun test:coverage     # Run tests and show coverage stats

How It Works

  1. Scans ~/.pi/agent/sessions (or given path) for .jsonl session files
  2. Parses each file, extracting assistant messages with usage data
  3. Aggregates token counts and costs per model+provider
  4. Renders in the requested format

Releasing

This project uses automated publishing to NPM via GitHub Actions. The workflow will:

  • Run all CI checks
  • Build the package
  • Publish to NPM with provenance (signed) via trusted publishing

License

See LICENSE