Real-time context monitoring for Claude Code. Track token usage, catch degradation early, and understand your AI spend — all without leaving your terminal.
By the time you notice output quality dropping, you've already wasted tokens — and money.
Each tool call, each file read quietly consumes context. You only find out when Claude starts looping or forgetting what it just wrote.
A single runaway session can burn thousands of tokens before you realize the model is operating at 20% intelligence. No warning, no way to see trends.
As context fills, Claude's effective intelligence drops along a measurable curve. Running at 30% context free isn't the same as running at 80% free.
After a session ends, you can't audit what happened — which interactions consumed the most tokens or why a particular task ballooned the context.
Claude's prompt cache has a 5-minute TTL. Every pause — a review, a coffee, a long think — silently evicts it. Your next request pays full token price again, with no warning and no way to tell.
When Claude compacts its context at low model intelligence, the summary is lossy — key details get lost. You have no idea when it happened or how degraded the model was at the time.
Stop hunting for session IDs. Three improvements that make the CLI feel instant, shipped April 2026.
sessions commandRun context-stats sessions to list recent sessions with project, model, token count, and last-activity time. Use --minutes N to widen the window.
Every command — graph, report, export, cache-warm — auto-detects the most recent session when you omit the ID. Just run context-stats and go.
sessions validationMissing, zero, or negative --minutes values now fail fast with a clear error instead of silently falling back to the default. Stray positionals are rejected too.
Swapped legacy .replace("statusline.", "") and slice-based prefix stripping for Python 3.9+ removeprefix() across the CLI and state modules.
From real-time awareness to multi-week cost reports — context-stats gives you complete visibility without ever leaving your terminal.
Persistent status line in your Claude Code session — always on, zero friction.
context-stats graph)
▼ markers show when & where Claude compacted
context-stats sessions shows recent sessions with metadata
Export a detailed Markdown report for any completed session.
Understand cost trends, model mix, and efficiency across all your projects.
Claude's prompt cache has a strict 5-minute TTL. One idle gap — a review pause, a coffee, a long think — silently evicts it. Your next request pays full token price, no warning.
1h, 90m, 3600s
context-stats export reportFour commands — each level of analytics, shown in full.
Color-coded zones tell you exactly what to do — no guesswork required.
context-stats graphcontext-stats maps token usage to five zones so you always know what to do next.
The statusline updates live after each prompt. Here's exactly what it shows across all five zones.
No config files. No sign-up. No data leaving your machine.
One pip command, zero dependencies.
pip install context-stats
Add the status line to ~/.claude/settings.json.
{
"statusLine": {
"type": "command",
"command": "claude-statusline"
}
}
Your status line is live. Context zone, MI score, token delta — all visible.
claude # or open Claude Code
Use any of these commands any time — no session ID needed.
# Live ASCII dashboard — context, MI, cache, delta
context-stats graph
# List recent sessions (last 5 min by default)
context-stats sessions
context-stats sessions --minutes 30
# Keep the prompt cache alive during idle gaps
context-stats cache-warm on
# Export full session report to Markdown
context-stats export
# Multi-project analytics (last 30 days)
context-stats report --since-days 30
# Explain raw JSON from Claude Code stdin
context-stats explain
No. All session data stays local in ~/.claude/statusline/. There are no network requests, no telemetry, no external API calls of any kind. Your token usage and session data never leave your machine.
No. The statusline script is a lightweight Python process that runs synchronously on each prompt. It reads from local CSV files and writes a single line to stdout. Typical execution is under 10ms. Git operations have a 5-second timeout to prevent hangs.
Yes. context-stats is pure Python 3.9+ with zero external dependencies and runs on macOS, Linux, and Windows. The statusline script and CLI both work across all platforms.
Python 3.9 or higher. No external packages are required — context-stats uses only the Python standard library.
Yes. Create ~/.claude/statusline.conf with key=value pairs. You can customize 18 named colors or use hex codes, toggle MI display, token detail, delta tracking, session ID, motion effects, and more. Full configuration reference in the docs.
context-stats reads the token data directly from Claude Code's status line JSON. It does not estimate — it reports the exact values that Claude Code provides. The MI score is calibrated against the MRCR v2 8-needle benchmark.
The statusline (claude-statusline) is the persistent one-line display shown by Claude Code at each prompt — it's always on. The graph dashboard (context-stats graph) is an on-demand ASCII chart view you run manually to see usage history, MI trends, cache activity, and delta per interaction over the session.
Claude's prompt cache has a 5-minute TTL. Any pause longer than 5 minutes — a code review, a coffee break, a long think before replying — silently evicts the cache. Your next request then pays full token price instead of the cached rate (roughly 10× cheaper for large contexts). cache-warm solves this by running a lightweight background heartbeat every 4 minutes, keeping the cache alive for up to 30 minutes (or a custom duration you specify). Start it with context-stats <session_id> cache-warm on from a separate terminal, and stop it with cache-warm off. The savings show up automatically in your context-stats export report.
When Claude Code compacts its context (a >50% drop in token count between interactions), context-stats detects it automatically and marks the point with a ▼ symbol in your graphs. This tells you exactly when and where compaction occurred during a session. More importantly, it also captures the MI (Model Intelligence) score at that moment — if MI was below 0.6 when compaction happened, it flags the event as potentially lossy. A lossy compaction means Claude was already degraded when it summarized, so the summary may have dropped important details. You'll see this as ▼ compact (MI 0.61 ⚠ lossy) in the graph output.
Each context zone (Planning, Code, Dump, ExDump, Dead) now comes with a brief actionable recommendation so you always know what to do next — no need to look anything up. For example, in the Dump zone you'll see "Wrap up task, export session, prepare new context". These appear inline in the statusline output and in graph annotations.
Free. MIT licensed. Zero external dependencies.
All your data stays local — always.