Add token/context usage percentage to statusline script context object

Status Fixed / completed
Maintainer reply None cached
Activity 3 comments · opened Jan 26, 2026 · 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 ↗

3 Comments

github-actions[bot] · 8 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/11535
  2. https://github.com/anthropics/claude-code/issues/14058
  3. https://github.com/anthropics/claude-code/issues/12510

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

thomasjackson-tylertech · 8 months ago
github-actions[bot] · 8 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.