Feature request: expose token/context usage for external tools
Feature Request
Is your feature request related to a problem?
There's no way to display Claude Code's token/context usage in external monitoring tools (e.g., macOS menu bar apps like Stats, xbar/SwiftBar, or similar system monitors on other platforms).
Currently, token usage data is only visible inside the Claude Code TUI via /cost or the status line. Users who monitor system resources in their menu bar (CPU, RAM, disk, network) would love to also see Claude Code's context window usage at a glance.
Describe the solution you'd like
Expose session token/context usage in a machine-readable format, for example:
- Write usage stats to a file (e.g.,
~/.claude/usage.json) updated in real-time, containing: context_used_percent(% of context window used)tokens_input/tokens_outputcost_usd(session cost)model(current model)- Alternatively, a local socket or CLI command (
claude --usage --json) that returns current session stats
This would allow users to build integrations with menu bar tools (xbar, SwiftBar, Stats, Waybar, polybar, etc.) or custom dashboards.
Describe alternatives you've considered
- Relying on
/costinside the TUI — works, but requires switching context to the terminal - Parsing terminal output — fragile and not officially supported
Additional context
Many developers already use menu bar monitors for CPU/RAM/network. Having Claude Code usage alongside those metrics would improve workflow ergonomics significantly.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗