Feature Request: Add context data to statusline JSON input
Summary
Currently, statusline scripts receive JSON input with limited information. To enable accurate context window display, statusline tools need access to the actual context usage data that Claude Code already tracks internally.
Problem
Statusline tools like cc-statusline and ccstatusline try to calculate context usage by parsing session transcript files. However, this approach is inherently inaccurate because:
- System prompt tokens are not recorded in session files
- MCP tool definitions (~30-50k tokens for typical setups) are not included
- CLAUDE.md and other context files are loaded but not tracked in session transcripts
As a result, statuslines may show "36% context remaining" while Claude Code reports "8% until auto-compact" - a significant discrepancy that confuses users.
Proposed Solution
Add context information to the JSON that Claude Code passes to statusline commands:
{
"workspace": { "current_dir": "/path/to/project" },
"model": { "display_name": "Opus 4.5", "id": "claude-opus-4-5-20251101" },
"session_id": "...",
"context": {
"used_tokens": 176000,
"max_tokens": 200000,
"used_percent": 88,
"remaining_percent": 12,
"auto_compact_threshold_percent": 80
}
}
Alternative: /context --json command
Alternatively, expose a /context --json command or API that returns the accurate context data, which statusline scripts could query.
Current Workaround
Both cc-statusline and ccstatusline calculate context from session files using:
contextLength = input_tokens + cache_read_input_tokens + cache_creation_input_tokens
But this fundamentally cannot include:
- System prompt overhead
- MCP tool definitions (for users with many MCP servers, this can be 30-50k+ tokens)
- Environment/configuration context
Impact
Users who rely on statusline context displays to manage their context window are misled by the inaccurate numbers. This makes it harder to know when to use /compact or start a new conversation.
Additional Context
- Claude Code version: 2.0.53
- Tested with cc-statusline and ccstatusline
- Both tools show the same discrepancy because they use the same calculation method
- The
/contextcommand already displays accurate data internally - this request is to expose it to external tools
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗