Feature: expose context window usage programmatically

Resolved 💬 2 comments Opened May 28, 2026 by hannesnortje Closed Jun 1, 2026

Problem: Claude Code tracks context window usage internally and displays it via /context, but there is no programmatic way to access this data from outside the TUI.

Use Case: Multi-agent orchestration — monitoring 10+ Claude Code instances running in tmux panes. Currently the only way to check an agent context health is to capture the pane output after running /context and parse the ANSI text. Fragile and invasive.

Requested Feature — expose context window usage via ONE of:

  1. CLI flag: claude --context-usage returning JSON with model, tokens_used, tokens_total, percentage
  2. Session file: ~/.claude/sessions/<id>/context.json updated each turn
  3. Environment variable: CLAUDE_CONTEXT_USED / CLAUDE_CONTEXT_TOTAL
  4. JSON output mode: extend --output-format json to include context stats

Current Workaround: Parse TUI output via tmux capture-pane after sending /context — fragile, invasive, breaks agent flow.

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗