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

llm-usage-extraction

v0.3.1

Published

Read token usage from the local session logs of Claude Code, Claude Cowork, Codex and Cursor

Readme

llm-usage-extraction

Reads token usage from the session logs that AI coding agents write on your machine, and optionally from Cursor's usage dashboard. Shared by tokenmaxxing and agentgate. Bun only.

| Source | Where it reads | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | claude_code | ~/.claude/projects/**/*.jsonl (CLAUDE_CONFIG_DIR) and PostHog Desktop's <posthog>/claude/projects | | claude_cowork | Claude Desktop's local agent sessions (CLAUDE_COWORK_DIR) | | codex | ~/.codex/sessions/ and archived_sessions/ (CODEX_HOME), the rollouts listed in state_*.sqlite (CODEX_SQLITE_HOME), and PostHog Desktop's <posthog>/codex-home/*/sessions | | cursor_local | Cursor's state.vscdb (CURSOR_DATA_DIR) and agent transcripts (CURSOR_PROJECTS_DIR) | | cursor_api | Cursor's usage dashboard, signed in with the token in state.vscdb. Opt-in | | grok_bot | Grok Bot's rows on that same dashboard. Opt-in |

App data lives in ~/Library/Application Support on macOS, %APPDATA% on Windows and $XDG_CONFIG_HOME (or ~/.config) on Linux. <posthog> is @posthog/posthog-code there, or POSTHOG_DESKTOP_DIR.

cursor_api is the same Cursor usage as cursor_local, as Cursor counted and charged it, with costCents. Enable one of the two, never both, or Cursor is counted twice. The dashboard sources send the user's Cursor login to cursor.com, so SOURCES leaves them out: enable them by name. collect asks the dashboard at most every 15 minutes and re-reads the last 7 days, because Cursor can publish a request's usage after it finished. The checkpoint moves only once the whole window is read. Besides the user's own usage, it reads each Cursor team the user belongs to and keeps only the rows that user owns, because usage billed to a team (Grok Bot's, for example) is missing from the personal read. A row both reads return counts once.

Each model turn becomes a TokenEvent: input, output, cache read, cache write and reasoning tokens, with session, message id, model and timestamp. Message content is never read into an event.

Install

bun add llm-usage-extraction

Use

collect reads every enabled source from where the last read stopped and yields batches. Commit a batch's state only after you have stored its events, so a failure re-reads them next time.

import { collect, type ExtractState } from "llm-usage-extraction";

let state: ExtractState = { files: {} };
for await (const batch of collect(state, { enabled: new Set(["claude_code", "codex"]) })) {
  await store(batch.events);
  state = batch.commit(state);
}

Persist state between runs to read only new lines. dirs reads only the given folders for a source instead of its default locations, for example { claude_code: [ownDir, otherDir] }. seen replaces the set of message keys used to drop repeats within a run; a long-running process reading GBs of logs can pass a smaller one, such as { has: (k) => hashes.has(Bun.hash(k)), add: (k) => hashes.add(Bun.hash(k)) }.

The parsers (parseClaudeCodeFile, parseCodexFile, parseCursorTranscriptFile, parseCursorLocal, and fetchCursorUsagePages for the dashboard) and the file listers (listClaudeCodeFiles(dir?) and friends) are exported for callers that walk other directories. A lister given a dir reads only that folder; with none it reads every default location.

What it handles

  • Claude Code writes one line per content block with the same message id, and only the last has the final output_tokens. Each message counts once, with the last line's numbers. A message split across two reads arrives twice with the same ids; keep the larger numbers.
  • Codex's input_tokens includes cached tokens; events report them separately. Replayed token_count lines and the parent history copied into forked or subagent rollouts are not counted again.
  • Session logs of several GB are read in bounded windows, and a partly written last line is left for the next read.