Skip to content

Conversation

@BowgartField
Copy link

@BowgartField BowgartField commented Jan 26, 2026

Summary

  • Display session cost, context usage percentage, and rate limits in the chat toolbar
  • Add Rust backend module for OAuth token retrieval and Anthropic API calls
  • Add show_usage_status_bar preference with toggle in Settings
  • Add context tracking hook for accurate context percentage

Features

  • S: $X.XX | XX% - Session cost and context usage percentage
  • L: XX% (Xh Xm) - 5-hour rate limit utilization with reset time
  • W: XX% (+X.X%) (XXh) - 7-day rate limit (shown when L >= 90%)

Context Tracking Hook

The context percentage cannot be accurately calculated from token metadata alone (which stores per-API-call data). To get the real context window usage, this PR adds an optional hook that integrates with Claude Code:

How it works

  1. Enable "Accurate context tracking" in Settings > Defaults
  2. Jean installs a hook in ~/.claude/settings.json that runs on Claude Code's Stop event
  3. The hook writes context data to ~/.jean/context-data/{session_id}.json
  4. Jean reads this data to display accurate context percentage

Hook data captured

  • contextWindowTokens - Real context window size
  • contextWindowLimit - Model's context limit (200K)
  • totalCost - Session cost from Claude Code
  • modelId - Model being used

Without the hook

Falls back to calculating context from token metadata, which may be less accurate.

Technical Details

  • OAuth token retrieved from macOS Keychain or ~/.claude/.credentials.json
  • Usage limits fetched from https://api.anthropic.com/api/oauth/usage with 60-second cache
  • Session usage calculated from token metadata (input, output, cache tokens)
  • Hook uses Claude Code's session ID (stored in Jean's session metadata)

Test plan

  • Enable status bar in Settings > Defaults > Usage status bar
  • Verify S: shows cost and context % after sending messages
  • Verify L: and W: appear when logged in to Claude CLI
  • Toggle off in Settings and confirm status bar is hidden
  • Enable "Accurate context tracking" and verify context % is accurate (~40-50% instead of 100%)

Display session cost, context usage percentage, and rate limits in the chat toolbar.

- Add Rust backend module (claude_usage/) for OAuth token retrieval and API calls
- Fetch usage limits from Anthropic API with 60-second cache
- Calculate session usage from token metadata (cost, context %)
- Add ClaudeUsageStatusBar component with tooltips
- Add show_usage_status_bar preference with toggle in Settings
- Show 5-hour limit (L:) and 7-day limit (W:) when OAuth credentials available
@BowgartField
Copy link
Author

Some preview of the feature:
Capture d’écran 2026-01-26 à 08 59 30


Capture d’écran 2026-01-26 à 08 59 23


Capture d’écran 2026-01-26 à 08 59 17

Context percentage should reflect current conversation size, not cumulative tokens.
- Use last run's input_tokens + cache_read for context %
- Keep summing all runs for cost calculation
- Add hook installer that automatically configures Claude Code settings
- Hook captures real context window size from Claude Code's Stop event
- Fix session ID mismatch: use claude_session_id from metadata
- Add "Accurate context tracking" toggle in Settings > Defaults
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants