TokenOps for Claude Code
Why am I hitting my limit? One command names the prompts that cost you the most, says why, and what to change. Read from your own session logs, on your machine.
/tokenops:doctor
Why am I hitting my limit? (last 7 days, 12 sessions, 304 prompts, $235 at API list prices)
37% of your Claude usage went to coming back after a break.
39 times the cache had expired, so Claude re-paid for the whole conversation.
/compact before you step away would have saved ~31%.
Your 3 most expensive prompts (9% of usage)
#2 Wed 21:56 project B (prompt hidden)
█████████░░░░░░░░░░░ 44% of that 5-hour window | 24x your typical prompt
CACHE EXPIRED away 4h 45m, past the 1h cache: one call re-wrote your
whole 965k-token conversation to the cache at 2x the input price
1 model call, paid $7.41 -> /compact before leaving ~$0.52 (14x less) | /clear + note ~$0.27
...
Where your usage goes
41% Re-reading context every call
37% Coming back after breaks (cache re-written)
12% Claude's output
11% Caching new context
What to change
1. Re-reading is 41%: every call reads the whole conversation again ... Use /clear when you
switch to an unrelated task.
2. Output is 12% of your usage, so a terse-output tool like caveman can save at most that ...
Install
In Claude Code:
/plugin marketplace add theagentplane/tokenops
/plugin install tokenops@tokenops
Then run /tokenops:doctor (last 7 days; /tokenops:doctor 30 for 30). Needs Python 3.9+ on
your PATH; nothing to pip install.
Or, without installing anything, from any terminal with uv:
uvx tokenops doctor
(The tokenops package on PyPI is this CLI; the agent governance library is agent-tokenops.)
Reading the report
- Prompts. One prompt you type can make many model calls (tool use, subagents). They are all counted under the prompt that started them. The doctor shows the 3 most expensive prompts, with the project they were typed in.
- Tokens are the size of the whole conversation that one call sent, not a sum over calls. Models with a 1M-token context can carry a conversation that long.
- CACHE EXPIRED means the call came more than the cache lifetime (1 hour on a Claude plan, 5 minutes with an API key) after the previous one, and wrote most of the conversation to the cache again at the cache-write price. The headline and the "Coming back after breaks" row are the same number: the cache writes of those calls.
- 5-hour windows are estimated from your first prompt in each, not read from Anthropic's meter. The cheaper costs are estimates: only the calls a break made expensive are re-priced.
- Sharing a screenshot? From a terminal,
uvx tokenops doctor --redacthides your prompts and project names ("project A", "project B").
Saver mode
/tokenops:saver on lets TokenOps act on what the doctor finds. Off by default; every hook
fails open.
-
Resume guard. After a break longer than the cache lifetime, your next message re-reads the whole conversation at the cache-write price. The guard holds that message once:
TokenOps: this session's cache expired (1.5 h since the last reply). Sending now re-reads 433k tokens at the cache-write price: about $3.47 API-equivalent, against $0.09 while the cache was warm. - Send the same message again to continue anyway. - Or run /compact first: it keeps the gist in far fewer tokens. - Or /clear and paste a 3-line summary of where you were (cheapest).It only acts when the context is at least 50k tokens (
TOKENOPS_GUARD_MIN_TOKENS). -
Smart RTK. With RTK installed, shell commands Claude runs are rewritten to their compact RTK form (
git status->rtk git status), using RTK's ownrtk rewrite. File reads (cat,head,sed -n),git diff/git show, and the next test run after a failing one stay verbatim, because Claude needs that output exactly. If RTK's own hook is installed, smart RTK stays off so nothing is rewritten twice: remove RTK's hook from your Claude Code settings to let TokenOps decide. -
Measured, not guessed. Smart RTK and caveman are each switched on in a random half of your sessions. After 10 sessions on and 10 off, the doctor shows what each one did to your usage per prompt, and the saver mode keeps it only if it saves:
Measured on your sessions (saver mode A/B, usage per prompt) Smart RTK -6% usage per prompt (95% range -9% to -2%) -> kept on caveman +1% usage per prompt (95% range -3% to +5%) -> turned off Usage only: hooks cannot see whether the work went as well.For caveman, set its own default to off (
"defaultMode": "off"in caveman's config file, orCAVEMAN_DEFAULT_MODE=off) so TokenOps decides per session.
/tokenops:saver status shows what is on; /tokenops:saver off turns it all off.
How it reads your usage
Claude Code writes every model response to ~/.claude/projects/*/*.jsonl, often on several
lines with the same message id. The doctor keeps the last line per response, includes subagent
transcripts, counts a response once even when a forked session copies it, and prices each response at Anthropic's list rates: input, output, cache reads,
and cache writes (1.25x input for the 5-minute cache, 2x for the 1-hour cache). Prices come from
TokenOps' price book (src/tokenops/framework/pricing.py).
- Coming back after breaks: a cache write of 20,000+ tokens, at least half the conversation, more than the cache lifetime after the previous call. The cache had expired, so the whole conversation was written again.
- Re-reading context: cache reads. Every call reads the conversation again.
- Caveman and RTK advice is a ceiling from your own usage mix (what share is output, what share of tool output came from shell commands RTK compacts), not a measured A/B.
On a Claude plan the dollar figures are API-equivalent: they show your share of usage, not a bill. Nothing leaves your machine.
What it runs, reads and stores
- Runs:
python3(orpython) with the scripts in this folder, standard library only. With Saver mode on and RTK installed, it also runsrtk rewrite <command>to ask RTK how it would compact a shell command. Nothing else. - Reads: your Claude Code session logs (
~/.claude/projects/*/*.jsonl), your Claude Code settings files (to see which token savers are installed), caveman's installed skill file and config (only when caveman is installed), and this plugin's ownprices.json. - Stores: a small settings file and one small JSON file per session in Claude Code's plugin
data folder (
$CLAUDE_PLUGIN_DATA): whether Saver mode is on, the A/B choices and results. - Sends: nothing. It makes no network requests and keeps no copy of your prompts or code.
- Changes: with Saver mode on, it can hold one message after a break (you send it again to go on) and rewrite a shell command to its RTK form. With Saver mode off, it only reads.
Development
python scripts/sync-claude-prices.py # after changing DEFAULT_RATES
python -m pytest tests/claude_code
Metadata
Release files for tokenops 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tokenops-0.2.0.tar.gz | 23.9 kB | Without provenance | Details for tokenops-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tokenops-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for tokenops-0.2.0-py3-none-any.whl |
Total release size: 53.2 kB
Release files / tokenops-0.2.0.tar.gz
| Download URL | tokenops-0.2.0.tar.gz |
|---|---|
| Size | 23.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cc9bee30ec739438cf08b5cb455d3a4b2d50d96d376ed3cbf57c263a4e4e44fb
|
|
BLAKE2b-256 checksum How to use checksums |
3b72afd852b7c50d5ef8eea640b8fe94c698bc534a9c831e83d470cc5394fcf8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / tokenops-0.2.0-py3-none-any.whl
| Download URL | tokenops-0.2.0-py3-none-any.whl |
|---|---|
| Size | 29.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
273be2846cebc0a4da82fe1d960ba371dc289096eb9a9ee5a50382f268622612
|
|
BLAKE2b-256 checksum How to use checksums |
13ddb44cea333569334a86291d755b3b02d713882e99019194dd90dc56774ab5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for tokenops 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.