Skip to main content

Live terminal TUI tracking Claude Code token usage and cost estimates

Project description

claude-tokens

Live terminal TUI tracking Claude Code token consumption — session and weekly windows, cost estimates, progress bars, calibration wizard, and color picker. Cross-platform: Mac, Linux, Windows.

  ~ estimates only · Anthropic usage API is private
╭──────────────────────────────────────────╮
│   Tue 2026-05-20  14:32:01 Claude Tokens │
│                                          │
│   Session  resets in 2h 14m             │
│   ████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░  │
│   2.72M / 7.63M  (36%)                  │
│   4.91M remaining                        │
│   42 msgs  ≈ $1.23                       │
│                                          │
│   Week  resets Tue 05/26 12:00           │
│   ████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░  │
│   6.78M / 26.23M  (26%)                 │
│   19.45M remaining                       │
│   187 msgs  ≈ $5.67                      │
│                                          │
╰──────────────────────────────────────────╯
  refresh 15s · q quit · r refresh · c calibrate · t colors

Install

Mac — Homebrew

brew tap Bernardo-Andreatta/tap
brew install claude-tokens

Windows — Scoop

scoop bucket add bernardo https://github.com/Bernardo-Andreatta/scoop-bucket
scoop install claude-tokens

Requires Scoop and Python installed (scoop install python).

Linux — pipx

pipx install git+https://github.com/Bernardo-Andreatta/terminal-claude-token-usage.git

pipx isolates the install and ensures claude-tokens lands in your PATH automatically. Install pipx: sudo apt install pipx · sudo pacman -S python-pipx · pip install pipx

Any platform — from source

git clone https://github.com/Bernardo-Andreatta/terminal-claude-token-usage.git
cd terminal-claude-token-usage
pipx install .

Usage

claude-tokens            # interactive TUI
claude-tokens-calibrate  # standalone calibration wizard
claude-tokens-colors     # standalone color picker
python -m claude_tokens  # same as claude-tokens, via module

Keys: q quit · r force refresh · c calibrate limits · t pick colors

Configuration

Settings are saved to ~/.claude/claude-tokens.conf — the calibration wizard and color picker both offer to save there automatically. No shell editing required.

You can also set any value as an env var (env vars override the config file):

# ~/.claude/claude-tokens.conf  (or export in ~/.zshrc / $PROFILE)
CLAUDE_SESSION_LIMIT=7631489
CLAUDE_WEEKLY_LIMIT=26230769
CLAUDE_REFRESH=15

Calibrating limits

Press c in the TUI (or run claude-tokens-calibrate standalone) while claude.ai shows your current usage percentages. The tool reads your current token counts, prompts for the percentages shown on claude.ai → Settings → Usage, and calculates limits automatically.

  Session usage % shown on claude.ai: 36
  Weekly  usage % shown on claude.ai: 26

  CLAUDE_SESSION_LIMIT = 7,550,583  (7.55M)
  CLAUDE_WEEKLY_LIMIT  = 26,076,923  (26.08M)

Limits apply immediately in the running TUI. The wizard then prompts to save to ~/.claude/claude-tokens.conf.

Colors

Press t in the TUI (or run claude-tokens-colors standalone) to open the interactive color picker. Choose warning color behavior, pick a color per role from 16 swatches, and preview the full widget live.

Color roles can also be set directly as env vars:

CLAUDE_COLOR_SESSION=cyan      # session section (default: cyan)
CLAUDE_COLOR_WEEK=magenta      # week section (default: magenta)
CLAUDE_COLOR_OK=green          # remaining indicator, low usage (default: green)
CLAUDE_COLOR_WARN=yellow       # bar/remaining at 75%+ usage (default: yellow)
CLAUDE_COLOR_CRIT=red          # bar/remaining at 90%+ usage (default: red)

Accepts color names (cyan, bright_cyan, magenta, …) or raw ANSI codes (36, 35, 92, …).

All env vars

Variable Default Description
CLAUDE_SESSION_LIMIT 0 Session token limit (0 = no bar cap)
CLAUDE_WEEKLY_LIMIT 0 Weekly token limit (0 = no bar cap)
CLAUDE_REFRESH 15 Refresh interval in seconds
CLAUDE_SESSION_OFFSET_SECS 0 Shift session start earlier (useful when starting on claude.ai web)
CLAUDE_WEIGHT_CACHE_READ_SESSION 0.1 Cache read weight for session quota
CLAUDE_WEIGHT_CACHE_READ_WEEKLY 0.0 Cache read weight for weekly quota
CLAUDE_PRICE_INPUT 3.00 Input token price per 1M
CLAUDE_PRICE_OUTPUT 15.00 Output token price per 1M
CLAUDE_PRICE_CACHE_WRITE 3.75 Cache write price per 1M
CLAUDE_PRICE_CACHE_READ 0.30 Cache read price per 1M
CLAUDE_MARGIN 2 Left margin spaces in the TUI
CLAUDE_WARN_COLORS 1 Set to 0 to disable warning color shifts

How it works

Reads ~/.claude/projects/**/*.jsonl — the JSONL logs Claude Code writes per conversation. Aggregates usage fields from API response records, deduplicating by message ID to avoid double-counting.

Session window: detected by simulating 5-hour windows through the last 12 hours of activity. A new session opens whenever an event arrives after the previous 5-hour window has closed — matching claude.ai's fixed session model.

Weekly window: resets Tuesday 15:00 UTC (matching claude.ai's observed reset schedule).

Cache read accounting: session and weekly quotas use different weights. Session counts cache reads at ~10%; weekly ignores them. If your percentages drift from claude.ai, run c to recalibrate.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stradiz_claude_tokens-1.0.1.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stradiz_claude_tokens-1.0.1-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file stradiz_claude_tokens-1.0.1.tar.gz.

File metadata

  • Download URL: stradiz_claude_tokens-1.0.1.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for stradiz_claude_tokens-1.0.1.tar.gz
Algorithm Hash digest
SHA256 1cbf71892fb80d51fa6a45383a04931e209b61ef9a24c115c4968070c49be1e3
MD5 7f77a14131e5964b6a1b849c408114a7
BLAKE2b-256 041d25cf213ee92c37a92cd66122ce7c4f09aa8e0b236d53e5e3348545ef9fc7

See more details on using hashes here.

Provenance

The following attestation bundles were made for stradiz_claude_tokens-1.0.1.tar.gz:

Publisher: publish.yml on Bernardo-Andreatta/terminal-claude-token-usage

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stradiz_claude_tokens-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for stradiz_claude_tokens-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 392749fb0ddf5235b35c5cffde1a7c6faed7a0fbcf19b7fdf55cbd1e8e952126
MD5 03a6aa8e3dbe21b09e61ce3c4f59cf8d
BLAKE2b-256 4e9a9dcb13bff4c16455fe96af4051f916fb6dd788764ebf17a57c0749b9a8cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for stradiz_claude_tokens-1.0.1-py3-none-any.whl:

Publisher: publish.yml on Bernardo-Andreatta/terminal-claude-token-usage

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page