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

@tokentop/agent-pi

v0.2.0

Published

Pi coding agent session and token tracking for tokentop

Readme

@tokentop/agent-pi

Session and token tracking for the Pi coding agent, and for agents built on it.

Built-in plugin for tokentop.

Install

Shipped with tokentop — nothing to install. To pin it yourself:

bun add @tokentop/agent-pi

Pi-based agents

Pi can be rebranded downstream through package.json#piConfig, which changes its config directory and environment variables but not its session format:

export const CONFIG_DIR_NAME = pkg.piConfig?.configDir || '.pi';
export const ENV_AGENT_DIR = `${APP_NAME.toUpperCase()}_CODING_AGENT_DIR`;

So this plugin discovers variants rather than hardcoding ~/.pi. Any agent following Pi's conventions is tracked with no change here:

| Agent | Config dir | Discovered via | |---|---|---| | Pi | ~/.pi/agent | default | | Prime | ~/.prime/agent | directory layout | | any Pi-based agent | ~/.<name>/agent | directory layout or <NAME>_CODING_AGENT_DIR |

Session directories resolve the way Pi resolves them:

<NAME>_CODING_AGENT_SESSION_DIR  >  settings.json#sessionDir  >  <agentDir>/sessions

Both on-disk layouts are read: Pi's per-project nesting (<root>/<encoded-cwd>/<timestamp>_<uuid>.jsonl) and the flat form (<root>/<uuid>.jsonl). Each usage row is tagged with metadata.variant.

What gets counted

Pi attaches usage to more than just assistant messages, and all of it is billed:

| Entry type | Usage | |---|---| | message | assistant turns | | usage | standalone notices, e.g. cache warming | | compaction | the summarisation call itself | | branch_summary | the branch summarisation call | | child_usage_attributed | spawned subagent turns |

child_usage_attributed matters most. Measured against 74 real session files, of which 57 carry any usage: all 2,347 childUsage figures appeared nowhere in the message stream, and account for 24% of all tokens (83.0M of 345.9M) — counting only message entries silently loses a quarter of the usage. Its sibling aggregateUsage field is a running total scoped to the child task, so it is deliberately ignored; summing it double-counts.

Two usage fields are documented subsets and are never added on top of their parents:

  • reasoning is already included in output
  • cacheWrite1h is already included in cacheWrite

Forked sessions

/fork, /clone and branch extraction copy a session's history into a new file verbatim — same entry ids, same token counts. Both files then describe the same usage.

Rows are de-duplicated by entry id plus token counts, with sessions processed oldest-header-first, so the original session keeps the shared history and only the fork's own turns are added to it. Header creation time is used rather than mtime: appending to a parent later must not hand ownership of its own past usage to the fork.

Providers

Pi-based agents often route through a proxy and report its name as the provider — real sessions carry meridian-local, anthropic-litellm, litellm and openai-codex. None of these exist in a pricing table.

Resolution order:

  1. Pi's provider id, when models.dev knows it. Aggregators such as openrouter stop here, since they legitimately key models as vendor/model.
  2. The vendor prefix of a vendor/model id, with the prefix stripped — how proxies pass the real vendor through.
  3. The model id prefix (claude- → anthropic, gpt- → openai, and so on).
  4. Pi's raw provider id, unchanged.

Step 4 is deliberate: an unrecognised provider surfaces as a missing price rather than a confidently wrong one.

Performance

tokentop polls parseSessions on a timer, so the plugin avoids re-reading unchanged files:

  • 2s TTL cache over the full parse result
  • per-file parse cache keyed by path, invalidated by mtime, LRU-capped
  • recursive fs.watch dirty-path tracking, with a 10-minute reconciliation sweep as a backstop
  • append-only offset tracking for real-time activity, so only newly written bytes are parsed

Measured on 74 session files / 57 sessions with usage / 5,630 usage rows: 144ms cold, 1.4ms warm.

API

import piAgentPlugin, { discoverVariants, parseSessionFile } from '@tokentop/agent-pi';

const variants = await discoverVariants();
// [{ name: 'prime', agentDir: '~/.prime/agent', sessionsRoot: '~/.prime/agent/sessions' }]

Credits

The Pi plugin was first contributed by @i3wangyi in tokentopapp/tokentop#109, which prompted making Pi support official. The session discovery and provider-inference approach here started from that work.

License

MIT