claude-code - 💡(How to fix) Fix Feature: expose context window usage programmatically

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Fix Action

Fix / Workaround

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

RAW_BUFFERClick to expand / collapse

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.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING