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

@agenttool/codex-usage

v0.1.0

Published

Privacy-minimal live local Codex token usage inspection for agents and operators

Readme

AgentTool Codex Usage

@agenttool/codex-usage is a local, read-only token pulse for Codex sessions. It reads Codex's numeric threads.tokens_used counters from the current local SQLite state on every sample. For the small set of returned sessions, it can also scan a bounded tail of each Codex rollout and extract only validated event_msg / token_count numbers.

It does not build a transcript index. It does not return prompts, replies, reasoning, tool output, titles, previews, working directories, rollout paths, Git metadata, model names, free-form agent labels, credentials, account identity, or raw Codex thread IDs. It makes no network call and performs no write to Codex state. Its hashed references are stable local correlation hints, not identity, authentication, ownership, permission, health, competence, consciousness, or consent.

Use

The public package installs local tooling only. It does not register an MCP server, start a background process, or expose a hosted usage surface. A package manager may contact its configured registry during installation; after install, the tracker runtime itself makes no network calls. Bun 1.3.5 or newer is required, and the stable install is pinned here so the selected bytes are explicit:

bun add --global @agenttool/[email protected]
agenttool-codex-usage
agenttool-codex-usage watch
agenttool-codex-usage mcp

From a source checkout:

bun install --frozen-lockfile
bun bin/agenttool-codex-usage.ts
bun bin/agenttool-codex-usage.ts self
bun bin/agenttool-codex-usage.ts watch
bun bin/agenttool-codex-usage.ts snapshot --breakdown
bun bin/agenttool-codex-usage.ts snapshot --json
bun bin/agenttool-codex-usage.ts doctor
bun bin/agenttool-codex-usage.ts mcp

watch samples once a second by default. An MCP client can call:

  • codex_usage_snapshot — fleet totals and recently updated sessions;
  • codex_usage_sessions — privacy-filtered session records;
  • codex_usage_session — one hashed session reference;
  • codex_usage_self — the thread matching inherited CODEX_THREAD_ID;
  • codex_usage_doctor — database/schema/boundary health only.

Numeric breakdown tails are opt-in (--breakdown or include_breakdown: true). Default snapshot, watch, and MCP calls read only SQLite, avoiding recurring rollout-file I/O.

Every MCP tool publishes strict input and output schemas. Snapshot deltas are kept only in the MCP process, keyed by the exact polling scope, and limited to 32 recent scopes. A counter decrease or Codex state-generation change returns an explicit uncomparable reset instead of a fabricated zero delta.

“Recently active” means the local Codex thread row was updated inside a caller- selected time window. It does not prove that a model, agent, app-server, or OS process is currently running. Poll-on-read reflects the latest committed state visible to the reader; it is not push delivery or a zero-latency guarantee.

The cumulative counters are Codex's observed processing totals. They are not API invoices, ChatGPT credits, prices, account usage, remaining quota, or a remaining-context guarantee. Cached input is shown as a subset supplied by Codex and is not subtracted from the cumulative total.

Source resolution

The reader uses, in order:

  1. AGENTOOL_CODEX_USAGE_DB — exact explicit SQLite file;
  2. the highest state_<version>.sqlite under CODEX_SQLITE_HOME;
  3. the highest state_<version>.sqlite under CODEX_HOME or ~/.codex.

Rollout token-event reads are constrained to sessions/ and archived_sessions/ beneath CODEX_HOME. Override rollout roots only through the TypeScript API for hermetic tests. If Codex changes its internal SQLite or rollout schema, doctor fails explicitly instead of guessing.

Verify

bun run ci

The tests create disposable SQLite/JSONL fixtures with privacy canaries, prove that live committed counters are re-read, reject fake token_count text inside ordinary transcript records, and exercise all MCP tool annotations.