← Catalog

@hanmo5888/toktaken

Report token usage from Claude Code, Codex, Pi, and OpenCode to TokTaken.

Package

Install

Install with PiG

pig install npm:@hanmo5888/toktaken

Install with Pi

pi install npm:@hanmo5888/toktaken
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./pi-extension.mjs"
  ]
}

README

Written by the package's publisher, shown as published in version 0.1.0 (README.md). PiG does not review it.

TokTaken reporters

One npm package contains the reporters for Claude Code, Codex, Pi, and OpenCode. It requires Node.js 22.13 or later and has no package dependencies. Install it once on each machine:

npm install -g @hanmo5888/toktaken
TOKTAKEN_PLUGIN_DIR="$(npm root -g)/@hanmo5888/toktaken"

Create a reporting key in My dashboard → Reporting keys on your TokTaken site, then set:

export TOKTAKEN_URL='https://usage.example.com'
export TOKTAKEN_API_KEY='tt_…'

TOKTAKEN_URL is the site URL, without /api/v1. Loopback HTTP works for local development. Export these two variables where all your harness processes will inherit them (for GUI apps, use the launcher's environment). Configure one key per machine; multiple harnesses on the machine share that key.

Enable the harnesses you use. In config files, replace /path/to/toktaken with the value of TOKTAKEN_PLUGIN_DIR.

HarnessSetupWhen it reports
Claude CodeStart claude --plugin-dir "$TOKTAKEN_PLUGIN_DIR".When a turn or subagent stops.
CodexMerge codex/hooks.example.json from the package into ~/.codex/hooks.json (or the hooks file under your custom Codex home). Approve the hook in /hooks. If Codex cannot find toktaken on its PATH, use node "/path/to/toktaken/cli.mjs" hook codex as the hook command.When a turn stops. The existing notify setting is independent.
PiAdd /path/to/toktaken/pi-extension.mjs to extensions in ~/.pi/agent/settings.json, or start with pi -e "$TOKTAKEN_PLUGIN_DIR/pi-extension.mjs".After an assistant turn.
OpenCodeAdd file:///path/to/toktaken/opencode-plugin.mjs to plugin in ~/.config/opencode/opencode.json.On completed assistant messages.

If you only use Pi or OpenCode, you can let the harness install the same npm package instead: run pi install npm:@hanmo5888/toktaken, or add "@hanmo5888/toktaken" to OpenCode's plugin array. Use one loading method per harness.

When running from a source checkout, set TOKTAKEN_PLUGIN_DIR to its packages/reporter directory and use node "$TOKTAKEN_PLUGIN_DIR/cli.mjs" in place of the installed toktaken command.

Configurations were developed against Claude Code 2.1, Codex 0.169, Pi 1.3, and OpenCode 1.19. Restart the harnesses after configuring them. Make a model call, then check My dashboard for the harness and model totals.

Retry or import selected history

Pending batches stay under ${XDG_STATE_HOME:-~/.local/state}/toktaken and are retried on the next reporting activity. Run this to send them immediately:

toktaken flush

To import an existing transcript or OpenCode database, select the file explicitly:

toktaken sync codex /path/to/rollout.jsonl
toktaken sync claudecode /path/to/transcript.jsonl
toktaken sync pi /path/to/session.jsonl
toktaken sync opencode /path/to/opencode.db

The reporters send only model usage metadata, never prompts, responses, or local paths. Transcript hooks read new records in the active session and checkpoint after queuing. The queue is bound to the server and key to keep accounts separate. If you have pending events, flush them before revoking a key; selected history can also be reimported with a replacement key. Invalid batches stay on disk with a .rejected suffix so they don't block later reports.