Feature Request: Context data access in statusline hooks
Problem
Currently, the statusline configuration in Claude Code runs as an external bash script that cannot access Claude Code's internal context state. This means users cannot display real-time context usage information (token count, memory breakdown, context percentage) in their status lines.
Current Situation
- The built-in
/contextcommand provides comprehensive context information - External statusline scripts have no way to access this same data
- Users must manually run
/contextto monitor session state
Requested Feature
Add built-in support for exposing context data to statusline hooks, enabling:
- Real-time token usage - Show current/max tokens (e.g., "33k/200k tokens")
- Context percentage - Visual progress indicator (e.g., "17%")
- Memory breakdown - Show system/tools/memory allocation
- Context progress bar - Visual representation similar to
/contextcommand
Proposed Implementation
Option 1: Environment Variables
Expose context data via environment variables when running statusline commands:
CLAUDE_CONTEXT_TOKENS=33000
CLAUDE_CONTEXT_MAX=200000
CLAUDE_CONTEXT_PERCENT=17
CLAUDE_MEMORY_TOKENS=7000
Option 2: JSON Input Extension
Extend the existing JSON input to statusline scripts with context data:
{
"workspace": {...},
"model": {...},
"context": {
"tokens_used": 33000,
"tokens_max": 200000,
"percentage": 17,
"breakdown": {
"system": 3000,
"tools": 11900,
"memory": 7000,
"messages": 3600
}
}
}
Use Cases
- Developers want to monitor context usage without interrupting their workflow
- Power users need proactive context management to avoid hitting limits
- Teams want consistent context awareness across development sessions
- CI/CD integrations need programmatic access to context state
Technical Analysis
This issue was identified while implementing a Claude Code development environment. We attempted several approaches:
- ❌ Transcript file parsing - unreliable due to format variations
- ❌ External command invocation -
/contextis session-internal only - ❌ Environment variable detection - Claude Code doesn't currently expose these
- ✅ Feature request - requires official Anthropic support
Related Issues
This relates to the broader theme of programmatic access to Claude Code session state for automation and monitoring purposes.
Priority
High - This is essential for effective context management in long-running development sessions.
This issue has 8 comments on GitHub. Read the full discussion on GitHub ↗