Skip to main content

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

Project description

claude-context-bar

PyPI version Python versions License: MIT

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

screenshot

What it does

I built contextbar because I was getting sick of running /context over and over to keep tabs on my agents.

This started as a little afternoon for-fun project that I wasn't going to put on GitHub, but it's actually really useful to watch your agents' context grow in real time. So I decided to throw it up on GitHub for shiggles.

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

pip install claude-context-bar
contextbar

That's it.

Native Windows (adds windows-curses):

pip install "claude-context-bar[windows]"

From source / GitHub:

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

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.1.tar.gz (8.6 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.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: claude_context_bar-0.1.1.tar.gz
  • Upload date:
  • Size: 8.6 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.1.tar.gz
Algorithm Hash digest
SHA256 c6ac376fbc006350f6524b2dd8d9c6322c377814ddc27bc29ea70e552e94d9f3
MD5 03156973da1e3b994120b2be5599f770
BLAKE2b-256 2cd277b4c8005beeb53926def5eb937a895b10aa8b744204932db594ae3b4044

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for claude_context_bar-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 207f5be81d723155d379aca231d6b7aff833bac865c60a4ad9e70658d8f04393
MD5 86ba515d0a48e048dc21f1889bd04cd3
BLAKE2b-256 76965d1f58db204d14cbd6a085de4f064b728505c7b777f7ba961233c3401a09

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