{"slug": "tokendiet-see-what-your-claude-code-session-costs-for-zero-tokens", "title": "Tokendiet – see what your Claude Code session costs, for zero tokens", "summary": "Developer Marco Cancellotti released Tokendiet, a free open-source statusline tool for Anthropic's Claude Code that displays real-time session token usage and cost, with color-coded warnings to prompt users to clear context. The tool, available on GitHub, measures actual session costs by comparing token readings between turns, showing that long sessions grow quadratically in expense, with cache reads accounting for about 66% of spend in large sessions.", "body_md": "A Claude Code statusline that shows what your session is actually costing —\nand tells you when to `/clear`.\n\nThe diet is on **context**, not on your prose. Shorter answers save almost\nnothing; long sessions are what get expensive. See [Why](#why-context-and-not-verbosity),\nor the short version at **[mcancellotti.github.io/tokendiet](https://mcancellotti.github.io/tokendiet)**.\n\nIn plain text, the three states:\n\n```\nOpus 5 · ~/myproject · main* · ░░░░░░░░░░ 40K/1.0M · $0.62\nOpus 5 · ~/myproject · main* · █░░░░░░░░░ 185K/1.0M · $3.42 · ◐ /clear when this task ends\nOpus 5 · ~/myproject · main* · ██████░░░░ 620K/1.0M · $18.40 · ⚠ /clear\n```\n\nGreen under 150K tokens, yellow past it, red past 350K. Model, working\ndirectory, git branch (`*` when dirty), context bar, live session cost.\n\nThe second line reports the turn that has just finished, and sets it against the first turn of the session:\n\n```\nOpus 5 · ~/myproject · main* · ██████░░░░ 620K/1.0M · $18.40 · ⚠ /clear\nturn +160K · $1.40 · 6.7× vs first turn · 1h34m\n```\n\nNone of that is modelled or estimated. A turn's cost is the difference between two readings of the session total, and the multiplier is that figure against the first turn that cost anything. It is this project's whole argument reduced to one number, measured on your own session: the question you are about to ask costs nearly seven times what the same question cost ninety minutes ago.\n\nThe multiplier appears once it passes 1.15x — below that it is noise, and a\nline that prints `1.0×` every turn is a line people stop reading. It goes\nyellow at 2x and red at 4x.\n\nSet `TOKENDIET_TURN=0` to keep a single line.\n\n```\ngit clone https://github.com/mcancellotti/tokendiet\ncd tokendiet\npython3 install.py     # on Windows: python install.py\n```\n\nThe installer copies `tokendiet.py` into `~/.claude/` and sets the `statusLine`\nblock in `~/.claude/settings.json`, leaving every other setting untouched. Your\nold `settings.json` is backed up next to it as `settings.json.bak`.\n\nStart a new Claude Code session to see the bar.\n\nTo do it by hand instead, drop `tokendiet.py` anywhere and add:\n\n```\n{\n  \"statusLine\": {\n    \"type\": \"command\",\n    \"command\": \"python3 ~/.claude/tokendiet.py\",\n    \"padding\": 0\n  }\n}\n```\n\nRequires Python 3.8+. No dependencies.\n\n`python install.py` works the same from `cmd` or PowerShell. If you'd rather\nnot clone the repo, fetch the script and wire it up by hand — from PowerShell:\n\n```\nNew-Item -ItemType Directory -Force \"$env:USERPROFILE\\.claude\" | Out-Null\nInvoke-WebRequest -UseBasicParsing https://raw.githubusercontent.com/mcancellotti/tokendiet/main/tokendiet.py -OutFile \"$env:USERPROFILE\\.claude\\tokendiet.py\"\n```\n\nThen add this to `%USERPROFILE%\\.claude\\settings.json`, with your own username\nin the path:\n\n```\n{\n  \"statusLine\": {\n    \"type\": \"command\",\n    \"command\": \"python C:/Users/YOU/.claude/tokendiet.py\",\n    \"padding\": 0\n  }\n}\n```\n\nThree Windows details worth knowing. That file is `settings.json` **inside**\nthe `.claude` folder — not the `.claude.json` sitting next to it, which holds\nyour MCP servers and is never checked for a statusline. Use `python` or `py`,\nnot `python3`: on Windows `python3` is usually the Microsoft Store alias, which\nopens the Store rather than running anything. And write the path with forward\nslashes — inside JSON a backslash starts an escape sequence, so `C:\\Users\\...`\nwould have to be doubled to survive.\n\nEvery turn re-sends the entire accumulated context. A session that has grown to\n500K tokens pays for 500K tokens *on every single turn*, whether the reply is\nthree words or three pages. Cost grows quadratically with session length.\n\nMeasured across my own five largest sessions:\n\n|  | share of spend | \n|---|---|\n| cache reads | ~66% | \n| cache writes | ~24% | \n| output | ~10% | \n\nAnd only about a quarter of that output was prose — the rest was tool calls. So\ncompressing how the model *writes* touches roughly 1.5% of the bill. Clearing\nbetween unrelated tasks, and reading files narrowly instead of wholesale, is\nworth orders of magnitude more. That is the diet this tool is named after.\n\nMost context meters show \"% of window full\". That number lies about cost. With a 1M-token window, 500K used looks like a comfortable half tank — but it costs 2.5x what 200K costs, on every turn, until you clear.\n\nSo the colours key off absolute token counts: yellow at 150K, red at 350K. The bar still fills proportionally to the window, because knowing how much room is left is useful too — it just isn't what determines the bill.\n\nA statusline is drawn by your terminal. It never enters the conversation, so it\ncosts **zero tokens**.\n\nThe alternative would be a `UserPromptSubmit` hook injecting a warning into the\ncontext. That works, but it pays for the warning in input tokens on every\nsingle turn — spending from exactly the budget it's trying to protect. And no\nhook can run `/clear` or `/compact` for you: those are harness commands, not\nthings a hook or a skill can invoke. Whatever you build, a human has to make\nthe call. So the job is to put the number where a human will see it, as cheaply\nas possible.\n\n| Variable | Default | Meaning | \n|---|---|---|\n| `TOKENDIET_WARN` | `150000` | Tokens at which the bar turns yellow | \n| `TOKENDIET_HIGH` | `350000` | Tokens at which it turns red | \n| `TOKENDIET_TURN` | `1` | Set to `0` to drop the per-turn second line | \n| `NO_COLOR` | unset | Set to anything to disable colour | \n\nSet them in the `statusLine` command itself if you want them scoped to it:\n\n```\n{ \"type\": \"command\", \"command\": \"TOKENDIET_WARN=100000 python3 ~/.claude/tokendiet.py\", \"padding\": 0 }\n```\n\nClaude Code pipes a JSON payload to the statusline command on stdin. tokendiet\ntakes `context_window.used_percentage` when it's there, and otherwise falls\nback to summing this turn's `input_tokens`, `cache_creation_input_tokens` and\n`cache_read_input_tokens` — cached or not, you pay for all three. Missing\nfields are skipped rather than guessed, and malformed input prints nothing\ninstead of spraying a traceback across your terminal.\n\n```\npython3 test_render.py -v\n```\n\nRenders sample payloads for each state — green, yellow, red, the fallback path, custom thresholds, empty payloads, junk on stdin — and checks the output. No test framework needed.\n\ntokendiet makes no network calls and collects nothing. It reads the payload\nClaude Code hands it, shells out to `git` for the branch name, and prints a\nline.\n\nThe per-turn line needs to remember the previous turn, so it keeps one small\nfile per session — a running total and the last turn's delta — in your system\ntemp directory under `tokendiet/`, pruned after three days. Nothing leaves your\nmachine, and `TOKENDIET_TURN=0` stops it being written at all.\n\nMIT", "url": "https://wpnews.pro/news/tokendiet-see-what-your-claude-code-session-costs-for-zero-tokens", "canonical_source": "https://github.com/mcancellotti/tokendiet", "published_at": "2026-09-09 09:30:04+00:00", "updated_at": "2026-09-09 10:12:51.538718+00:00", "lang": "en", "topics": ["developer-tools", "ai-tools", "ai-infrastructure"], "entities": ["Marco Cancellotti", "Claude Code", "Anthropic", "GitHub", "Tokendiet"], "alternates": {"html": "https://wpnews.pro/news/tokendiet-see-what-your-claude-code-session-costs-for-zero-tokens", "markdown": "https://wpnews.pro/news/tokendiet-see-what-your-claude-code-session-costs-for-zero-tokens.md", "text": "https://wpnews.pro/news/tokendiet-see-what-your-claude-code-session-costs-for-zero-tokens.txt", "jsonld": "https://wpnews.pro/news/tokendiet-see-what-your-claude-code-session-costs-for-zero-tokens.jsonld"}}