Add token/context usage percentage to statusline script context object

Resolved 💬 3 comments Opened Jan 26, 2026 by thomasjackson-tylertech Closed Jan 28, 2026

Summary

Add token and context usage metrics to the statusline script context object for real-time monitoring during Claude Code sessions.

Problem Statement

Custom statusline scripts receive JSON context via stdin with workspace information, but lack visibility into token/context usage. Users need real-time feedback on context consumption to:

  • Avoid hitting context limits unexpectedly
  • Monitor session efficiency
  • Make informed decisions about when to start fresh sessions
  • Integrate usage metrics directly into their development workflow

Current Behavior

The statusline script receives:

{
  "workspace": {
    "current_dir": "/path/to/workspace"
  }
}

Proposed Solution

Extend the context object with a usage field:

{
  "workspace": {
    "current_dir": "/path/to/workspace"
  },
  "usage": {
    "tokens_used": 12450,
    "tokens_limit": 200000,
    "usage_percentage": 6.2
  }
}

Use Case

Users with custom statusline scripts can display real-time context usage:

import json
import sys

context = json.loads(sys.stdin.read())
cwd = context.get('workspace', {}).get('current_dir', '.')
usage = context.get('usage', {})
pct = usage.get('usage_percentage', 0)

# Color-coded display based on usage
if pct > 80:
    status = f"\033[91m⚠ {pct:.0f}%\033[0m"  # Red warning
elif pct > 50:
    status = f"\033[93m{pct:.0f}%\033[0m"    # Yellow
else:
    status = f"\033[92m{pct:.0f}%\033[0m"    # Green

print(f"{status} | {cwd}")

Expected Behavior

  • usage field included in statusline context JSON
  • usage_percentage reflects current session's context window consumption
  • Updates on each statusline refresh
  • Defaults to 0 or null if unavailable

Additional Context

  • Metrics are already tracked internally (visible in UI)
  • Minimal performance impact expected
  • Could be extended to include cost estimates, request counts, etc.
  • Aligns with transparency goals around resource usage

View original on GitHub ↗

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