toktrack

by mag123cVerified

Ultra-fast token & cost tracker for LLM Token Usage (e.g. Claude Code)

184
Stars
19
Forks
Rust
Language
8/23/2026
Added
View on GitHubDownload ZIP

⚠️ Third-Party Software Notice

This skill is third-party open-source software developed and hosted independently on GitHub. SkillTip is an informational directory and does not control or maintain the underlying repository. Any security checks displayed are automated and limited in scope. Review the source code before installing.

Read the Terms of Service

Installation

Add to your Claude Code skills directory:

# Add to your Claude Code skills
git clone https://github.com/mag123c/toktrack

Getting Started

Guides for using skills like toktrack.

Security Report

Verified

Last scanned: —

{
  "status": "PASSED",
  "issues": []
}

README.md

toktrack logo

CI npm License: MIT

English | 한국어

⚠️ Did you know? Claude Code deletes your session data after 30 days by default. Once deleted, your token usage and cost history are gone forever — unless you preserve them.

The token & cost tracker that never loses your history. Most tools re-read your CLI's session files on every run — so when Claude Code deletes them after 30 days, your cost history goes with them. toktrack keeps a persistent cache, so your history survives.

Track usage across all your AI coding CLIs — Claude Code, GitHub Copilot CLI, Codex CLI, Gemini CLI, Qwen Code, OpenCode, PI Agent, and Antigravity — in one dashboard. Built in Rust, so it stays fast even on huge histories (simd-json + rayon).

toktrack overview

Why toktrack?

ProblemSolution
🗑️ Claude Code deletes data after 30 days — your cost history disappears💾 Persistent cache — history survives even after the CLI deletes its files
📊 No unified view — each CLI keeps its own separate data🎯 One dashboard — Claude Code, Copilot, Codex, Gemini, Qwen, OpenCode, PI Agent in one place
🐌 Re-scanning big histories is slowCached queries in ~0.04s — instant on every run

Features

  • Data Preservation — Persistent cache keeps your cost history even after a CLI deletes its own session files
  • Multi-CLI Support — Claude Code, GitHub Copilot CLI, Codex CLI, Gemini CLI, Qwen Code, OpenCode, PI Agent, Antigravity in one place
  • TUI Dashboard — 5 tabs (Overview, Stats, Models, Projects, Audit) with daily/weekly/monthly views
  • Per-Project Breakdown — the Projects tab shows token & cost usage per project (the session working directory), for CLIs that record one. Drill into any project for its day-by-day, per-model breakdown. Usage from CLIs that don't record a project is grouped under (no project). Project details are cached, so they survive past the CLI's 30-day deletion
  • CLI Commandsdaily, weekly, monthly, stats with JSON output support
  • Usage Reports — Shareable text & SVG receipts via toktrack report
  • Fast on huge histories — simd-json + rayon parallel parsing (~3 GiB/s); cached runs in ~0.04s

Installation

npx (Recommended)

No Rust toolchain required. Downloads the correct binary for your platform automatically.

npx toktrack
# or
bunx toktrack

Homebrew (macOS / Linux)

brew tap mag123c/toktrack
brew install toktrack

From Source

cargo install --git https://github.com/mag123c/toktrack

Pre-built Binaries

Download from GitHub Releases.

PlatformArchitecture
macOSx64, ARM64
Linuxx64, ARM64
Windowsx64

Quick Start

# Launch TUI dashboard
npx toktrack

# Get today's cost in JSON
npx toktrack daily --json

# Monthly summary
npx toktrack monthly --json

Usage

TUI Mode (Default)

toktrack

CLI Commands

# Open TUI at specific tab
toktrack daily     # Overview (daily view)
toktrack weekly    # Overview (weekly view)
toktrack monthly   # Overview (monthly view)
toktrack stats     # Stats tab

# JSON output (for scripting)
toktrack daily --json
toktrack weekly --json
toktrack monthly --json
toktrack stats --json

# Usage report (shareable receipt)
toktrack report              # Last 7 days (text)
toktrack report --month      # Last 30 days
toktrack report --days 14    # Last N days
toktrack report --svg        # Text + SVG file

# Data-preservation audit (live on disk vs cache-only)
toktrack audit               # Per-source coverage report
toktrack audit --json        # Machine-readable

Shell Integration

Show today's AI spend right in your prompt, updated after every command:

~/projects/api  main  $12.40
❯

A few lines of zsh/bash/fish — see Shell integration.

Remote Codex Sources

toktrack can include Codex session logs from SSH servers by syncing remote JSONL files into a local snapshot and parsing them with the existing Codex parser. It uses your existing ssh/rsync setup and never stores SSH passwords or keys.

Create ~/.toktrack/config.toml:

default_remotes = ["devbox"]

[[remotes]]
name = "devbox"
target = "ubuntu@devbox"

[remotes.paths]
codex = "~/.codex/sessions"

[[remotes]]
name = "prod"
target = "prod-alias"

[remotes.paths]
codex = "/home/codex/.codex/sessions"

You can also manage the same config from the CLI:

toktrack remote add devbox ubuntu@devbox --default
toktrack remote add prod prod-alias --codex-path /home/codex/.codex/sessions
toktrack remote default add prod
toktrack remote default remove devbox
toktrack remote remove prod
toktrack remote list

By default, commands read local data plus default_remotes:

toktrack report
toktrack daily --json

Override the configured defaults when needed:

toktrack --remote prod report      # local + default_remotes + prod
toktrack --all-remotes stats       # local + every configured remote
toktrack --local-only report       # local only

Remote Codex sources appear as codex@<remote-name> and use separate cache files such as ~/.toktrack/cache/codex@devbox_daily.json. If a remote sync fails, toktrack warns and continues with local data plus any existing snapshot/cache for that remote.

Keyboard Shortcuts

KeyAction
1-5Switch tabs directly (incl. Projects, Audit)
Tab / Shift+TabNext / Previous tab
j / k or / Scroll up / down
EnterOpen model breakdown popup (Daily tab)
d / w / mDaily / Weekly / Monthly view (Daily tab)
s / SSort by date → cost → tokens / Reverse direction (detail views)
rRefresh data
?Toggle help
Ctrl+CQuit

Supported AI CLIs

CLIStatusData Location
Claude Code~/.claude/projects/
GitHub Copilot CLI~/.copilot/session-state/*/events.jsonl
Codex CLI~/.codex/sessions/
Gemini CLI~/.gemini/tmp/*/chats/
Qwen Code~/.qwen/tmp/*/chats/
OpenCode~/.local/share/opencode/storage/message/
PI Agent~/.pi/agent/sessions/
Antigravity~/.gemini/antigravity-{ide,cli}/conversations/*.db

Costs from sources that don't record their own price (Gemini, Qwen, Codex, Antigravity, GitHub Copilot, and modern Claude logs) are computed from LiteLLM API list-price estimates and shown with a ~ marker (estimated). For GitHub Copilot CLI, the displayed value is the API-equivalent cost rather than your actual subscription/credit spend. Pricing works offline via a bundled snapshot when the network is unavailable. 1h ephemeral cache writes are billed at their own higher rate, and Claude Code requests made in fast mode (/fast) are billed at the provider's fast multiplier. A model LiteLLM has no price for shows ? instead of a cost, so a $0 row is never mistaken for free usage.

Environment Variables

Each source's data directory can be overridden (matching the upstream CLI's own variable):

VariableSourceDefault
CLAUDE_CONFIG_DIRClaude Code (root)~/.claude (+ /projects)
COPILOT_HOMEGitHub Copilot CLI~/.copilot (+ /session-state)
CODEX_HOMECodex CLI (root)~/.codex (+ /sessions)
GEMINI_CLI_HOMEGemini CLI (home root)~ (+ /.gemini/tmp)
QWEN_HOMEQwen Code~/.qwen (+ /tmp)
OPENCODE_DATA_DIR / XDG_DATA_HOMEOpenCode~/.local/share/opencode
PI_CODING_AGENT_SESSION_DIR (then PI_AGENT_DIR)PI Agent~/.pi/agent/sessions
export CLAUDE_CONFIG_DIR="/path/to/.claude"

Custom pricing (including web_search / web_fetch per-request rates) can be set in ~/.toktrack/pricing.toml.

Performance

RunTime
First run (cold)~1.0s
Daily use (cached)~0.04s

Measured on Apple Silicon with 2,000+ JSONL files (3.4 GB). The persistent cache means only the current day is recomputed on each run — past days are read straight from cache, so daily use stays instant no matter how large your history grows.

Why it's fast: SIMD JSON parsing (simd-json) + parallel processing (rayon) = ~3 GiB/s throughput on the cold path.

Data Preservation

The Problem: You've been using Claude Code for 3 months, spending hundreds of dollars. One day you want to check your total spending — but Claude Code already deleted your session files from 2 months ago. That cost data is gone forever.

toktrack solves this. It caches daily cost summaries independently, so your usage history survives even after the CLI deletes the original files.

CLI Data Retention Policies (The Hidden Risk)

CLIDefault RetentionPolicy
Claude Code30 dayscleanupPeriodDays (default: 30)
Gemini CLIUnlimitedopt-in sessionRetention
Codex CLIUnlimitedsize-cap only (max_bytes)

toktrack Cache Structure

~/.toktrack/
├── cache/
│   ├── claude-code_daily.json   # Daily cost summaries
│   ├── codex_daily.json
│   ├── codex@devbox_daily.json
│   ├── gemini_daily.json
│   ├── opencode_daily.json
│   └── pi-agent_daily.json
├── remotes/
│   └── devbox/codex/sessions/   # Synced remote Codex JSONL snapshots
├── config.toml                  # Optional remote source configuration
└── pricing.json                 # LiteLLM pricing (1h TTL)

Past dates in each *_daily.json are immutable — once a day is summarized, the cached result is never modified. Only the current day is recomputed on each run. This means even if Claude Code deletes session files after 30 days, your cost history remains intact in the cache.

See Exactly What's Preserved

toktrack audit shows, per source and per day, whether the data is still live (raw session file on disk), cache-only (the CLI deleted the raw file — only toktrack still has it), or missing (no data — an unused day, or one lost before toktrack first saw it; never claimed as a loss).

$ toktrack audit

Data preservation audit (2026-06-08)

  claude-code   2025-12-22 → 2026-06-08
    live (raw on disk):         79 days
    preserved (CLI deleted):    83 days
    no data (unused or lost):    7 days
  ...

  ► 100 days of cost history preserved that your CLIs already deleted.

Use toktrack audit --json for the full per-day breakdown, or open the Audit tab in the TUI (press 4) for a visual coverage map.

Disable Claude Code Auto-Deletion

// ~/.claude/settings.json
{
  "cleanupPeriodDays": 9999999999
}

Reset Cache

rm -rf ~/.toktrack/cache/

The next run will rebuild the cache from available session data.

How It Works

architecture

Cold path (first run): Full glob scan → parallel SIMD parsing → build cache → aggregate.

Warm path (cached): Load cached summaries → parse only recent files (yesterday midnight mtime filter) → merge → aggregate.

Deep Dive: I Rewrote a Node.js CLI in Rust — It Went from 43s to 1s | 한국어

Development

make check    # fmt + clippy + test (pre-commit)
cargo test    # Run tests
cargo bench   # Benchmarks

Roadmap

Now tracking 8 CLIs (Claude Code, Copilot, Codex, Gemini, Qwen Code, OpenCode, PI Agent, Antigravity) — see Supported AI CLIs. Planned: live/burn-rate monitoring, MCP server / statusline, more CLIs (Goose, Amp, Kimi).

Contributing

Issues and PRs welcome!

make check  # Run before PR

Star History

Star History Chart

License

MIT

Frequently Asked Questions

What is toktrack?

toktrack is an open-source cli tools skill for AI coding assistants such as Claude Code, Codex CLI, and ChatGPT, built by mag123c. Ultra-fast token & cost tracker for LLM Token Usage (e.g. Claude Code). It has 184 GitHub stars.

Is toktrack safe to use?

Yes. toktrack passed SkillsLLM's automated security scan — a dependency vulnerability audit plus prompt-injection heuristics — with no high-severity issues. You can read the full report in the Security Report section on this page.

How do I install toktrack?

Clone the repository with "git clone https://github.com/mag123c/toktrack" and add it to your Claude Code skills directory (see the Installation section above).

What programming language is toktrack written in?

toktrack is primarily written in Rust. It is open-source under mag123c on GitHub, so you can review or fork the full source.

Are there alternatives to toktrack?

Yes. SkillsLLM lists many other CLI Tools skills you can browse and compare side by side. Open the CLI Tools category from the badge at the top of this page, or use the Related Skills and comparison links further down to weigh toktrack against similar tools.

Comments (0)

No comments yet. Be the first to share your thoughts!

ui-ux-pro-max-skill

by nextlevelbuilder

12

An AI skill that provides design intelligence for building professional UI/UX across multiple platforms.

119,92012,870Python
CLI Toolsai-skillsantigravity
View details

happy

by slopus

Mobile and Web client for Codex and Claude Code, with realtime voice, encryption and fully featured

23,4501,980TypeScript
CLI Tools
View details

claudecodeui

by siteboon

Use Claude Code, OpenCode, Cursor CLI, and Codex on mobile and web with CloudCLI (aka Claude Code UI). CloudCLI is a free open source webui/GUI that helps you manage your Claude Code session and projects remotely.

13,3941,866TypeScript
CLI Tools
View details

CRS-自建Claude Code镜像,一站式开源中转服务,让 Claude、OpenAI、Gemini、Droid 订阅统一接入,支持拼车共享,更高效分摊成本,原生工具无缝使用。

12,5471,869JavaScript
CLI Tools
View details

ccstatusline

by sirmalloc

🚀 Beautiful highly customizable statusline for Claude Code CLI with powerline support, themes, and more.

12,508545TypeScript
CLI Tools
View details

Developers Also Liked

Based on votes and bookmarks from developers who liked this skill

ECC

by affaan-m

10

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

242,21936,702JavaScript
AI Agentsai-agentsanthropicclaude-code
View details
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI Agentsai-agentsbrainstorming
View details

n8n

by n8n-io

12

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

201,88160,308TypeScript
MCP Serversapisai-tools
View details

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

185,94028,768JavaScript
AI Agentsai-agentsanthropicclaude-code
View details

cc-switch

by farion1231

3

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

128,8688,826Rust
AI Agentsclaude-codeai-tools
View details