Skip to main content

Live multi-session context-window meter for Claude Code.

Project description

claude-context-bar

A live, multi-session context-window meter for Claude Code.

screenshot

What it does

contextbar watches every session file under ~/.claude/projects/ and shows a live TUI dashboard with one row per active Claude Code session: project name, colored usage bar, percentage, token counts, and time since the session was last updated. It refreshes once per second, depends only on the Python standard library, and ships as a single file.

Install

From GitHub (recommended):

pip install git+https://github.com/ethanarnold/claude-context-bar.git

Native Windows (adds windows-curses):

pip install "git+https://github.com/ethanarnold/claude-context-bar.git#egg=claude-context-bar[windows]"

No-install one-liner:

curl -O https://raw.githubusercontent.com/ethanarnold/claude-context-bar/main/contextbar.py
python3 contextbar.py

Usage

contextbar [--ascii] [--limit N] [--no-auto-limit]
           [--refresh SEC] [--once] [--version]
Flag Example Effect
(no flags) contextbar Live TUI dashboard. Press q to quit.
--once contextbar --once Print one snapshot line per session and exit. Pipe-friendly.
--ascii contextbar --ascii Use ASCII glyphs (#/-) instead of Unicode block characters.
--limit N contextbar --limit 1000000 Override the context window in tokens. Disables auto-detect.
--no-auto-limit contextbar --no-auto-limit Disable per-model context window detection; use the 200k default.
--refresh SEC contextbar --refresh 0.5 Change the refresh interval (default: 1.0s).
--version contextbar --version Print version and exit.

Combine --once --ascii for clean piping:

contextbar --once --ascii | head -3

How it works

Claude Code stores each session as a JSON-Lines file under ~/.claude/projects/<encoded-cwd>/<session-id>.jsonl. contextbar walks those files and, for each one, scans entries of the form:

{"type": "assistant", "message": {"model": "claude-...", "usage": { ... }}}

The token count for a session is the sum of the four token fields in the most recent usage object:

  • input_tokens
  • cache_creation_input_tokens
  • cache_read_input_tokens
  • output_tokens

The model name is read from message.model on the same entries and is used to pick the right context window via the regex table in MODEL_LIMITS.

Color thresholds

Usage Color
< 50% Green
50%–85% Yellow
≥ 85% Red
schema mismatch Yellow with schema? label

Caveats

  • The Claude Code session file format is undocumented and unofficial. If it changes, the bar may render 0% or display a yellow schema? warning on affected rows. Open an issue if you see this.
  • Model auto-detection is regex-based and only knows about opus, sonnet, haiku, and the 1M-context Sonnet beta. Use --limit for anything else.
  • The TUI uses Unicode block glyphs by default. On terminals that can't render them, pass --ascii.
  • Reads files only — contextbar never writes to or modifies your Claude Code sessions.

Requirements

  • Python 3.9+
  • A curses-capable terminal:
    • macOS / Linux / WSL: built in
    • Native Windows: pip install windows-curses (or use the [windows] install extra above)
  • Claude Code installed and run at least once, so that ~/.claude/projects/ exists

Development

git clone https://github.com/ethanarnold/claude-context-bar.git
cd claude-context-bar
python3 contextbar.py

Single-file project. No build step, no dependencies.

License

MIT © 2026 Ethan

Disclaimer

Not affiliated with Anthropic. "Claude" and "Claude Code" are trademarks of Anthropic. This project depends on an undocumented file format and may break without warning when Claude Code is updated.

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

claude_context_bar-0.1.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

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

claude_context_bar-0.1.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file claude_context_bar-0.1.0.tar.gz.

File metadata

  • Download URL: claude_context_bar-0.1.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for claude_context_bar-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6656de71aeeee05dcb109c283332cc31c4efc3f470876dd98e9c20087df66d54
MD5 9287ed626d08d0f1594f9339f0eca6b6
BLAKE2b-256 59a27f1a1dcf3370d4e23b6c21662e6f19f0567615c1b87bdb86a65c5ac95f9c

See more details on using hashes here.

File details

Details for the file claude_context_bar-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for claude_context_bar-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 10055697404c21548f4a8d00e070c7c018cb4d040d2f1e634380c387359cceb7
MD5 f667748227952f1b530913adc38774fd
BLAKE2b-256 04adf22c5cd01b7afafb06d6ed946aa8c2041fd25e7645a93dade51c24ceb1d1

See more details on using hashes here.

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