{"slug": "monitor-claude-code-token-usage-cost-in-the-status-line-before-the-ai-bubble", "title": "Monitor Claude Code Token Usage & Cost in the Status Line (Before the AI Bubble Pops)", "summary": "Anthropic's Claude Code now displays real-time token usage and cost in its terminal status line, helping users monitor their session and weekly limits. The feature, configured via a custom script, shows context window percentage, rate limit usage, and running dollar cost to prevent budget overruns. As AI token prices are currently subsidized by investor funding, the tool encourages spending awareness before costs rise.", "body_md": "I wanted to see my real (dollar) token cost and usage limits at a glance while I work with Claude Code. Here’s how I set it up.\n\nFirst, some background. Every message you send to Claude is measured in **tokens** (roughly, chunks of text). If you’re on a paid plan like Max, Anthropic doesn’t charge per token. Instead it gives you a budget that refills on two timers: a **5-hour session limit** and a **weekly limit**. Run out, and you have to wait for the next reset.\n\nThat makes it easy to burn through your budget without realising. A heavy planning session eats far more tokens than lighter implementation work, so it helps to know where you stand before you hit a wall. For a while, the only way to check was to open a separate usage panel and switch back and forth. Now Claude Code can show it all right in the [status bar](https://code.claude.com/docs/en/statusline) at the bottom of your terminal.\n\nThere’s a longer-term reason to watch this, too. Right now AI tokens are cheap, practically subsidised, because these companies are spending investor money to win users. That won’t last forever. When the bubble pops and every prompt costs what it actually costs, it’s better to already be in the habit of watching what you spend. So let’s get that number on screen.\n\nClaude Code has a **status line**, a single line of text at the bottom of the screen. You point it at a small script of your own, and each time the conversation updates, Claude Code hands that script a bundle of live data (as JSON) about your session. Your script picks out the bits it cares about and prints one line back. Whatever it prints is what you see.\n\nWire it up in `~/.claude/settings.json`\n\n:\n\n```\n{\n  \"statusLine\": {\n    \"type\": \"command\",\n    \"command\": \"bash /Users/you/.claude/statusline-command.sh\",\n    \"padding\": 0,\n    \"refreshInterval\": 10\n  }\n}\n```\n\nThe data Claude Code hands your script carries everything you need:\n\n`.context_window.used_percentage`\n\n: how full the current context is`.rate_limits.five_hour.used_percentage`\n\n: your 5-hour session limit`.rate_limits.seven_day.used_percentage`\n\n: your weekly limit`.cost.total_cost_usd`\n\n: the running cost of this sessionRead them with `jq`\n\nand glue them into a string:\n\n```\ninput=$(cat)\nused=$(echo \"$input\" | jq -r '.context_window.used_percentage')\ncost=$(echo \"$input\" | jq -r '.cost.total_cost_usd')\nprintf \"ctx:%.0f%%  \\$%.2f\" \"$used\" \"$cost\"\n```\n\nRead the docs on [available data for status line](https://code.claude.com/docs/en/statusline#available-data) to customise further.\n\nSession cost is only half the story. For per-day and per-week spend, incorporate [ ccusage](https://github.com/ryoppippi/ccusage). ccusage reads local usage data from coding agent CLIs and turns it into daily, weekly, monthly, and session reports.\n\n```\nccusage daily --json --since 2026-06-24\n```\n\nCache its output for a minute so you’re not re-running it on every keystroke, then sum the totals with `jq`\n\n.\n\nThat’s it. Your context, limits, reset times, and running cost now sit at the bottom of the screen, updating as you work. When tokens finally get pricey, you won’t be flying blind.\n\nI’ve also added a cherry on top by colour coding the output. Green when there is enough time, yellow, and red when the session or tokens are about to expire.\n\nHere is the full script for `/Users/you/.claude/statusline-command.sh`\n\n:\n\n``` bash\n#!/bin/sh\n# To install dependencies, use brew:\n# brew install jq ccusage\ninput=$(cat)\n\nbranch=$(git -C \"$(echo \"$input\" | jq -r '.workspace.current_dir')\" --no-optional-locks rev-parse --abbrev-ref HEAD 2>/dev/null)\nmodel=$(echo \"$input\" | jq -r '.model.display_name')\nused=$(echo \"$input\" | jq -r '.context_window.used_percentage // empty')\nsession=$(echo \"$input\" | jq -r '.rate_limits.five_hour.used_percentage // empty')\nsession_reset=$(echo \"$input\" | jq -r '.rate_limits.five_hour.resets_at // empty')\nweekly=$(echo \"$input\" | jq -r '.rate_limits.seven_day.used_percentage // empty')\nweekly_reset=$(echo \"$input\" | jq -r '.rate_limits.seven_day.resets_at // empty')\nsession_cost=$(echo \"$input\" | jq -r '.cost.total_cost_usd // empty')\n\nESC=$(printf '\\033')\nGREEN=\"${ESC}[32m\"\nYELLOW=\"${ESC}[33m\"\nRED=\"${ESC}[31m\"\nRESET=\"${ESC}[0m\"\n\nsession_pct_color=\"\"\nif [ -n \"$session\" ]; then\n  if [ \"$session\" -lt 60 ]; then\n    session_pct_color=\"$GREEN\"\n  elif [ \"$session\" -le 90 ]; then\n    session_pct_color=\"$YELLOW\"\n  else\n    session_pct_color=\"$RED\"\n  fi\nfi\n\nsession_reset_at=\"\"\nsession_reset_in=\"\"\nsession_time_color=\"\"\nif [ -n \"$session_reset\" ]; then\n  session_reset_at=$(date -r \"$session_reset\" +%H:%M 2>/dev/null)\n  now=$(date +%s)\n  remaining=$((session_reset - now))\n  if [ \"$remaining\" -gt 0 ]; then\n    hours=$((remaining / 3600))\n    mins=$(((remaining % 3600) / 60))\n    if [ \"$hours\" -gt 0 ]; then\n      session_reset_in=\"${hours}h${mins}m\"\n    else\n      session_reset_in=\"${mins}m\"\n    fi\n    if [ \"$remaining\" -gt 7200 ]; then\n      session_time_color=\"$GREEN\"\n    elif [ \"$remaining\" -ge 3600 ]; then\n      session_time_color=\"$YELLOW\"\n    else\n      session_time_color=\"$RED\"\n    fi\n  fi\nfi\n\nweekly_days_left=\"\"\nif [ -n \"$weekly_reset\" ]; then\n  now_epoch=$(date +%s)\n  weekly_remaining=$((weekly_reset - now_epoch))\n  if [ \"$weekly_remaining\" -gt 0 ]; then\n    weekly_days_left=$(( (weekly_remaining + 86399) / 86400 ))\n  fi\nfi\n\ntoday_cost=\"\"\nweek_cost=\"\"\nif [ -n \"$weekly_reset\" ]; then\n  week_start_epoch=$((weekly_reset - 7 * 24 * 3600))\n  week_start=$(date -r \"$week_start_epoch\" +%Y-%m-%d 2>/dev/null)\n  today_date=$(date +%Y-%m-%d)\n  cache_file=\"/tmp/statusline-ccusage-cache.json\"\n  cache_max_age=60\n\n  refresh_cache=1\n  if [ -f \"$cache_file\" ]; then\n    age=$(( $(date +%s) - $(stat -f %m \"$cache_file\" 2>/dev/null || echo 0) ))\n    [ \"$age\" -lt \"$cache_max_age\" ] && refresh_cache=0\n  fi\n\n  if [ \"$refresh_cache\" = \"1\" ]; then\n    (ccusage daily --json --since \"$week_start\" > \"${cache_file}.tmp\" 2>/dev/null && mv \"${cache_file}.tmp\" \"$cache_file\") &\n  fi\n\n  if [ -f \"$cache_file\" ]; then\n    today_cost=$(jq -r --arg today \"$today_date\" '[.daily[] | select(.period == $today) | .totalCost] | add // empty' \"$cache_file\" 2>/dev/null)\n    week_cost=$(jq -r '[.daily[].totalCost] | add // empty' \"$cache_file\" 2>/dev/null)\n  fi\nfi\n\noutput=\"🇺🇦\"\n\n[ -n \"$branch\" ] && output=\"$output $branch\"\n[ -n \"$model\" ] && output=\"$output  $model\"\n[ -n \"$used\" ] && output=\"$output  ctx:$(printf '%.0f' \"$used\")%\"\n[ -n \"$session\" ] && output=\"$output  5h:${session_pct_color}$(printf '%.0f' \"$session\")%${RESET}\"\n[ -n \"$session_reset_at\" ] && output=\"${output}→${session_reset_at}\"\n[ -n \"$session_reset_in\" ] && output=\"${output} ${session_time_color}(${session_reset_in})${RESET}\"\n[ -n \"$weekly\" ] && output=\"$output  7d:$(printf '%.0f' \"$weekly\")%\"\n[ -n \"$weekly_days_left\" ] && output=\"${output} (${weekly_days_left}d)\"\n[ -n \"$session_cost\" ] && output=\"$output  sess:\\$$(printf '%.2f' \"$session_cost\")\"\n[ -n \"$today_cost\" ] && output=\"$output day:\\$$(printf '%.2f' \"$today_cost\")\"\n[ -n \"$week_cost\" ] && output=\"$output wk:\\$$(printf '%.2f' \"$week_cost\")\"\n\nprintf \"%s\" \"$output\"\n```\n\nPaste this prompt into Claude Code and it’ll do the whole thing, following the same steps from this article. Steps described are for a Mac, and Claude will try to adapt the script if you’re on a different OS.\n\n```\nSet up a custom status line for Claude Code that shows my live token usage and cost. Use the full script exactly as is on this tutorial: https://www.yurikoval.com/blog/monitoring-claude-code-token-usage.html\n\n1. Install the dependencies with Homebrew: jq and ccusage.\n2. Create a shell script at ~/.claude/statusline-command.sh. It should read the JSON that Claude Code sends on stdin and print ONE status line containing:\n   - the current git branch and the model display name\n   - context window used percent (.context_window.used_percentage)\n   - the 5-hour session limit used percent and its reset time (.rate_limits.five_hour)\n   - the 7-day weekly limit used percent and days remaining (.rate_limits.seven_day)\n   - the running session cost (.cost.total_cost_usd)\n   - today's and this week's total cost from \"ccusage daily --json\", cached for about 60 seconds so it isn't re-run on every update\n   Colour the session and weekly numbers green / yellow / red as they get close to the limit or reset.\n3. Register the script in ~/.claude/settings.json under a \"statusLine\" block of type \"command\" that runs it with bash.\n4. Make the script executable and show me the resulting status line.\n```\n\nHappy vibe coding!", "url": "https://wpnews.pro/news/monitor-claude-code-token-usage-cost-in-the-status-line-before-the-ai-bubble", "canonical_source": "https://www.yurikoval.com/blog/monitoring-claude-code-token-usage.html", "published_at": "2026-06-30 01:00:00+00:00", "updated_at": "2026-07-07 14:04:17.901045+00:00", "lang": "en", "topics": ["ai-tools", "large-language-models", "developer-tools"], "entities": ["Anthropic", "Claude Code", "ccusage", "jq"], "alternates": {"html": "https://wpnews.pro/news/monitor-claude-code-token-usage-cost-in-the-status-line-before-the-ai-bubble", "markdown": "https://wpnews.pro/news/monitor-claude-code-token-usage-cost-in-the-status-line-before-the-ai-bubble.md", "text": "https://wpnews.pro/news/monitor-claude-code-token-usage-cost-in-the-status-line-before-the-ai-bubble.txt", "jsonld": "https://wpnews.pro/news/monitor-claude-code-token-usage-cost-in-the-status-line-before-the-ai-bubble.jsonld"}}